How often does Windows system send messages to my application?

Hi there:

You write a win32 application. When user clicks a mouth, a message is generated from OS and sent to your application's queue. Then things go on, depending on what you want.


My question is, which of the following two schemes are used for os to send messages to our app?
scheme 1: for a very short period of time, a message is sent even if the user hasn't done anything

scheme 2: only when system status changes, say, when a button is pressed, should a message be sent.



Or if the OS actually follows a third scheme, please point it out!

Thanks a lot for any inputs.

That's actually a very good question h9uest.

Windows waits patiently. Its not spinning in a loop in your application. If you start a program and do nothing, i.e., don't move the mouse, touch the keyboard, or do anything else in terms of providing input, then Windows will only 'broadcast' various 'system' messages to your program or its Window Procedure. Of course, if you so much as bump the mouse, hundreds of WM_MOUSEMOVE messages will bombard your Window Procedure. Its an awesome machine!

It would probably be worth your while to write a program that opens a text file and prints out to it the various messages that come through the Window Procedure.
Microsoft spy++ can already log and display all messages send to your application.
To expand on what freddie1 says the program he mentions isn't that hard to write. Just put an ofstream object at the beginning of your CallBack function since that is the point that the Win32 API sends it's messages to. You only need to save the integer value that you are being passed.
GetMessage will wait for the system to send a message to the program, but you can use another method called PeekMessage which will just check if theres a message available and then you can handle it, e.g.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) // Wait for an event
{
  // Calls the window procedure function of msg.hwnd window
  DispatchMessage(&msg);
}

MSG msg = {0};
while (msg.message != WM_QUIT)
{
  // Is there a message?
  // PM_REMOVE removes the message from queue
  if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
  {
    // Handle the message
    DispatchMessage(&msg);
  }
  // other code here
}
@ ALL

Thank you guys very much for taking time to reply! Sorry about the delay as I was on a trip.

I'll explore it a bit.
Topic archived. No new replies allowed.