Solved

Sending WM_COMMAND messages

Posted on 1998-08-13
5
588 Views
Last Modified: 2013-11-20
Is it possible to send out a WM_COMMAND message ?
If so how do you set the parameters.

If not, how do you add a command message to the message queue??
0
Comment
Question by:manx
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:bernfarr
ID: 1320748
You can send out any message using the SendMessage() call.

LRESULT SendMessage( HWND hWnd,
  UINT Msg,       // message to send (WM_COMMAND in your case)
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter);

You need to figure out who you're sending the message to and what exactly you're sending. For WM_COMMAND, the parameters are as follows (from the WM_COMMAND reference):
  wNotifyCode = HIWORD(wParam);
  wID = LOWORD(wParam);
  hwndCtl = (HWND) lParam;

Which message queue do you want to add the command to? The one for your application?
0
 
LVL 6

Accepted Solution

by:
snoegler earned 50 total points
ID: 1320749
For what purpose do you want to send a WM_COMMAND message?
The parameters are like this:
wNotifyCode=HIWORD(wParam) - sth. like BN_CLICKED
wID=LOWORD(wParam) - identifier of the control ( ID_FILE_OPEN or ID_OK )
hwndCtl=(HWND)lParam - window handle of the control

hwndCtl is NULL if the message came from a menu item or accelerator, otherwise
it contains the window handle of the control from which the message has been sent
You can obtain the handle by calling CWnd::GetDlgItem() with the ID of the control.
I hope that helps ;)
0
 

Author Comment

by:manx
ID: 1320750
I would like to send the message to the application queue. As I would like to execute a event immediately after a certain function is executed.

What is wrong with this command format ?

SendMessage(WM_COMMAND(BN_CLICKED,ID_FILE_CLOSE,NULL);

It gives me a "term does not evaluate to a function" (C2064) error ?
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1320751
SendMessage(WM_COMMAND,
                         MAKELONG(ID_FILE_CLOSE,0),
                         NULL)
Look into the WM_COMMAND docs:
wNotifyCode is '0' when the message is sent from a menu,
hwndCtl is also NULL.

BTW: WM_COMMAND(x,y,z) is not defined - that's the cause of the error.
0
 

Author Comment

by:manx
ID: 1320752
Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

828 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