Click here to Skip to main content
15,902,939 members
Articles / Programming Languages / C++
Article

Using ON_MESSAGE to handle non-MFC flavored messages

Rate me:
Please Sign up or sign in to vote.
4.46/5 (17 votes)
18 Jul 2004 46K   13   4
Using ON_MESSAGE to handle non-MFC flavored messages

Introduction

I must confess that I am "new" to this discipline, not because I just started, but because I learn slowly. Also, having gained so much from Code Project, I was greatly convicted to contribute something.

While developing a plot library for a data analysis tool using unmanaged C++ (MFC) in VS7, I discovered that my app was not receiving LBUTTONUP messages. Quick and sloppy research revealed that I was not the only one wondering where they were going. At the time I was trying to prevent a window from completely processing the flood of PAINT messages that accompanies resizing events. One approach is to handle WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE which AFAIK are not included in MFC.

Details

Add:

  • ON_MESSAGE( WM_ENTERSIZEMOVE, OnEnterSizeMove)
  • ON_MESSAGE( WM_EXITSIZEMOVE, OnExitSizeMove)

to your message map.

Put:

  • afx_msg LRESULT OnEnterSizeMove (WPARAM, LPARAM);
  • afx_msg LRESULT OnExitSizeMove (WPARAM, LPARAM);

in your header file.

Handle the messages returning zero as follows:

LRESULT CWhatever::OnEnterSizeMove( WPARAM wparam, LPARAM lparam)
{
    // do stuff

    return (LRESULT)0;
}

LRESULT CWhatever::OnExitSizeMove( WPARAM wparam, LPARAM lparam)
{
    // do stuff

    return (LRESULT)0;
}

NOTE: for both messages, wparam = lparam = 0.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionuse ON_MESSAGE_VOID Pin
Marian Spanik31-May-15 12:36
Marian Spanik31-May-15 12:36 
QuestionError 1 error C2440: 'static_cast' : cannot convert from 'overloaded-function' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' Pin
MS_TJ2-Oct-10 18:19
MS_TJ2-Oct-10 18:19 
AnswerRe: Error 1 error C2440: 'static_cast' : cannot convert from 'overloaded-function' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' Pin
hans.sch5-Jul-23 2:59
hans.sch5-Jul-23 2:59 
@MS_TJ, your class CCDlg2 must be derived from CWnd (or from CDialog which itself is derived from CWnd).

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.