close
如今的程式是一場工程師和上帝的競賽,工程師要開發出更大更好、傻瓜都會用到軟體。而上帝在努力創造出更大更傻的傻瓜。目前為止,上帝是贏的。(Rick Cook)
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Rick Cook)
這一章節,我準備來教如何註冊Windows API,而我打算用最簡單的方式教,那就是寫點CODE.
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
MSG msg = { 0 };
HWND hConsole = GetActiveWindow();
RegisterHotKey
(
hConsole, // 註冊快捷鍵的窗口Handle
1, // 熱鍵標示符號
MOD_CONTROL|MOD_NOREPEAT, // Ctrl , 不要重複發送
'A' // B
); //Ctrl + A
//Ctrl+B
RegisterHotKey(hConsole, 2, MOD_CONTROL | MOD_NOREPEAT, 'B');
//ALT+A
RegisterHotKey(hConsole, 3, MOD_ALT | MOD_NOREPEAT, 'A');
//ALT+A
RegisterHotKey(hConsole, 4, MOD_ALT | MOD_NOREPEAT, 'B');
//直接按S
RegisterHotKey(hConsole, 5, MOD_NOREPEAT, 'S');
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
if (msg.message == WM_HOTKEY)
{
switch (msg.wParam)
{
case 1:
printf("Ctrl+A\n"); break;
case 2:
printf("Ctrl+B\n"); break;
case 3:
printf("Alt+A\n"); break;
case 4:
printf("Alt+B\n"); break;
case 5:
printf("S\n"); break;
default:
break;
}
}
}
return 0;
}
全站熱搜
留言列表