5 static void redraw(void);
6 static void reshape(int x, int y);
7 static void keydown(int key, int x, int y);
8 static void keyup(int key, int x, int y);
9 static void button(int bn, int st, int x, int y);
10 static void motion(int x, int y);
12 static int create_window(const char *title, int width, int height);
13 static HRESULT CALLBACK handle_message(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam);
14 static int translate_vkey(int vkey);
15 static void handle_mbutton(int bn, int st, WPARAM wparam, LPARAM lparam);
18 static HINSTANCE hinst;
20 static int win_width, win_height;
23 int WINAPI WinMain(HINSTANCE hinst_, HINSTANCE hprev, char *cmdline, int showcmd)
30 wc.cbSize = sizeof wc;
31 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
32 wc.hCursor = LoadCursor(0, IDC_ARROW);
33 wc.hIcon = wc.hIconSm = LoadIcon(0, IDI_APPLICATION);
35 wc.lpfnWndProc = handle_message;
36 wc.lpszClassName = "gphgfxtest";
37 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
38 if(!RegisterClassEx(&wc)) {
39 fprintf(stderr, "failed to register window class\n");
43 if(create_window("gph-gfx test", 800, 600) == -1) {
44 UnregisterClass("gphgfxtest", hinst);
49 while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
50 TranslateMessage(&msg);
51 DispatchMessage(&msg);
61 UnregisterClass("gphgfxtest", hinst);
65 static int create_window(const char *title, int width, int height)
67 if(!(win = CreateWindow("gphgfxtest", title, WS_OVERLAPPEDWINDOW, 0, 0, width,
68 height, 0, 0, hinst, 0))) {
69 fprintf(stderr, "failed to create window\n");
78 static HRESULT CALLBACK handle_message(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam)
80 static int mouse_x, mouse_y;
97 if(x != win_width && y != win_height) {
100 reshape(win_width, win_height);
106 key = translate_vkey(wparam);
107 keydown(key, mouse_x, mouse_y);
112 key = translate_vkey(wparam);
113 keyup(key, mouse_x, mouse_y);
117 handle_mbutton(0, 1, wparam, lparam);
120 handle_mbutton(1, 1, wparam, lparam);
123 handle_mbutton(2, 1, wparam, lparam);
126 handle_mbutton(0, 0, wparam, lparam);
129 handle_mbutton(1, 0, wparam, lparam);
132 handle_mbutton(2, 0, wparam, lparam);
136 motion(lparam & 0xffff, lparam >> 16);
141 if(wparam == SC_KEYMENU || wparam == SC_SCREENSAVE || wparam == SC_MONITORPOWER) {
145 return DefWindowProc(win, msg, wparam, lparam);
152 static int translate_vkey(int vkey)
154 if(vkey >= 'A' && vkey <= 'Z') {
161 static void handle_mbutton(int bn, int st, WPARAM wparam, LPARAM lparam)
163 int x = lparam & 0xffff;
164 int y = lparam >> 16;