Windows port: putting some bases in place for new tool system.
Here, clean window class handler, which prevents regging a class twice and unregging a class which isn't regged. The stuff I'm adding is not set in a stone. It may be modified or even removed at any moment.
This commit is contained in:
parent
8167bff3c4
commit
6e36bfe1fd
|
@ -22,6 +22,67 @@
|
||||||
#include "CWindow.h"
|
#include "CWindow.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Window class handling
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
vector<string> ReggedWndClasses;
|
||||||
|
|
||||||
|
bool RegWndClass(string name, WNDPROC wndProc, int extraSize)
|
||||||
|
{
|
||||||
|
return RegWndClass(name, wndProc, 0, NULL, extraSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RegWndClass(string name, WNDPROC wndProc, HICON icon, int extraSize)
|
||||||
|
{
|
||||||
|
return RegWndClass(name, wndProc, 0, icon, extraSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RegWndClass(string name, WNDPROC wndProc, UINT style, HICON icon, int extraSize)
|
||||||
|
{
|
||||||
|
// If the class is already regged, don't re-reg it
|
||||||
|
if (find(ReggedWndClasses.begin(), ReggedWndClasses.end(), name) != ReggedWndClasses.end())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
WNDCLASSEX wc;
|
||||||
|
|
||||||
|
wc.cbSize = sizeof(wc);
|
||||||
|
wc.lpszClassName = name.c_str();
|
||||||
|
wc.hInstance = hAppInst;
|
||||||
|
wc.lpfnWndProc = wndProc;
|
||||||
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||||
|
wc.hIcon = icon;
|
||||||
|
wc.lpszMenuName = 0;
|
||||||
|
wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
||||||
|
wc.style = style;
|
||||||
|
wc.cbClsExtra = 0;
|
||||||
|
wc.cbWndExtra = extraSize;
|
||||||
|
wc.hIconSm = 0;
|
||||||
|
|
||||||
|
if (RegisterClassEx(&wc) != 0)
|
||||||
|
{
|
||||||
|
// If registration succeeded, add the class name into the list
|
||||||
|
ReggedWndClasses.push_back(name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnregWndClass(string name)
|
||||||
|
{
|
||||||
|
vector<string>::iterator it = find(ReggedWndClasses.begin(), ReggedWndClasses.end(), name);
|
||||||
|
|
||||||
|
// If the class wasn't regged, we can't unreg it :P
|
||||||
|
if (it == ReggedWndClasses.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Otherwise unreg the class and remove its name from the list
|
||||||
|
UnregisterClass(name.c_str(), hAppInst);
|
||||||
|
ReggedWndClasses.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
WINCLASS::WINCLASS(LPSTR rclass, HINSTANCE hInst)
|
WINCLASS::WINCLASS(LPSTR rclass, HINSTANCE hInst)
|
||||||
{
|
{
|
||||||
memset(regclass, 0, sizeof(regclass));
|
memset(regclass, 0, sizeof(regclass));
|
||||||
|
|
|
@ -24,6 +24,23 @@
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Window class handling
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool RegWndClass(string name, WNDPROC wndProc, int extraSize = 0);
|
||||||
|
bool RegWndClass(string name, WNDPROC wndProc, HICON icon, int extraSize = 0);
|
||||||
|
bool RegWndClass(string name, WNDPROC wndProc, UINT style, HICON icon, int extraSize = 0);
|
||||||
|
|
||||||
|
void UnregWndClass(string name);
|
||||||
|
|
||||||
|
|
||||||
class WINCLASS
|
class WINCLASS
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1473,23 +1473,6 @@ void ChangeLanguage(int id)
|
||||||
MenuInit();
|
MenuInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int RegClass(WNDPROC Proc, LPCTSTR szName)
|
|
||||||
{
|
|
||||||
WNDCLASS wc;
|
|
||||||
|
|
||||||
wc.style = CS_DBLCLKS;
|
|
||||||
wc.cbClsExtra = wc.cbWndExtra=0;
|
|
||||||
wc.lpfnWndProc=Proc;
|
|
||||||
wc.hInstance=hAppInst;
|
|
||||||
wc.hIcon=LoadIcon(hAppInst,"ICONDESMUME");
|
|
||||||
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
|
|
||||||
wc.hbrBackground=(HBRUSH)(COLOR_BACKGROUND);
|
|
||||||
wc.lpszMenuName=(LPCTSTR)NULL;
|
|
||||||
wc.lpszClassName=szName;
|
|
||||||
wc.cbClsExtra = 0;
|
|
||||||
wc.cbWndExtra = 0;
|
|
||||||
return RegisterClass(&wc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ExitRunLoop()
|
static void ExitRunLoop()
|
||||||
{
|
{
|
||||||
|
@ -1605,7 +1588,7 @@ int _main()
|
||||||
}*/
|
}*/
|
||||||
ColorCtrl_Register();
|
ColorCtrl_Register();
|
||||||
|
|
||||||
if (!RegClass(WindowProcedure, "DeSmuME"))
|
if (!RegWndClass("DeSmuME", WindowProcedure, CS_DBLCLKS, LoadIcon(hAppInst, "ICONDESMUME")))
|
||||||
{
|
{
|
||||||
MessageBox(NULL, "Error registering windows class", "DeSmuME", MB_OK);
|
MessageBox(NULL, "Error registering windows class", "DeSmuME", MB_OK);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
@ -1981,6 +1964,8 @@ int _main()
|
||||||
if (lpBackSurface != NULL) IDirectDraw7_Release(lpBackSurface);
|
if (lpBackSurface != NULL) IDirectDraw7_Release(lpBackSurface);
|
||||||
if (lpDDraw != NULL) IDirectDraw7_Release(lpDDraw);
|
if (lpDDraw != NULL) IDirectDraw7_Release(lpDDraw);
|
||||||
|
|
||||||
|
UnregWndClass("DeSmuME");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue