Windows Messages

Dec 7, 2011 at 7:52pm
I had added the below code to my wndproc:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    FILE*  fpw = fopen("windows_msgs.log", "ab");
 
    if (fpw) {
      char  szLogString[256];
   
      sprintf(szLogString, "message : <%d>, WPARAM : <%d>, LPARAM <%d>.\r\n", message, wParam, lParam);
      fwrite((const void*)szLogString, sizeof(char), strlen(szLogString), fpw);
      fclose(fpw);
      fpw = NULL;
    }

    switch (message) {
         ...
         ...
         ...
    }
    ...
    ...
    ...
}

I had added this code in order to trace exactly the window messages that i'm getting. However, as you all can notice, the log file will contains a meaningless content as the below:

message : <36>, WPARAM : <0>, LPARAM <2944948>.
message : <129>, WPARAM : <0>, LPARAM <2944924>.
message : <131>, WPARAM : <0>, LPARAM <2944980>.
message : <1>, WPARAM : <0>, LPARAM <2944904>.
message : <28>, WPARAM : <1>, LPARAM <1944>.
message : <799>, WPARAM : <1>, LPARAM <0>.


So I wish if anyone can help to get the meaningful msgs in stead of those numbers.

Best regards,
Dec 7, 2011 at 10:46pm
Well, the messages are all equates specified in the various windows includes, so if you are looking for, for example 'WM_CREATE', you won't get 'WM_CREATE, but rather the number assigned to WM_CREATE. So you'll need a switch to output WM_CREATE to your file when that message (or any other) is received.

Second, there are usually two numbers packaged in the WPARAM. You need the HIWORD() and LOWORD macros to seperate them out. The LPARAM is usually a pointer, and when it is there isn't any HIWORD or LOWORD to that one.

Personally, I'd use the text output functions, rather than the way you are doing it with fwrite.
Dec 8, 2011 at 2:58pm
Thx for your update..
However, from where could I know which number corresponds to WM_CREATE for example!!!
I know that I still need a switch to output the exact message identifier rather than its corresponding number. But I need the full list of those messages and their assigned numbers.

Regarding the WPARAM and LPARAM, actually I don't need to know their values in the message log file. But when I know the message name, I will be able to know the HIWORD and the LOWORD since their meaning and values will change with the changing of the corresponding message.

Best Regards,
Dec 8, 2011 at 5:28pm
Do you have some utility to scan directories for names? That's how I came up with this from winuser.h (which makes sense - that's where a large number of Win Api functions for the user interface are located)...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define WM_NULL                         0x0000
#define WM_CREATE                       0x0001
#define WM_DESTROY                      0x0002
#define WM_MOVE                         0x0003
#define WM_SIZE                         0x0005

#define WM_ACTIVATE                     0x0006
/*
 * WM_ACTIVATE state values
 */
#define     WA_INACTIVE     0
#define     WA_ACTIVE       1
#define     WA_CLICKACTIVE  2

#define WM_SETFOCUS                     0x0007
#define WM_KILLFOCUS                    0x0008
#define WM_ENABLE                       0x000A
#define WM_SETREDRAW                    0x000B
#define WM_SETTEXT                      0x000C
#define WM_GETTEXT                      0x000D
#define WM_GETTEXTLENGTH                0x000E
#define WM_PAINT                        0x000F
#define WM_CLOSE                        0x0010
#define WM_QUERYENDSESSION              0x0011
#define WM_QUIT                         0x0012
#define WM_QUERYOPEN                    0x0013
#define WM_ERASEBKGND                   0x0014
#define WM_SYSCOLORCHANGE               0x0015
#define WM_ENDSESSION                   0x0016
#define WM_SHOWWINDOW                   0x0018
#define WM_WININICHANGE                 0x001A 


There are of course a lot more. I just came up with that bunch by doing a text search on WM_CREATE in the inc directory of my VC6 installation.
Last edited on Dec 8, 2011 at 5:29pm
Dec 12, 2011 at 2:33pm
I had found this file as you specified, however, I have some questions about some defined pre-processor and their values. The below values stand for which windows version?
1
2
3
4
WINVER >= 0x0500 or 0x0400 or 0x0600
_WIN32_WCE
_WIN32_WINNT >= 0x0500 or 0x0501 or 0x0600
_WIN32_WINDOWS > 0x0400

Moreover, I found that there a long list of numbers that are missing while assigning numbers to each message like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0x0004
0x0009
0x0017
0x0019
0x0025
0x0029
0x0034
0x0035
0x0036
0x0038
0x003A
0x003B
0x003C
0x003E
0x003F
0x0040
0x0042
0x0043
0x0045
0x0049
0x004C
0x004D
0x004F
0x0056 - 0x007A

Thanks in advance for your clarification
Ahmad
Dec 12, 2011 at 3:45pm
As for your question regarding Widows Versions see this link: http://msdn.microsoft.com/en-us/library/aa383745(VS.85).aspx

As for the missing numbers, some of the windows messages are older and no longer used, others are reserved for system use only; there are probably more reasons but those two are the major ones.
Dec 12, 2011 at 11:08pm
I have a question:
does every control (edit, button, combobox, ...) has its window procedure handle ?

I am sending a WM_SETTEXT message to an edit box and then i'm not able to find it in the list of messages that i'm printing into the file as mentioned above.. please note that the messages i'm listing are the messages of a form containing that edit box.

Moreover, i would like to know how to set the focus for this edit box. i tried to send message with WM_SETFOCUS but it didnt work as well

Best regards,
Ahmad
Dec 14, 2011 at 2:45pm
any body to answer me guysssssss ??!!!!!!!!!
Furthermore, from where can i get a document that illustrate the flow of messages from creating any window and then creating its control items till the window is read for user input or interaction. I need to know those in order to manipulate the control items (modify their position, size, behavior, ...) before they being created and in order to do other needed validation.

Regards,
Ahmad
Dec 14, 2011 at 5:36pm
I think you might be over-doing it with outputting messages ahbazzi! Yes, yes, messages are really important - its how Windows works. But the fact is that there are just too many to really accomplish what you seem to be trying.

Also, keep in mind that your main window's WndProc seems to be where you are executing output statements, and the only messages you will catch there are messages pertaining to your main program window. If you you SendMessage() a WM_SETFOCUS to an edit control which is a child of your main program window, that message will not pass through your main program window's window procedure, but rather will go to the edit control's window procedure, and that window procedure isn't in your app, but rather within Windows. Also, you may have better luck using SetFocus( handle of window you want to have focus ) instead of SendMessage()'ing WM_SETFOCUS. Read up on the SetFocus() Api Function.

Having said that, if you really insist on wanting to see the messages sent to child controls, then you will have to subclass the control using SetWindowLong(). In that way you would have a 'hook' of sorts into the window procedure for the control in Windows itself. You would create a Window Procedure for the child window control in your app, and Windows would call it for you.

Further, keep in mind the important and sometimes confusing distinction between Windows Messages, and child window control Notification Messages.

Dec 17, 2011 at 2:36am
ahbazzi if you want to see what window messages are being sent then I suggest you get the following.

www.softpedia.com › Windows › Security › Security Related
24 Mar 2010 – Download Winspector - An application that allows you to look at the messages being sent in the system.
Dec 17, 2011 at 6:36am
Why to use that 3rd party program and not use Spy++ that comes in windows sdk ?
Dec 18, 2011 at 12:01am
like to be independant as well as being prefered app
Topic archived. No new replies allowed.