Windows Messages Bizarreness

Probably just a gross oversight of some sort, but I'm not receiving any WM_SIZE messages in the message loop. However, I do receive them in the WndProc. I thought the windows loop gave messages out to WndProc?

LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch(message) { // this message is read when the window is closed case WM_DESTROY: { // close the application entirely PostQuitMessage(0); return 0; } break; case WM_SIZE: return 0; break; } printf("wndproc - %i\n", message); // Handle any messages the switch statement didn't return DefWindowProc (hWnd, message, wParam, lParam); }

... and now the message loop...

while(TRUE) { // Check to see if any messages are waiting in the queue if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // translate keystroke messages into the right format TranslateMessage(&msg); // send the message to the WindowProc function DispatchMessage(&msg); // check to see if it's time to quit if(msg.message == WM_QUIT) { break; } if(msg.message == WM_SIZING) { printf("loop - resizing...\n"); } } else { //do other stuff } }

-------------Problems Reply------------

If a message is sent by the system to your window while it's in DefWindowProc or elsewhere in that netherworld that's the Windows message queue, then that message is not going to be seen by your message loop at all.

Note that this is only true for sent messages. Posted messages will show up in the message loop.

If you want to filter all messages, use SetWindowsHookEx with your thread ID, and the appropriate hook type. Or better yet, process them properly in your WndProc.

While you've got hold of the sizing gripper, I believe that Windows is running its own message loop. That will dispatch to your message queue, but your loop is out of the picture while the sizing is ongoing.

The frame window will call SetCapture to capture all subsequent mouse messages. Then it'll resize your window as the mouse moves. It'll also pump the message loop; you can see some similar code here: ftp://ftp.ringdale.com/support/Nlynx/Tech%20Support%20Docs/Midrange/EmeraldSeries/ADK/DDE/C/APITERM/TRACK.C. Note the message loop in the middle of that function.

It pumps the queue itself so that the sizing code doesn't have to return until after the resize tracking is complete.

Edit: I bring up the tracking rectangle code since that's how window resizing used to work, showing just a thin rectangular outline of the window, until we got dynamic window resizing where the entire window updates on the fly while you resize. The behavior internally is likely similar.

Edit 2: Still, credit to the guys who mentioned posted vs sent messages... sent messages won't ever go through the message pump. Sent messages quickly boil down to a function call of your wnd proc. Unless they're sent to windows owned by a different thread, which becomes a lot more complex; they get added to an internal queue belonging to the destination thread's message queue, and are processed internally - before posted messages are returned -inside GetMessage. Getting the sent message's return value back to the source thread involves more gyrations :)

WM_SIZING and WM_SIZE are not the same message. I think ordinary mouse operations to resize a window send WM_SIZING first, but if some program sends a WM_SIZE message then you're only going to get WM_SIZE without WM_SIZING.

Category:c# Views:0 Time:2010-12-22
Tags: c# windows

Related post

  • Why do modal dialogs that are opened through a menu item's click event process all window messages? 2008-09-25

    So for the past day or so I have been fixing a bug that is caused by a modal dialog. I work on an application which communicates with the server through the Windows message pump. When I use ShowDialog() to show a modal form, the message pump is block

  • How could I create a custom windows message? 2008-11-16

    Our project is running on Windows CE 6.0 and is written in C++ . We have some problems with the code , and we are unable to debug . We also found out that if in our application we create threads and try to printf from them , the output won't appear .

  • Looking for an alternative to windows messages used in inter-process communication 2008-12-11

    I a have a multithread application (MIDAS) that makes uses of windows messages to communicate with itself. MAIN FORM The main form receives windows messages sent by the RDM LogData(‘DataToLog’) Because windows messages are used they have the followin

  • Windows mobile Windows Messages tracing utility 2009-01-21

    I'm looking for small utility to run on windows mobile phone and trace all windows messages it receive. Not message codes, but names if it could figure them out. I could probably write on for my own, but don't know where I could get a dictionary of W

  • How to filter windows messages from a managed DLL 2009-01-26

    How can I get UI framework independent (WinForms, WPF, other frameworks) way to filter windows messages? Thank you. --------------Solutions------------- Windows messages are framework dependent. WPF actually tries to hide this away from you but it de

  • Which windows message triggers a form's load event? 2009-02-13

    I posted this answer (more of an idea really) but haven't been able to find out for sure which message triggers a WinForms Form.Load event. From Spy++ and some reading I suggested it might be WM_SHOWWINDOW, but I'd like to be sure. Also, other than S

  • Looking for a program to view Windows messages 2009-03-25

    I am looking for a program to view Windows messages Can you help? --------------Solutions------------- Spy++ comes with Visual Studio. I have found Winspector to be somewhat more stable than Spy++ especially while debugging a program while at the sam

  • CDialog not Receiving Windows Messages in ActiveX Control 2009-04-02

    I have an ActiveX control in MFC that manipulates images and I am trying to add TWAIN scanning functionality to it. I need to be able to receive a Windows Message back from the TWAIN driver that tells my control when an image has been scanned, so I h

  • How can my app find the sender of a windows message? 2009-05-26

    I have an app which uses a keyboard hook procedure in a library. The wParam in the hook for one message is 255 which we think is "(reserved / OEMClear)". I'd like to work out the source of this message as it causes my application to crash in the libr

  • Can I send / receive window messages without a window? 2009-06-01

    I'm writing a .NET wrapper around an old MFC-based library we have. It's based around a class that sends notifications using window messages; it has a function that lets the user pass in a handle to a window, and that window will receive the messages

  • Determining Window Message Queue Depth 2009-06-02

    We have an application that uses the window message queue to pass data from a socket to consumer HWNDs (at a rate of ~2100Hz). This application has worked for >2 years. Recently our application has started exhibiting problems where WM_TIMER is not

  • Repeat windows messages in Winforms 2009-06-08

    I want repeat sent windows messages to my winforms application. Now, I have class implementing "IMessageFilter" which saves the selected messages (WM _KEYDOWN, WM _LBUTTONDOWN, etc...) to the list. On key "Pause/Break" I copy the list of messages, cl

  • What conditions need to be fulfilled for a window message to be posted? 2009-07-30

    I've successfully registered a window class using RegisterClassEx and created a window using CreateWindowEx: m_hInstance = ::GetModuleHandle(NULL); ... m_hWnd = ::CreateWindowEx(0, "CMyClassName", "Message Window", 0, 0, 0, 0, 0, HWND_MESSAGE, 0, m_h

  • Send windows message to a Windows Service 2009-08-05

    Is there any tool to send (mimic) a windows message like 'WM_ENDSESSION' to a windows service? OR How can I send a windows message to a process using C#? (I know only C#) EDIT: Purpose: Basically I have to debug a windows service for fixing a bug tha

  • Console get key press w/o windows messages c++ 2009-08-16

    Is there any way to get the last key press in a console without using Windows messages or the std::cin stream? I've heard that there is a function in the standard library. Solutions should preferably be as portable as possible. Thanks for your help i

  • How to parallelize Windows message loop and hook callback logic and the Ruby threads it creates? 2009-08-16

    I'm working on a free, simple, hopefully multi-platform hotkey launcher tool, written in Ruby. Right now I'm struggling with some threading issues of the Windows implementation. The rough proof of concept code shown below already works reliably in my

  • Hook into and log "everything" in the windows message queue 2009-08-20

    Has anyone got a working code example of how to connect to the windows message queue(post/sendMessage) and log all messages there? Preferably in Python. I'm interrested in this to easier be able to create test-scripts that emulates user input. ------

  • VB6 quitting while debugging with active Windows message hook 2009-09-08

    One of our largest old VB6 apps has some code in it to allow other apps (including some dotNET ones) to pass an ID to it via a Windows message - this ID is then used by the VB6 app to load an entry in a regular Windows form. The message hook is added

  • Windows messages serviced whilst assert dialog is being displayed? 2009-09-21

    I have an MFC application that spawns a number of different worker threads and is compiled with VS2003. When calling CTreeCtrl::GetItemState() I'm occasionally getting a debug assertion dialog popup. I'm assuming that this is because I've passed in a

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.084 (s). 11 q(s)