Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 602
  • Last Modified:

Getting the right wNotifyCommands using the user32.dll


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.
  • 3
  • 2
1 Solution
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
develcAuthor Commented:
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.
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....

develcAuthor Commented:
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
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now