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 84 85 86 87
| #include <windows.h>
#include <stdio.h>
#define ID_LABEL1 1001
#define ID_LABEL2 1002
#define WMAP_KEYBDHOOKMSG WM_APP + 1
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
typedef void (*TInitFunc)(HWND);
typedef void (*TEndFunc)();
TInitFunc InitHooks;
TEndFunc EndHooks;
HINSTANCE instance;
HINSTANCE dll;
int WinMain(HINSTANCE this_instance, HINSTANCE prev_instance, LPSTR cmd_line, int view_mod)
{
WNDCLASS wnd_class;
wnd_class.style = 0;
wnd_class.lpfnWndProc = WindowProcedure;
wnd_class.cbClsExtra = 0;
wnd_class.cbWndExtra = 0;
wnd_class.hInstance = NULL;
wnd_class.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wnd_class.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd_class.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
wnd_class.lpszMenuName = NULL;
wnd_class.lpszClassName = "wnd_class";
instance = this_instance;
if(!RegisterClass(&wnd_class)) return false;
HWND wnd = CreateWindow("wnd_class", "CounterClic", WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 220, 100, NULL, NULL, this_instance, NULL);
if(!wnd) return false;
ShowWindow(wnd, view_mod);
UpdateWindow(wnd);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProcedure(HWND wnd, UINT msg, WPARAM w_param, LPARAM l_param)
{
static HWND label1, label2;
static int counter;
switch(msg)
{
case WM_CREATE :
label1 = CreateWindow("STATIC", "Number of clicks :", WS_CHILD | WS_VISIBLE | SS_NOTIFY, 10, 25, 150, 60, wnd, (HMENU)ID_LABEL1, instance, NULL);
label2 = CreateWindow("STATIC", "0", WS_CHILD | WS_VISIBLE | SS_NOTIFY, 133, 25, 55, 60, wnd, (HMENU)ID_LABEL2, instance, NULL);
dll = LoadLibrary("mydll.dll");
if(!dll) PostQuitMessage(0);
InitHooks = (TInitFunc)GetProcAddress(dll, "_InitHook");
EndHooks = (TEndFunc) GetProcAddress(dll, "_EndHook");
return 0;
case WMAP_KEYBDHOOKMSG :
{
counter++;
char nbr[6] = {0};
sprintf(nbr, "%i", counter);
SetWindowText(label2, nbr);
InvalidateRect(wnd, 0, 0);
return 0;
}
case WM_DESTROY :
EndHooks();
PostQuitMessage(0);
return 0;
default : return DefWindowProc(wnd, msg, w_param, l_param);
}
} |
Partager