1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <windows.h>
#include <tchar.h>
#include <crtdbg.h>
LRESULT CALLBACK LLKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
PKBDLLHOOKSTRUCT hookstruct;
if (nCode == HC_ACTION)
{
switch (wParam)
{
case WM_KEYDOWN: case WM_SYSKEYDOWN:
case WM_KEYUP: case WM_SYSKEYUP:
hookstruct = (PKBDLLHOOKSTRUCT)lParam;
if (hookstruct->vkCode == 91) /* pesky Windows button */
{
return 1;
}
else
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HHOOK hook_keys;
int keycode;
switch (uMsg)
{
case WM_CREATE:
hook_keys = SetWindowsHookEx(WH_KEYBOARD_LL,
LLKeyboardProc,((LPCREATESTRUCT)lParam)->hInstance,0);
return 0;
case WM_DESTROY:
UnhookWindowsHookEx(hook_keys);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
TCHAR szClassName[] = _T("Template");
TCHAR szWindowName[] = _T("Template");
WNDCLASSEX wc = { 0 };
MSG messages;
HWND hWnd;
wc.lpszClassName = szClassName;
wc.lpfnWndProc = WindowProc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
wc.hInstance = hInstance;
_ASSERTE(RegisterClassEx(&wc) != 0);
hWnd = CreateWindowEx(0, szClassName, szWindowName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
HWND_DESKTOP, 0, hInstance, 0);
_ASSERTE(::IsWindow(hWnd));
ShowWindow(hWnd, SW_SHOWMAXIMIZED);
while (GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return static_cast<int>(messages.wParam);
}
|