[Win32] Message Handling without Global Wnd Proc

Started by
14 comments, last by Aardvajk 14 years, 9 months ago
SendMessage will post to the Window Procedure and wont return until the message has been processed as well.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Advertisement
Quote:Original post by RealMarkP

It's more of an experiment. I'm trying to segregate the windowing functionality from the Message handling functionality.


You are attempting to impose purity where none may exist. This is the very heart of Ancient Windows, dude. It was designed to do miracles - very dark, stack-thunking satanic miracles - on 286's in very little memory, and the last thing on anyone's mind in those days was purity. It is what it is. Leave it be, lest it consume you and spit up your gibbering liver on the roadside as a warning to others.

Quote:Original post by Washu
SendMessage will post to the Window Procedure and wont return until the message has been processed as well.
This is important.

There are two ways to send messages in Windows: posting (via PostMessage and sending (via SendMessage).

Messages sent via PostMessage go on your thread's message queue and are dispatched to the window procedure by DispatchMessage. However, any message which is sent via SendMessage bypasses your message queue and calls the window procedure directly.

SendMessage is used quite frequently by child windows to send notifications to their parent (so for example, the WM_COMMAND message is sent by a button control to the parent window when you click the button). If you don't implement a proper window procedure, you'd never get that notification.
Also, TranslateAccelerator() posts directly and I wouldn't want to reimplement accelerators in code, given all the subtle complexities:

Quote:SDK Docs
If the accelerator command corresponds to a menu item, the application is sent WM_INITMENU and WM_INITMENUPOPUP messages, as if the user were trying to display the menu. However, these messages are not sent if any of the following conditions exist:

  • The window is disabled.
  • The accelerator key combination does not correspond to an item on the window menu and the window is minimized.
  • A mouse capture is in effect. For information about mouse capture, see the SetCapture function.


  • If the specified window is the active window and no window has the keyboard focus (which is generally the case if the window is minimized), TranslateAccelerator translates WM_SYSKEYUP and WM_SYSKEYDOWN messages instead of WM_KEYUP and WM_KEYDOWN messages.

    If an accelerator keystroke occurs that corresponds to a menu item when the window that owns the menu is minimized, TranslateAccelerator does not send a WM_COMMAND message. However, if an accelerator keystroke occurs that does not match any of the items in the window's menu or in the window menu, the function sends a WM_COMMAND message, even if the window is minimized.


    Eeek! [smile]
    Well, nuts.
    ------------Anything prior to 9am should be illegal.
    Quote:Original post by RealMarkP
    Well, nuts.


    If you could give us a bit more detail about exactly why you feel it would be a benefit to avoid using a WndProc, I'm sure we can advise on an alternative method that addresses your issues without causing all the problems above.

    Oluseyi's article on the subject is a good read as well.

    This topic is closed to new replies.

    Advertisement