65.9K
CodeProject is changing. Read more.
Home

Using ON_MESSAGE to handle non-MFC flavored messages

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.46/5 (13 votes)

Jul 19, 2004

viewsIcon

46342

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.