-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathXG_Window.cpp
80 lines (77 loc) · 2.45 KB
/
XG_Window.cpp
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
#include "XG_Window.hpp"
#include <cassert>
/*static*/ LRESULT CALLBACK
XG_Window::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
XG_Window *pWindow;
if (uMsg == WM_NCCREATE)
{
if (LPCREATESTRUCT pCS = reinterpret_cast<LPCREATESTRUCT>(lParam))
{
::SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pCS->lpCreateParams));
pWindow = static_cast<XG_Window*>(pCS->lpCreateParams);
pWindow->m_hWnd = hwnd;
}
else
{
return 0;
}
}
else
{
pWindow = reinterpret_cast<XG_Window *>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
if (!pWindow)
return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
if (uMsg == WM_NCDESTROY)
{
pWindow->m_hWnd = nullptr;
}
}
return pWindow->WindowProcDx(hwnd, uMsg, wParam, lParam);
}
BOOL XG_Window::RegisterClassDx(HINSTANCE hInstance/* = ::GetModuleHandle(nullptr)*/)
{
WNDCLASSEX wcx = { sizeof(wcx) };
wcx.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wcx.lpfnWndProc = WindowProc;
wcx.cbWndExtra = DLGWINDOWEXTRA;
wcx.hInstance = hInstance;
wcx.hIcon = ::LoadIcon(nullptr, IDI_APPLICATION);
wcx.hCursor = ::LoadCursor(nullptr, IDC_ARROW);
wcx.hbrBackground = reinterpret_cast<HBRUSH>(static_cast<INT_PTR>(COLOR_3DFACE + 1));
wcx.lpszClassName = GetWndClassName();
ModifyWndClassDx(wcx);
return ::RegisterClassEx(&wcx);
}
/*static*/ INT_PTR CALLBACK
XG_Dialog::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
XG_Dialog *pDialog;
if (uMsg == WM_INITDIALOG || uMsg == WM_CREATE)
{
assert(s_pTrapping != nullptr);
pDialog = s_pTrapping;
::SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LPARAM>(pDialog));
pDialog->m_hWnd = hwnd;
}
else
{
pDialog = reinterpret_cast<XG_Dialog *>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
if (!pDialog)
{
if (uMsg == WM_MEASUREITEM || uMsg == WM_SIZE)
{
assert(s_pTrapping != nullptr);
pDialog = s_pTrapping;
pDialog->m_hWnd = hwnd;
return pDialog->DialogProcDx(hwnd, uMsg, wParam, lParam);
}
return 0;
}
if (uMsg == WM_NCDESTROY)
{
pDialog->m_hWnd = nullptr;
}
}
return pDialog->DialogProcDx(hwnd, uMsg, wParam, lParam);
}