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
|
// 17 july 2014
#include "winapi_windows.h"
#include "_cgo_export.h"
#define windowclass L"gouiwindow"
static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
void *data;
RECT r;
LRESULT shared;
data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
if (data == NULL) {
// the lpParam is available during WM_NCCREATE and WM_CREATE
if (uMsg == WM_NCCREATE) {
storelpParam(hwnd, lParam);
data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
storeWindowHWND(data, hwnd);
}
// act as if we're not ready yet, even during WM_NCCREATE (nothing important to the switch statement below happens here anyway)
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
if (sharedWndProc(hwnd, uMsg, wParam, lParam, &shared))
return shared;
switch (uMsg) {
case WM_SIZE:
if (GetClientRect(hwnd, &r) == 0)
xpanic("error getting client rect for Window in WM_SIZE", GetLastError());
windowResize(data, &r);
return 0;
case WM_CLOSE:
windowClosing(data);
return 0;
default:
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
xmissedmsg("Window", "windowWinProc()", uMsg);
return 0; // unreached
}
DWORD makeWindowWindowClass(char **errmsg)
{
WNDCLASSW wc;
ZeroMemory(&wc, sizeof (WNDCLASSW));
wc.lpfnWndProc = windowWndProc;
wc.hInstance = hInstance;
wc.hIcon = hDefaultIcon;
wc.hCursor = hArrowCursor;
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
wc.lpszClassName = windowclass;
if (RegisterClassW(&wc) == 0) {
*errmsg = "error registering Window window class";
return GetLastError();
}
return 0;
}
HWND newWindow(LPWSTR title, int width, int height, void *data)
{
HWND hwnd;
hwnd = CreateWindowExW(
0,
windowclass, title,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
width, height,
NULL, NULL, hInstance, data);
if (hwnd == NULL)
xpanic("Window creation failed", GetLastError());
return hwnd;
}
void windowClose(HWND hwnd)
{
if (DestroyWindow(hwnd) == 0)
xpanic("error destroying window", GetLastError());
}
|