-
Notifications
You must be signed in to change notification settings - Fork 2
/
baseWindow.cpp
236 lines (201 loc) · 5.36 KB
/
baseWindow.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include "headerUI.h"
BaseWindow::BaseWindow()
{
dwStyle=WS_OVERLAPPEDWINDOW;
exStyle=WS_EX_LEFT;
xPos=CW_USEDEFAULT;
yPos=CW_USEDEFAULT;
width=CW_USEDEFAULT;
height=CW_USEDEFAULT;
hPen = CreatePen(PS_SOLID, 1, RGB(0,0,0));
LOGBRUSH logBrush={
BS_SOLID,
RGB(0,200,0),
(ULONG_PTR)NULL
};
hBrush=CreateBrushIndirect(&logBrush);
}
HWND BaseWindow::getHWND(){
return hWnd;
}
ATOM BaseWindow::registerClass(WNDCLASS &WndClass)
{
WindowClass=&WndClass;
return RegisterClass(WindowClass);
}
bool BaseWindow::init(LPCTSTR windowName)
{
DWORD dwStyle=WS_OVERLAPPEDWINDOW;
int x=CW_USEDEFAULT;
int y=CW_USEDEFAULT;
int cx=CW_USEDEFAULT;
int cy=CW_USEDEFAULT;
HWND hwndParent=NULL;
HMENU hMenu=NULL;
HINSTANCE hInst=NULL;
hWnd = CreateWindow(
WindowClass->lpszClassName, // the window class name
windowName, // The window title
dwStyle, // Window style as overlapped
x, // Default screen position of upper left
y, // corner of our window as x,y...
cx, // Default window size
cy, // ....
hwndParent, // No parent window
hMenu, // No menu
hInst, // Program Instance handle
0 // No window creation data
);
return (hWnd)?TRUE:FALSE;
}
bool BaseWindow::init(LPCTSTR windowName="New window",
DWORD dwStyle=WS_OVERLAPPEDWINDOW,
int x=CW_USEDEFAULT,
int y=CW_USEDEFAULT,
int cx=CW_USEDEFAULT,
int cy=CW_USEDEFAULT,
HWND hwndParent=NULL,
HMENU hMenu=NULL,
HINSTANCE hInst=NULL)
{
hWnd = CreateWindow(
WindowClass->lpszClassName, // the window class name
windowName, // The window title
dwStyle, // Window style as overlapped
x, // Default screen position of upper left
y, // corner of our window as x,y...
cx, // Default window size
cy, // ....
hwndParent, // No parent window
hMenu, // No menu
hInst, // Program Instance handle
0 // No window creation data
);
width=cx;
height=cy;
return (hWnd)?TRUE:FALSE;
}
bool BaseWindow::initEx(
DWORD dwExStyle=WS_EX_LEFT,
LPCTSTR windowName="New window",
DWORD dwStyle=WS_OVERLAPPEDWINDOW,
int x=CW_USEDEFAULT,
int y=CW_USEDEFAULT,
int cx=CW_USEDEFAULT,
int cy=CW_USEDEFAULT,
HWND hwndParent=NULL,
HMENU hMenu=NULL,
HINSTANCE hInst=NULL)
{
hWnd = CreateWindowEx(
dwExStyle,
WindowClass->lpszClassName, // the window class name
windowName, // The window title
dwStyle, // Window style as overlapped
x, // Default screen position of upper left
y, // corner of our window as x,y...
cx, // Default window size
cy, // ....
hwndParent, // No parent window
hMenu, // No menu
hInst, // Program Instance handle
0 // No window creation data
);
width=cx;
height=cy;
return (hWnd)?TRUE:FALSE;
}
bool BaseWindow::show(int nCmdShow=SW_SHOW)
{
return ShowWindow(hWnd, nCmdShow); // Display the window
}
RECT BaseWindow::getRect()
{
RECT aRect;
GetClientRect(hWnd, &aRect);
return aRect;
}
int BaseWindow::getWidth()
{
RECT aRect;
GetClientRect(hWnd, &aRect);
return aRect.right-aRect.left;
}
int BaseWindow::getHeight()
{
RECT aRect;
GetClientRect(hWnd, &aRect);
return aRect.bottom-aRect.top;
}
bool BaseWindow::SetWindowPosition(int x,int y,int cx,int cy)
{
return SetWindowPos(hWnd,HWND_TOP,x,y,cx,cy,SWP_SHOWWINDOW);
}
bool BaseWindow::printText(int xt=0, int yt=0,const char* str="")
{
HDC hDC;
hDC=GetDC(hWnd);
//SetBkMode(hDC, TRANSPARENT); // Set text background mode
TextOut(hDC,xt,yt,str,strlen(str));
ReleaseDC(hWnd,hDC);
return TRUE;
}
bool BaseWindow::lineTo(int x,int y)
{
bool result;
HDC hDC;
hDC=GetDC(hWnd);
SetBkMode(hDC, TRANSPARENT); // Set text background mode
result=LineTo(hDC,x,y);
ReleaseDC(hWnd,hDC);
return result;
}
bool BaseWindow::line(int xPrev,int yPrev,int x, int y)
{
bool result;
HDC hDC;
HPEN hOldPen;
HBRUSH hOldBrush;
hDC=GetDC(hWnd);
hOldPen=(HPEN)SelectObject(hDC, hBrush);
hOldBrush=(HBRUSH)SelectObject(hDC, hPen);
SetROP2(hDC, R2_NOTXORPEN);
//SetBkMode(hDC, TRANSPARENT); // Set text background mode
MoveToEx(hDC,xPrev,yPrev,NULL);
result=LineTo(hDC,x,y);
//DeleteObject(hDC,SelectObject(hDC, hOldPen));
//DeleteObject(hDC,SelectObject(hDC, hOldBrush));
ReleaseDC(hWnd,hDC);
return result;
}
bool BaseWindow::moveTo(int x,int y)
{
bool result;
HDC hDC;
hDC=GetDC(hWnd);
result=MoveToEx(hDC,x,y,NULL);
ReleaseDC(hWnd,hDC);
return result;
}
bool BaseWindow::hitCursor(int x, int y, int marker)
{
RECT rt;
POINT point;
point.x=x;
point.y=y;
SetRect(&rt,x-marker,y-marker,x+marker,y+marker);
return PtInRect(&rt,point);
}
bool BaseWindow::refreshWindow()
{
return InvalidateRect(hWnd,NULL,FALSE);
}
bool BaseWindow::setBrush(HBRUSH*){
return true;
}
bool BaseWindow::setPen(HPEN* phPen){
if (hPen)
DeleteObject(hPen);
hPen=*phPen;
return true;
}