Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Visual C++

I am trying to set up a hot key of "F1" to call a routine within my software. I have been able to register the hot key but can not get the code to compile to try to take action when the hot key is pressed. I don't know how to handle WM_HOTKEY.

Code:
C++
include windowsx.h

//this seems to be working.  if I call it a 2nd time it fails
if(!RegisterHotKey(NULL, IDC_OP_START, 0, 0x70)) MessageBox("F1 Register Failed");

WPARAM wParam;
LPARAM lParam;
HANDLE_MSG(NULL, WM_HOTKEY, OnStartTest)

void COpui::OnStartTest()
{
//my routine in here
}

ERROR!!
error C2046: illegal case
error 'HANDLE_WM_HOTKEY' : undeclared identifier

Seems like the HANDLE_MSG function does not like me passing WM_HOTKEY.
Posted
Updated 30-Nov-12 10:56am
v2

I think you need to spend some time learning about Windows programming before trying such advanced topics as this. You cannot just dump a case statement in the middle of your code and expect it to do something. The HANDLE_MSG macro is designed to be used inside a switch {} block in the windows message handler function of your program.
 
Share this answer
 
Comments
Albert Holguin 1-Dec-12 22:34pm    
I agree... learn to do the windows message handling and you'll understand this much better... +5 Richard
You are not showing source code which causes this problem. The identifier HANDLE_WM_HOTKEY, is not found, but the source code you show uses WM_HOTKEY which will be compiled with "windows.h":
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646279%28v=vs.85%29.aspx[^].

Compare: http://support.microsoft.com/kb/83456[^]. HANDLE_MSG is the macro used to implement window procedure (in a lame C++ way, in my opinion :-)):
http://msdn.microsoft.com/en-us/library/windows/desktop/ff468931%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632593%28v=vs.85%29.aspx[^].

[EDIT]

In response to the follow-up question: yes, this token-pasting '##' operator you never mentioned before. It is explained here:
http://msdn.microsoft.com/en-us/library/09dwwt6y%28v=vs.110%29.aspx[^].

All this preprocessor activity and this way of message handling is such a lame! Can I unsee it? :-)

—SA
 
Share this answer
 
v4
Comments
denso1 30-Nov-12 17:12pm    
I am not making a reference to HANDLE_WM_HOTKEY. It seems like the HANDLE_MSG is doing that on its own. I am using WINDOWSX.h file and it has the HANDLE_MSG function defined as follows:

<pre lang="cs">/****** Message crackers ****************************************************/

#define HANDLE_MSG(hwnd, message, fn) \
case (message): return HANDLE_##message((hwnd), (wParam), (lParam), (fn))</pre>


I think maybe the "return HANDLE_##message" is somehow causing my problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900