0

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

Community
  • 1
  • 1
Dani
  • 14,639
  • 11
  • 62
  • 110
  • Maybe it's not even an *IDE problem* exactly, the message is just not on a short list, so it is not listed on the IDE. You can add handler manually typing code in. Whether your window receives specifci message or not - you can always check with `Spy++` tool. – Roman R. Sep 07 '13 at 09:15
  • I've seen a note about changing the settings to show those missing messages but I have no Idea what to change and when: http://www.codeproject.com/Articles/1724/Some-handy-dialog-box-tricks-tips-and-workarounds?fid=3124&select=3423450&fr=21#xx0xx – Dani Sep 07 '13 at 10:38
  • It all depends on what you need to do, sometimes there's no need to wait for `WM_WINDOWPOSCHANGING` and you can call `PostMessage()` from your `WM_INITDIALOG` handler (or in your `OnInitDialog()` override if you are using MFC). Can you give a screenshot of what you see in your messages tab? – Edward Clements Sep 07 '13 at 12:57
  • I get about 30 messages, but not the one I need... I've added it manually. – Dani Sep 08 '13 at 14:22

1 Answers1

4

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.

IInspectable
  • 46,945
  • 8
  • 85
  • 181
  • It is a dialog, and I need to start something only after it is shown. there are several articles that talks about using this message with dialog... – Dani Sep 07 '13 at 13:46
  • @Dani You are probably looking for [`WM_WINDOWPOSCHANGED`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms632652.aspx) then. Regardless of that, make sure you have selected the dialog class under *Class name* in the top right of the class wizard. – IInspectable Sep 07 '13 at 13:56
  • Ok, just used the wizard to create the WM_SHOWWINDOW and then changed everything to match my message. it works. I don't know why the message is missing from the properties screen.... – Dani Sep 08 '13 at 14:22