-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasewin.h
More file actions
125 lines (85 loc) · 2.33 KB
/
basewin.h
File metadata and controls
125 lines (85 loc) · 2.33 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
template <class DERIVED>
class BaseWindow
{
public:
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
DERIVED *pThis = NULL;
try {
if (uMsg == WM_NCCREATE)
{
CREATESTRUCT* pCreate = (CREATESTRUCT*)lParam;
pThis = (DERIVED*)pCreate->lpCreateParams;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pThis);
pThis->m_hwnd = hwnd;
}
else
{
pThis = (DERIVED*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
}
if (pThis)
return pThis->HandleMessage(uMsg, wParam, lParam);
}
catch (std::exception & stdExp)
{
printf("Exception Caught: %s\n", stdExp.what());
//return 1;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
BaseWindow() : m_hwnd(NULL) { }
BOOL Create(
PCWSTR lpWindowName,
DWORD dwStyle,
int nCmdShow,
DWORD dwExStyle = 0,
int x = CW_USEDEFAULT,
int y = CW_USEDEFAULT,
int nWidth = CW_USEDEFAULT,
int nHeight = CW_USEDEFAULT,
HWND hWndParent = 0,
HMENU hMenu = 0
)
{
WNDCLASS wc = {0};
wc.lpfnWndProc = DERIVED::WindowProc;
wc.hInstance = GetModuleHandle(NULL);
wc.lpszClassName = (LPCWSTR)ClassName();
RegisterClass(&wc);
m_hwnd = CreateWindowEx(
dwExStyle, (LPCWSTR)ClassName(), (LPCWSTR)lpWindowName, dwStyle, x, y,
nWidth, nHeight, hWndParent, hMenu, GetModuleHandle(NULL), this
);
if( !m_hwnd )
return FALSE;
ShowWindow( m_hwnd, nCmdShow );
return TRUE;
}
HWND Window() const { return m_hwnd; }
protected:
virtual PCWSTR ClassName() const = 0;
virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) = 0;
HWND m_hwnd;
};
class MainWindow : public BaseWindow<MainWindow>
{
Device m_Dev;
GpuCpu m_GPCP;
public:
MainWindow(){
m_bWin = false;
}
PCWSTR ClassName() const { return L"Main Window Class"; }
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
HRESULT choosefilename(WCHAR* szFile);
HRESULT Init(GpuParam Par);
HRESULT Resize(GpuParam Par);
void Clear();
void Close();
void Render(UINT* DataIn, UINT* DataOut);
void SetScaleOffset(float Scl, bool bTyp, bool bCol);
void Shift(short Shift);
UINT m_width;
UINT m_height;
bool m_bWin;
};