01 //--------------------------------------------------------------------------------------------------
02 // Register global hotkeys
03 // (C) Oscar Kohler / www.adminzone.org
04 //--------------------------------------------------------------------------------------------------
05 // Prinzip Code, keine Gewähr !
06 //--------------------------------------------------------------------------------------------------
07 
08 #include <windows.h>
09 #include <tchar.h>
10 
11 //--------------------------------------------------------------------------------------------------
12 
13 int APIENTRY _tWinMain( HINSTANCE hInstance,
14                         HINSTANCE hPrevInstance,
15                         LPTSTR    lpCmdLine,
16                         int       nCmdShow  ) {
17 
18     const int iID_1 = 1;
19     const int iID_2 = 2;
20 
21     const TCHAR szTitle[] = _T( "Hotkey Test © adminzone.org" );
22 
23     // Register global hotkeys
24 
25     if (! RegisterHotKey ( NULL, iID_1, MOD_ALT | MOD_CONTROL, VK_F1 )) {
26         MessageBox ( 0, _T("Error while registering hotkey: 1"), szTitle, MB_ICONERROR | MB_OK );
27         return 1;
28     }
29     if (! RegisterHotKey ( NULL, iID_2, MOD_ALT | MOD_CONTROL, VK_F2 )) {
30         MessageBox ( 0, _T("Error while registering hotkey: 2"), szTitle, MB_ICONERROR | MB_OK );
31         return 1;
32     }
33 
34     // Messageloop
35 
36     MSG msg;
37 
38     while ( GetMessage( &msg, NULL, 0, 0 ) != 0 ) {
39         if ( msg.message == WM_HOTKEY ) {
40             switch ( msg.wParam ) {
41                 case iID_1:
42                     MessageBeep( MB_ICONWARNING );
43                     break;
44                 case iID_2:
45                     MessageBeep( MB_ICONERROR );
46                     PostQuitMessage( 0 );
47                     break;
48             }
49         }
50     }
51  
52     // Unregister global hotkeys
53 
54     UnregisterHotKey( NULL, iID_1 );
55     UnregisterHotKey( NULL, iID_2 );
56 
57     return 0;
58 }
59 
60 //--------------------------------------------------------------------------------------------------