This is a simple example which opens notepad.exe if you press ctrl+shift+o.
hotkey.cpp:
#include <windows.h>
#include <shellapi.h>
#include "resource.h"
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg){
case WM_COMMAND:
switch(LOWORD(wParam)){
case ID_OPENNOTEPAD:
ShellExecute(0,0,"notepad.exe",0,0,SW_SHOW);
break;
}break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
{
WNDCLASS wc = {0};
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.hInstance = GetModuleHandle(0);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "hotkeyWndClass";
wc.hCursor = LoadCursor(0,IDC_ARROW);
RegisterClass(&wc);
ShowWindow(CreateWindow("hotkeyWndClass","hotkey",WS_CAPTION|WS_SYSMENU,CW_USEDEFAULT,0,CW_USEDEFAULT,0,0,0,hInstance,0),SW_SHOW);
MSG msg;
HANDLE hAccelTable = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDACCEL));
while(GetMessage(&msg,0,0,0))
if(!TranslateAccelerator(msg.hwnd,hAccelTable,&msg)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
resource.h:
#define ID_OPENNOTEPAD 101
#define IDACCEL 10000
resource.rc:
#include <windows.h>
#include "resource.h"
IDACCEL ACCELERATORS
BEGIN
"O", ID_OPENNOTEPAD,VIRTKEY,CONTROL, SHIFT
END