Question

I'm trying to implement This Article But when I look at all the messages my dialog "has" in the resource view (in messages tab) I don't see this message. Any idea how to catch it (is it available ? is it an IDE problem ?) Thanks, Dani

Was it helpful?

Solution

The MFC class wizard does not show messages for which a message handler is already implemented in the CWnd base class. To handle WM_WINDOWPOSCHANGING all you have to do is override CWnd::OnWindowPosChanging.

Update: I just checked and my Visual Studio 2012 (Update 3) installation does list WM_WINDOWPOSCHANGING for a dialog class. If it doesn't show up for you you may have selected the wrong class from the Class name dropdown list.

If the message does not show up for you in the class wizard for whatever reason you can still implement it manually. The class wizard is merely a convenience, not a requirement. MFC implements its message handling by constructing a Message Map that you can extend by adding message handlers through Message Map Macros.

Declare a message handler with the correct signature and name in your dialog class. Note that the afx_msg macro expands to nothing and merely serves to document that this is an MFC message handler.

afx_msg void OnWindowPosChanging(WINDOWPOS* lpwndpos);

Add the message handler to your dialog's message map:

BEGIN_MESSAGE_MAP(CMyDialog, CDialogEx)
    ...
    ON_WM_WINDOWPOSCHANGING()
END_MESSAGE_MAP()

You can find both the macro to use as well as the function signature and name at WM_ Messages: T - Z. With this in place you can implement your message handler:

void CMyDialog::OnWindowPosChanging(WINDOWPOS* lpwndpos)
{
    CDialogEx::OnWindowPosChanging(lpwndpos);

    // TODO: Add your message handler code here
}

Note that the class wizard implementation (VS 2010 and above) no longer requires specially formatted comments in the source code (like it used to in VS6). Manually adding message handlers does not break class wizard functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top