-
Notifications
You must be signed in to change notification settings - Fork 16
/
CWindow.h
309 lines (244 loc) · 8.22 KB
/
CWindow.h
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
//This file was copied and adapted from DeSmuME: http://sourceforge.net/projects/desmume/
//Authors: DeSmuME team
/* Copyright (C) 2006 yopyop
Copyright (C) 2006-2009 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CWINDOW_H
#define CWINDOW_H
#include <commctrl.h>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include "../types.h"
extern CRITICAL_SECTION win_execute_sync;
//-----------------------------------------------------------------------------
// The Toolkit - RECT wrapper
//-----------------------------------------------------------------------------
class CRect
{
public:
CRect(int x, int y, int width, int height)
{
rcRect.left = x; rcRect.top = y;
rcRect.right = x + width;
rcRect.bottom = y + height;
}
CRect(RECT rc)
{
memcpy(&rcRect, &rc, sizeof(RECT));
//rcRect = rc;
}
~CRect() {}
RECT ToMSRect() { return rcRect; }
private:
RECT rcRect;
};
// GetFontQuality()
// Returns a font quality value that can be passed to
// CreateFont(). The value depends on whether font
// antialiasing is enabled or not.
DWORD GetFontQuality();
int DrawText(HDC hDC, char* text, int X, int Y, int Width, int Height, UINT format);
void GetFontSize(HWND hWnd, HFONT hFont, LPSIZE size);
// MakeBitmapPseudoTransparent(HBITMAP hBmp, COLORREF cKeyColor, COLORREF cNewKeyColor)
// Replaces the RGB color cKeyColor with cNewKeyColor in the bitmap hBmp.
// For use with toolbars and such. Replace a key color (like magenta) with the right
// system color to make the bitmap pseudo-transparent.
void MakeBitmapPseudoTransparent(HBITMAP hBmp, COLORREF cKeyColor, COLORREF cNewKeyColor);
//-----------------------------------------------------------------------------
// Window class handling
//-----------------------------------------------------------------------------
// RegWndClass()
// Registers a window class.
// Incase the class was already registered, the function
// just does nothing and returns true.
// Returns false if registration failed.
bool RegWndClass(std::string name, WNDPROC wndProc, UINT style, int extraSize = 0);
bool RegWndClass(std::string name, WNDPROC wndProc, UINT style, HICON icon, int extraSize = 0);
// UnregWndClass()
// Unregisters a previously registered window class.
// This function will silently fail if one or more windows
// using the class still exist.
void UnregWndClass(std::string name);
//-----------------------------------------------------------------------------
// Base toolwindow class
//-----------------------------------------------------------------------------
class CToolWindow
{
public:
// CToolWindow constructor #1
// Creates a window using CreateWindow().
// If the window creation failed for whatever reason,
// hWnd will be NULL.
CToolWindow(char* className, WNDPROC proc, char* title, int width, int height);
// CToolWindow constructor #2
// Creates a window from a dialog template resource.
// If the window creation failed for whatever reason,
// hWnd will be NULL.
CToolWindow(int ID, DLGPROC proc, char* title);
// CToolWindow destructor
// Dummy destructor. The derivated toolwindow classes must
// destroy the window in their own destructors. Thus, they
// can unregister any window classes they use.
virtual ~CToolWindow();
// this must be called by the derived class constructor. sigh.
void PostInitialize();
// Show(), Hide()
// These ones are quite self-explanatory, I guess.
void Show() { ShowWindow(hWnd, SW_SHOW); }
void Hide() { ShowWindow(hWnd, SW_HIDE); }
// SetTitle()
// Changes the title of the window.
void SetTitle(char* title) { SetWindowText(hWnd, title); }
// Refresh()
// Refreshes the window. Called by RefreshAllToolWindows().
void Refresh() { InvalidateRect(hWnd, NULL, FALSE); }
// Double-linked toolwindow list.
CToolWindow* prev;
CToolWindow* next;
// Handle to the window.
HWND hWnd;
private:
int ID;
DLGPROC proc;
std::string title;
char* className;
int width, height;
int whichInit;
};
//-----------------------------------------------------------------------------
// Toolwindow handling
//-----------------------------------------------------------------------------
// OpenToolWindow()
// Adds the CToolWindow instance to the toolwindow list.
// The instance will be deleted if its hWnd member is NULL.
bool OpenToolWindow(CToolWindow* wnd);
// CloseToolWindow()
// Removes the CToolWindow instance from the toolwindow list
// and deletes it.
void CloseToolWindow(CToolWindow* wnd);
// CloseAllToolWindows()
// Deletes all the toolwindows in the list and flushes the list.
void CloseAllToolWindows();
// RefreshAllToolWindows()
// Refreshes all the toolwindows in the list.
// Called once per frame when the emu is running.
void RefreshAllToolWindows();
//-----------------------------------------------------------------------------
// The Toolkit - Toolbar API wrapper
//-----------------------------------------------------------------------------
class CToolBar
{
public:
CToolBar(HWND hParent);
~CToolBar();
HWND GetHWnd() { return hWnd; }
void Show(bool bShow);
bool Visible() { return !hidden; }
void OnSize();
void AppendButton(int uID, int uBitmapID, DWORD dwState, bool bDropdown);
void AppendSeparator();
void EnableButton(int uID, bool bEnable) {
SendMessage(hWnd, TB_ENABLEBUTTON, uID, bEnable ? TRUE:FALSE); }
void CheckButton(int uID, bool bCheck) {
SendMessage(hWnd, TB_CHECKBUTTON, uID, bCheck ? TRUE:FALSE); }
void ChangeButtonBitmap(int uID, int uBitmapID);
void EnableButtonDropdown(int uID, bool bDropdown);
void ChangeButtonID(int uIndex, int uNewID) {
SendMessage(hWnd, TB_SETCMDID, uIndex, MAKELPARAM(uNewID, 0)); }
int GetHeight();
private:
HWND hWnd;
// We have to keep the bitmaps here because destroying them
// directly after use would also destroy the toolbar.
// They'll be destroyed when the CToolBar destructor is called.
typedef std::pair<int, HBITMAP> TBitmapPair;
typedef std::map<int, TBitmapPair> TBitmapList;
TBitmapList hBitmaps;
bool hidden;
};
class WINCLASS
{
private:
HWND hwnd;
HMENU hmenu;
HINSTANCE hInstance;
char regclass[256];
int minWidth, minHeight;
public:
WINCLASS(LPSTR rclass, HINSTANCE hInst);
~WINCLASS();
bool create(LPSTR caption, int x, int y, int width, int height, int style,
HMENU menu);
bool createEx(LPSTR caption, int x, int y, int width, int height, int style, int styleEx,
HMENU menu);
bool setMenu(HMENU menu);
bool addMenuItem(u32 item, bool byPos, LPCMENUITEMINFO info);
DWORD checkMenu(UINT idd, bool check);
void Show(int mode);
void Hide();
HWND getHWnd();
CRect GetRect()
{
RECT rc; GetWindowRect(hwnd, &rc);
return CRect(rc);
}
void setMinSize(int width, int height);
enum // keepRatio flags
{
NOKEEP = 0x0,
KEEPX = 0x1,
KEEPY = 0x2,
FULLSCREEN = 0x4,
};
void sizingMsg(WPARAM wParam, LPARAM lParam, LONG keepRatio = NOKEEP);
void setClientSize(int width, int height);
};
class THREADCLASS
{
friend DWORD WINAPI ThreadProc(LPVOID lpParameter);
HANDLE hThread;
public:
THREADCLASS();
virtual ~THREADCLASS();
bool createThread();
void closeThread();
protected:
DWORD threadID;
virtual DWORD ThreadFunc()=NULL;
};
class TOOLSCLASS : public THREADCLASS
{
private:
HWND hwnd;
HINSTANCE hInstance;
DLGPROC dlgproc;
int idd;
char class_name[256];
char class_name2[256];
DWORD doOpen();
void doClose();
protected:
DWORD ThreadFunc();
public:
TOOLSCLASS(HINSTANCE hInst, int IDD, DLGPROC wndproc);
virtual ~TOOLSCLASS();
bool open(bool useThread=true);
bool close();
void regClass(LPSTR class_name, WNDPROC wproc, bool SecondReg = false);
void unregClass();
};
#endif