Click here to Skip to main content
Rate this: bad
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.
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;
void COpui::OnStartTest()
//my routine in here
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
Edited 30-Nov-12 11:56am
Rate this: bad
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.
Albert Holguin at 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
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":[^].
Compare:[^]. HANDLE_MSG is the macro used to implement window procedure (in a lame C++ way, in my opinion Smile | :) ):[^],[^].
In response to the follow-up question: yes, this token-pasting '##' operator you never mentioned before. It is explained here:[^].
All this preprocessor activity and this way of message handling is such a lame! Can I unsee it? Smile | :)
denso1 at 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
0 Sergey Alexandrovich Kryukov 8,478
1 OriginalGriff 6,516
2 Peter Leow 3,587
3 Zoltán Zörgő 3,406
4 Richard MacCutchan 2,397

Advertise | Privacy | Mobile
Web03 | 2.8.150123.1 | Last Updated 1 Dec 2012
Copyright © CodeProject, 1999-2015
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