Getting the right wNotifyCommands using the user32.dll

Posted on 2004-08-16
Medium Priority
Last Modified: 2012-08-13

I try to handle a window automatically.
With Spy++ I already found out the right lParam and the WM_Command Code.
But if I monitor the window - the wNotifyCode is wrong.
I've to send a BN_CLICKED WM_Command but with my routine I send a Code 0 (send from a menue) Message.

Is there anywhere a documentation where the wNotifyCommands are explained?
Is there a way to calculate them?
Did anybody already handle a window with a BN_CLICKED Message?

I would be gratefully for every advice.
Question by:develc
  • 3
  • 2

Expert Comment

ID: 11821160
You can download Microsoft's Platform SDK from: http://www.microsoft.com/msdownload/platformsdk/sdkupdate/

That will contain documentation on WM_COMMAND

For BN_CLICKED, the WM_COMMAND parameters are as follows:
wParam - The low-order word contains the button's control identifier. The high-order word specifies the notification
lParam - Handle to the button.

There is lots more documentation on button processing in the SDK.

You could also search for the same information online at msdn.microsoft.com.

Author Comment

ID: 11828987
Hello SoftMar_SA,

thank you very much for your message.

On MSDN I already found very generally information but not much details.
For example :
and so on.

Maybe there are some better sites there.
Do you know some?

Do you can give me any example how to use the right lParam and wParam with the information from Spy++?
For example the message I want to handle got the WM_Command 0x111 and the lParam 0x000012A6
and the wParam 0x00D1672 if I monitor the windows there is wNotifyCode:BN_Clicked wID:4774 hwndCTl:000D1672.
But when I use my routine and use the Params from Spy++ I send a wNotifyCode:0 (send from a menue) WID:4774

So maybe I got one failure in the high and low order words?
Do anybody knows a good documentation for that?

Any more advices are welcome.

Expert Comment

ID: 11832025
Not sure what language your using.... Or what your trying to achieve...

Are you trying to handle a button press or fake a button press...

Here is a rough fragment to illustrate handling a button in C - This would be in your message loop

HWND hCtrl;

switch (msg)
   case  WM_COMMAND :
       notifyCode = HIWORD(wParam); // 0 if from a menu, 1 accellerator, otherwise control notification code

       if (notifyCode == BN_CLICKED)
          btnID  = LOWORD (wParam)   // Button ID - identifies which button send the message
          hCtrl = lParam;                     // Window handle of your button

          ... Code to handle your button press. You can determine which button was pressed from the button ID (btnID)

When sending a WM_COMMAND message yourself, construct your wParam, lParam parameters as follows:

lParam   = NULL; // or the window handle of the button if you know it.

It sounds like you've been setting the notification code part of the wParam to 0 - which would not indicate a button click.

If the notification is 0, your are processing a menu selection... in which case the LOWORD (wParam) is the menuitem ID and not a button ID....


Author Comment

ID: 11850711
Hello SoftMar_SA,

thank you very very much your effort.
I'm really glad that someone helps me.

I prefer using C# - but for the generally questions with the params it may plays not such a big role.
What I'm trying to achieve, can you read under the following question :
"Commit a Outllook Message automatically ..." http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21089688.html
Unfortunaltely this question isn't answered until yet.
To sum up, I want to rebuild / reconstruct the following freeware tool : http://www.contextmagic.com/express-clickyes/.

I thought the wParam is a hex Code?
And you're right with my code - I'm sending the notification of 0 which processing a menu selection, despite I'm using the
hex code which is shown in Spy++ when you click the okay Button - where is my failure?

What is the result when the lParam is Null?

I hope you don't give up!

Thank you.
Best regards

Accepted Solution

SoftMar_SA earned 1500 total points
ID: 11891427
I see what you are trying to do.... I once did something very similar. An earlier version of Outlook always used to show a logon dialog on my pc.  The user name was always there, just needed to press OK. I had Outlook in my Startup folder. I wrote an application to automatically press the OK button to log Outlook in for me.

My approach was

1. Do the FindWindow on the window class - I think you already know how to do this.
2. I then called EnumChildWindows to enumerate the child windows. If I remember correctly the first child window was
    the OK button.
3. Having got the Window Handle of the OK button I then posted WM_LBUTTONDOWN/WM_LBUTTONUP messages to the

This faked a mouse click on the button.

The button would then send it's own WM_COMMAND messages....

This worked. Unfortunately I no longer have the code... I think this approach would work for you as well.

I've been trying to get my copy of Outlook 2003 to show the message so I could try to knock togethor the code.... But it doesn't seem to want to. Maybe a setting somewhere. I already have an application that calls it via MAPI.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Starting up a Project

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question