2014-08-14 09:42:10 -05:00
|
|
|
// 17 july 2014
|
2014-07-17 22:11:16 -05:00
|
|
|
|
|
|
|
#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;
|
2014-08-14 15:12:43 -05:00
|
|
|
LRESULT lResult;
|
2014-07-17 22:11:16 -05:00
|
|
|
|
2014-08-14 15:12:43 -05:00
|
|
|
data = getWindowData(hwnd, uMsg, wParam, lParam, &lResult, storeWindowHWND);
|
|
|
|
if (data == NULL)
|
|
|
|
return lResult;
|
|
|
|
if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult))
|
|
|
|
return lResult;
|
2014-07-17 22:11:16 -05:00
|
|
|
switch (uMsg) {
|
|
|
|
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);
|
|
|
|
}
|
2014-08-14 15:17:44 -05:00
|
|
|
xmissedmsg("Window", "windowWndProc()", uMsg);
|
2014-08-14 09:42:10 -05:00
|
|
|
return 0; // unreached
|
2014-07-17 22:11:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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 18:46:49 -05:00
|
|
|
HWND newWindow(LPWSTR title, int width, int height, void *data)
|
2014-07-17 22:11:16 -05:00
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
|
|
|
|
hwnd = CreateWindowExW(
|
|
|
|
0,
|
|
|
|
windowclass, title,
|
2014-08-04 18:46:49 -05:00
|
|
|
WS_OVERLAPPEDWINDOW,
|
2014-07-17 22:11:16 -05:00
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
width, height,
|
2014-08-04 18:46:49 -05:00
|
|
|
NULL, 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-07-17 22:11:16 -05:00
|
|
|
return hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void windowClose(HWND hwnd)
|
|
|
|
{
|
|
|
|
if (DestroyWindow(hwnd) == 0)
|
|
|
|
xpanic("error destroying window", GetLastError());
|
|
|
|
}
|