30. oktober 2000 - 14:57
#4
det her burde kunne virke ...
#include <windows.h>
#define WIN32_LEAN_AND_MEAN
WNDCLASS WinClass;
HINSTANCE Inst;
HRGN hRegion;
HWND Handle;
MSG Msg;
HHOOK hookdata;
int i = 48;
LRESULT CALLBACK KeyboardProc ( int code, WPARAM w, LPARAM l )
{
if ( code < 0 )
return CallNextHookEx ( hookdata, code, w, l ) ;
switch (w)
{
case 37 :
SetWindowText(Handle, \"Arrow Left\");
do {/*loop*/}while (PeekMessage(&Msg, 0, 0, 0, PM_REMOVE));
break;
case 38 :
SetWindowText(Handle, \"Arrow Up\");
do {/*loop*/}while (PeekMessage(&Msg, 0, 0, 0, PM_REMOVE));
break;
case 39 :
SetWindowText(Handle, \"Arrow Right\");
do {/*loop*/}while (PeekMessage(&Msg, 0, 0, 0, PM_REMOVE));
break;
case 40 :
SetWindowText(Handle, \"Arrow Down\");
do {/*loop*/}while (PeekMessage(&Msg, 0, 0, 0, PM_REMOVE));
break;
default:
return CallNextHookEx ( hookdata, code, w, l ) ;
}
return 1;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CREATE:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
Inst = hInstance;
WinClass.style = CS_CLASSDC | CS_PARENTDC;
WinClass.lpfnWndProc = &WndProc;
WinClass.hInstance = Inst;
WinClass.hbrBackground = CreateSolidBrush(0xFFFFFF);
WinClass.lpszClassName = \"JB_KEY_WINDOW\";
WinClass.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClass(&WinClass);
Handle = CreateWindowEx(WS_EX_WINDOWEDGE, \"JB_KEY_WINDOW\", \"\", WS_VISIBLE | WS_CAPTION|WS_SYSMENU, 363, 278, 350, 350, 0, 0, Inst, 0);
UpdateWindow(Handle);
hookdata = SetWindowsHookEx ( WH_KEYBOARD , &KeyboardProc, Inst, GetCurrentThreadId() ) ;
while(GetMessage(&Msg, 0, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Jens B