In GUI program you can use Accelerator's
Here is example without recources.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define ID_CTRL_X 6000
#define ID_ALT_Z 6001
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
TCHAR *szAppName = TEXT("WinTestAccel");
TCHAR *szFrameClass = TEXT("cWinTestAccel");
HWND hFrame;
HANDLE hInst;
HACCEL hAccel;
ACCEL aAccel[] = {
{FCONTROL | FVIRTKEY, 0x58, ID_CTRL_X},
{FALT | FVIRTKEY, 0x5A, ID_ALT_Z}
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wcx;
MSG msg;
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = (WNDPROC)WndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
wcx.hbrBackground = (HBRUSH)COLOR_3DSHADOW;
wcx.lpszMenuName = NULL;
wcx.lpszClassName = szFrameClass;
wcx.hIconSm = 0;
if (!RegisterClassEx(&wcx))
return 0;
hInst = hInstance;
hFrame = CreateWindowEx(0, szFrameClass, szAppName,
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInst, NULL);
if (!hFrame)
return 0;
ShowWindow(hFrame, nCmdShow);
UpdateWindow(hFrame);
hAccel = CreateAcceleratorTable(aAccel, 2);
while (GetMessage(&msg, NULL, 0, 0)) {
if (TranslateAccelerator(msg.hwnd, hAccel, &msg))
continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DestroyAcceleratorTable(hAccel);
return msg.wParam;
}
void TestKB(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
// case WM_CREATE:
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ID_CTRL_X:
SetWindowText(hWnd, TEXT("Ctrl-X"));
break;
case ID_ALT_Z:
SetWindowText(hWnd, TEXT("Alt-Z"));
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return (0);
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}