Solved

Sending WM_COMMAND messages

Posted on 1998-08-13
5
585 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ADO Memory leak with DELPHI 2007 37 181
sum67 challenge 35 99
only14 challenge 19 76
modThree challenge 4 91
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. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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