2014-07-17 22:11:16 -05:00
|
|
|
/* 17 july 2014 */
|
|
|
|
|
|
|
|
#include "winapi_windows.h"
|
2014-07-17 23:29:15 -05:00
|
|
|
#include "_cgo_export.h"
|
2014-07-17 22:11:16 -05:00
|
|
|
|
|
|
|
#define windowclass L"gouiwindow"
|
|
|
|
|
2014-07-17 23:22:21 -05:00
|
|
|
static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2014-07-17 22:11:16 -05:00
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
RECT r;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_COMMAND:
|
2014-07-17 23:22:21 -05:00
|
|
|
return forwardCommand(hwnd, uMsg, wParam, lParam);
|
2014-07-25 14:58:24 -05:00
|
|
|
case WM_NOTIFY:
|
|
|
|
return forwardNotify(hwnd, uMsg, wParam, lParam);
|
2014-07-17 22:11:16 -05:00
|
|
|
case WM_SIZE:
|
|
|
|
if (GetClientRect(hwnd, &r) == 0)
|
2014-07-17 23:22:21 -05:00
|
|
|
xpanic("error getting client rect for Window in WM_SIZE", GetLastError());
|
2014-07-17 22:11:16 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-08-04 10:05:39 -05:00
|
|
|
HWND newWindow(LPWSTR title, int width, int height, BOOL child, void *data)
|
2014-07-17 22:11:16 -05:00
|
|
|
{
|
|
|
|
HWND hwnd;
|
2014-08-04 10:05:39 -05:00
|
|
|
DWORD style;
|
|
|
|
HWND parent;
|
2014-07-17 22:11:16 -05:00
|
|
|
|
2014-08-04 10:05:39 -05:00
|
|
|
style = WS_OVERLAPPEDWINDOW;
|
|
|
|
parent = NULL;
|
|
|
|
if (child) {
|
2014-08-04 12:13:59 -05:00
|
|
|
style = WS_CHILD | WS_VISIBLE;
|
2014-08-04 10:05:39 -05:00
|
|
|
parent = msgwin;
|
|
|
|
}
|
2014-07-17 22:11:16 -05:00
|
|
|
hwnd = CreateWindowExW(
|
|
|
|
0,
|
|
|
|
windowclass, title,
|
2014-08-04 10:05:39 -05:00
|
|
|
style,
|
2014-07-17 22:11:16 -05:00
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
width, height,
|
2014-08-04 10:05:39 -05:00
|
|
|
parent, NULL, hInstance, data);
|
2014-07-17 22:11:16 -05:00
|
|
|
if (hwnd == NULL)
|
2014-07-17 23:22:21 -05:00
|
|
|
xpanic("Window creation failed", GetLastError());
|
2014-08-04 10:05:39 -05:00
|
|
|
if (!child)
|
|
|
|
calculateBaseUnits(hwnd);
|
2014-07-17 22:11:16 -05:00
|
|
|
return hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void windowClose(HWND hwnd)
|
|
|
|
{
|
|
|
|
if (DestroyWindow(hwnd) == 0)
|
|
|
|
xpanic("error destroying window", GetLastError());
|
|
|
|
}
|