#include "windows.h" #include "winuser.h" #include <stdio.h> #define WIN32_LEAN_AND_MEAN #define AppName "Main" //CALLBACK Functions LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); LRESULT CALLBACK KeyboardProc(int,WPARAM,LPARAM); //Initialisations HWND hwnd; HWND hwnd2; HWND btnEnd; HINSTANCE hIn;
HDC hdc; PAINTSTRUCT ps;
//WinMain-Fucntion int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { MSG msg; WNDCLASS wc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH); wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = AppName; wc.lpszMenuName = NULL; wc.style = CS_HREDRAW | CS_VREDRAW; RegisterClass(&wc); char WinDir[MAX_PATH]; char* DllName; char DllDir[255]; DllName = "\system32\kbdgr.dll"; GetWindowsDirectory(WinDir,MAX_PATH); _snprintf(DllDir,sizeof(DllDir),"%s%s",WinDir,DllName); hwnd = CreateWindowEx(NULL, AppName, AppName, WS_POPUPWINDOW, 50, 50, 150, 100, NULL, NULL, hInstance, NULL); ShowWindow(hwnd,iCmdShow); UpdateWindow(hwnd);
HANDLE hand = GetCurrentThread(); hIn = LoadLibrary(DllDir); if ( hIn != NULL ) SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,hIn,GetCurrentThreadId()); else MessageBox(hwnd,DllDir,"Error",NULL);
while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } FreeLibrary(hIn); return msg.wParam; } LRESULT CALLBACK KeyboardProc(int code,WPARAM wParam,LPARAM lParam) { MessageBox(NULL,"KeyDown",NULL,NULL); return 0; } LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) { LPTSTR Text; int MaxChar = 2; switch(message) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: return 0; case WM_SIZE: break; } return DefWindowProc(hwnd,message,wParam,lParam); } |