Using ON_UPDATE_COMMAND_UI with controls

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

afxpriv.h has a message, WM_KICKIDLE, that is sent during idle processing. To get dialogs to work with the ON_UPDATE_COMMAND_UI message maps, you need to trap the kick idle message and call UpdateDialogControls.

In a dalog class header, add the following in the message map:

	afx_msg LRESULT OnKickIdle(WPARAM , LPARAM );

In the implementation file:

	#include <afxpriv.h>

In the message map add:
	ON_MESSAGE(WM_KICKIDLE, OnKickIdle)

Implement the function:

	LRESULT CMyDlg::OnKickIdle(WPARAM wParam, LPARAM lParam)
	{
		UpdateDialogControls(this, FALSE);
		return 0;
	}

I leave the bDisableIfNoHndler flag as FALSE so buttons without message map entries are not disabled.

You can now use ON_UPDATE_COMMAND_UI message maps for enabling/disabling controls, setting static text, etc.

It works really well when you have two or more radio buttons that enable/disable different groups of controls. Just have one OnUpdate... function for each group of controls that enables/disables depending on the radio button selected, use IsDlgButtonChecked. Then add a message map entry for each control.

To use ON_UPDATE_COMMAND_UI in form views.

The kick idle message doesn't work in form views, but there's another message in afxpriv.h called WM_IDLEUPDATECMDUI, that does.

In a form view class header, add the following in the message map:

	afx_msg LRESULT OnIdleUpdateCmdUI(WPARAM , LPARAM );

In the implementation file:

	#include <afxpriv.h>

In the message map add:

	ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)

Implement the function:

	LRESULT CMyFormView::OnIdleUpdateCmdUI(WPARAM wParam, LPARAM)
	{
		UpdateDialogControls(this, FALSE);
		return 0L;
	}

ON_UPDATE_COMMAND_UI can now be used as described above.

Updated 21 March 1998



Comments

  • UpdateCmdUI for a modeless dialog in a dialog based application

    Posted by Legacy on 04/06/2000 12:00am

    Originally posted by: Anna

    I tried this code for my dialog based application.
    i dont have a frame wnd here but applied all the steps to the main dialog class instead of the frame wnd.
    please see the code:
    In the main dialog class, i put this message map entry and a handler to it.
    ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)

    LRESULT CMyDlg1::OnIdleUpdateCmdUI(WPARAM wParam,
    LPARAM lParam)
    {
    m_pViewDoc->SendMessage(WM_IDLEUPDATECMDUI);
    return 0L;
    }
    m_pViewDoc is a pointer to the modeless dialog(CViewDoc) which has a toolbar that needs the updatecmdUI.
    In the Modeless dialog i have the following code:
    ON_MESSAGE(WM_KICKIDLE, OnKickIdle) in the message map entry of this class.

    LRESULT CViewDoc::OnKickIdle(WPARAM wParam, LPARAM lParam)
    {
    UpdateDialogControls(this, FALSE);
    return 0;
    }
    I have UpdateCmdUI handlers for the toolbar buttons .
    this does not work . can anyone help me out.
    thanks.
    Anna

    Reply
  • Default() might be fine

    Posted by Legacy on 01/29/2000 12:00am

    Originally posted by: Petr Novotny

    It might be cosmetic, but it might not: Instead of 
    
    UpdateDialogControls(this,FALSE);
    return 0;
    I'd rather use
    UpdateDialogControls(this,FALSE);
    return Default();
    giving MFC/Windows chance to do more with this message if neccessary...

    Reply
  • ON_UPDATE_COMMAND_UI for Modeless Dialogs

    Posted by Legacy on 10/07/1998 12:00am

    Originally posted by: Tim McColl

    Modeless dialogs can't automatically use the WM_KICKIDLE message to start idle processing. This is because MFC uses it's own model dialog message loop that sends WM_KICKIDLE messages. But modeless dialogs use the standard dialog message loop in Windows. This one doesn't send WM_KICKIDLE messages.

    So by taking a look at how MFC allows dialog bars to do idle processing, this is the best I can come up with.

    1. Keep a pointer to the modeless dialog in the parent window that created the dialog. Frame or view.
    2. In the parent window add a message map for WM_IDLEUPDATECMDUI. This message is pumped out by the app's OnIdle loop.
    3. Send WM_IDLEUPDATECMDUI to the modeless dialog from the parent's OnIdleUpdateCmdUI function.
    4. Add a message map for WM_IDLEUPDATECMDUI in the dialog and call UpdateDialogControls
    5. Use ON_UPDATE_COMMAND_UI message maps as needed.

    Notes:
    WM_IDLEUPDATECMDUI is defined in afxpriv.h.
    You could send the dialog WM_KICKIDLE messages. I just used WM_IDLEUPDATECMDUI to fit in with the way MFC does things.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date