Getting the right wNotifyCommands using the user32.dll

Posted on 2004-08-16
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:

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

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 ..."
Unfortunaltely this question isn't answered until yet.
To sum up, I want to rebuild / reconstruct the following freeware tool :

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 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
strDist challenge 35 84
java  and programming certification ? 4 65
Recommendation vb6 to or others 14 39
Birthdays 3 0
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now