Click here to Skip to main content
12,700,874 members (30,584 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++
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:
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 30-Nov-12 11:29am
denso1253
Updated 30-Nov-12 11:56am
RyanDev233.9K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 1 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100