Solved

Sending WM_COMMAND messages

Posted on 1998-08-13
5
602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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