From YYpBD's MediaWiki
case WM_CREATE:
BYTE appkey;
appkey = SHGetAppKeyAssoc(_T("testkeys.exe"));
if (appkey != 0)
{
if (!RegisterHotKey(hWnd, 400, MOD_WIN, appkey))
{
// Can't register keyboard shortcut.
MessageBox(NULL, _T("Can't register hotkey."),
_T("Warning"), MB_OK);
exit(0); // Replace with specific error handling.
}
}
switch(wParam)
{
case 400:
// This is the keyboard shortcut you registered.
// Is the application in the foreground?
if (hWnd != GetForegroundWindow())
{
// No, bring it forward and that is all.
// Set focus to foremost child window.
// The "| 0x01" is used to bring any owned
// windows to the foreground and open them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
}
else
{
// Already on top, so take an action.
MessageBox(hWnd, _T("Hotkey Pressed"),
_T("Hotkey"), MB_OK);
}
break;
case WM_DESTROY:
appkey = SHGetAppKeyAssoc(_T("testkeys.exe"));
if (appkey != 0)
{
if(!UnregisterHotKey(hWnd, 400))
{
// Can't unregister hotkey.
MessageBox(NULL, _T("Can't unregister hotkey"),
_T("Warning"), MB_OK);
exit(0); // Replace with specific error handling.
}
}