aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/windows/winpublic.cpp
blob: 397a3b54c90f9ba0fbef313d5ad01b5ea463078b (plain)
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
// 6 april 2015
#include "uipriv_windows.hpp"

void uiWindowsEnsureDestroyWindow(HWND hwnd)
{
	if (DestroyWindow(hwnd) == 0)
		logLastError(L"error destroying window");
}

void uiWindowsEnsureSetParentHWND(HWND hwnd, HWND parent)
{
	if (parent == NULL)
		parent = utilWindow;
	if (SetParent(hwnd, parent) == 0)
		logLastError(L"error setting window parent");
}

void uiWindowsEnsureAssignControlIDZOrder(HWND hwnd, LONG_PTR *controlID, HWND *insertAfter)
{
	SetWindowLongPtrW(hwnd, GWLP_ID, *controlID);
	(*controlID)++;
	setWindowInsertAfter(hwnd, *insertAfter);
	*insertAfter = hwnd;
}

void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, int x, int y, int width, int height)
{
	RECT r;

	r.left = x;
	r.top = y;
	r.right = x + width;
	r.bottom = y + height;
	if (SetWindowPos(hwnd, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER) == 0)
		logLastError(L"error moving window");
}

// do these function even error out in any case other than invalid parameters?! I thought all windows had rects
void uiWindowsEnsureGetClientRect(HWND hwnd, RECT *r)
{
	if (GetClientRect(hwnd, r) == 0) {
		logLastError(L"error getting window client rect");
		// zero out the rect on error just to be safe
		r->left = 0;
		r->top = 0;
		r->right = 0;
		r->bottom = 0;
	}
}

void uiWindowsEnsureGetWindowRect(HWND hwnd, RECT *r)
{
	if (GetWindowRect(hwnd, r) == 0) {
		logLastError(L"error getting window rect");
		// zero out the rect on error just to be safe
		r->left = 0;
		r->top = 0;
		r->right = 0;
		r->bottom = 0;
	}
}