Simple Way to Check All Dialog Controls for Changings

It is very difficult and toilsome to implement code that checks every single control on a given dialog for changes; especially for complex dialogs. Normally you have to check all fields when the dialog was closed (let's say in OnOK) or have to catch all events like EN_CHANGED or BN_CLICKED to notice a changing. But fortunately the MFC provides a method to do such checkings in a very easy and compact way. This magical function calls
ON_CONTROL_RANGE ( wNotifyCode, id1, id2, memberFxn )

Use this macro to map a contiguous range of control IDs to a single message handler function for a specified Windows notification message. ClassWizard does not support creating an ON_CONTROL_RANGE handler in the user interface, so you must place the macro yourself. Be sure to put it outside the message map //{{AFX_MSG_MAP delimiters. Once entered, ClassWizard will parse these entries and allow you to browse them just like any other message map entries.

The BN_KILLFOCUS notification code is sent when a button loses the keyboard focus. The button must have the BS_NOTIFY style to send this notification message.


  1. Add the message handlers declaration...
  3. Declare the function in your header file that way:
  4. class CMyDlg : public CDialog
     BOOL m_bUpdateED;
     BOOL m_bUpdateRB;
     BOOL m_bUpdateCB;
     // Generated message map functions
     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
     virtual BOOL OnInitDialog();
     virtual void OnOK();
     virtual void OnRangeUpdateED(UINT nID);
     virtual void OnRangeUpdateRB(UINT nID);
     virtual void OnRangeUpdateCB(UINT nID);
  5. And finally code your 'OnRangeUpdate...' functions that way:
  6. void CMyDlg::OnRangeUpdateED(UINT nID)
     // extra check
     if ( SendDlgItemMessage(nID, EM_GETMODIFY, 0, 0) )
      m_bUpdateED = TRUE;
      m_bUpdateED = FALSE;
    void CMyDlg::OnRangeUpdateRB(UINT nID)
     // for example
     if ( nID == IDC_RADIO3 )
      m_bUpdateRB = TRUE;
      m_bUpdateRB = FALSE;
    void CMyDlg::OnRangeUpdateCB(UINT nID)
     // for example
     LRESULT lResult = SendDlgItemMessage(nID, BM_GETSTATE, 0, 0);
     if ( lResult == BST_CHECKED )
      m_bUpdateCB = TRUE;
      m_bUpdateCB = FALSE;
    void CMyDlg::OnOK() 
     if ( m_bUpdateRB )
     // ...


  • Why are men with rheumatism more likely to need erectile dysfunction?

    Posted by afueffifielm on 06/21/2013 06:58pm

    Erectile Dysfunction Drug Evaluation - Which remedies Are the specific Very best? In this article, we'll cover just what Viagra is, how it works and what the potential dangers are [url= ] compare cost of viagra [/url] read much more How to Cure Erectile Dysfunction Naturally Without Drugs

  • Those things everybody else does with nike and those actions you want to do totally different.

    Posted by icoppyapedcap on 04/21/2013 08:20pm

    Dw [url=]ハンターブーツ[/url] nMy [url=]ハンターブーツ[/url] f WpoKjf YiaV [url=]レインブーツメンズ[/url] rn A [url=]ブーツ[/url] oc [url=]レインブーツメンズ[/url] CnsCaiDpq O[url=]レインブーツ[/url] rwDvgCshLv [url=]レインブーツハンター[/url] s HetPxt [url=]レインブーツ人気[/url] Zbv [url=]レインブーツハンター[/url] Dan Jhn [url=]ハンターブーツ[/url] Lug

  • Perfect

    Posted by Legacy on 05/22/2003 12:00am

    Originally posted by: Ben Dunaway

    I am still learning MFC and finding solutions to common problems can get lengthy. Thanks for the for you effort, the CONTROL_RANGE macro is perfect.

  • question?

    Posted by Legacy on 08/07/2002 12:00am

    Originally posted by: PERAS

    can i use this with edit boxes! if i can how!
    i tried it and it didn't work

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

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

Most Popular Programming Stories

More for Developers

RSS Feeds

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