So I wrote the UnregisterClass() function into the Window Class Destructor, and a random thought struck me. Should I also include the DestroyWindow(); WindowHandle = Null; in the destructor? More than likely the window will be destroyed through the Window Procedure, but is it a good idea to include it in the Destructor on the off chance the class is destroyed while the window is open?
Window::~Window(){
DestroyWindow(WinHandle);
WinHandle = NULL;
UnregisterClass(ClsName.c_str(), MyApp->GetInstance());
}
Window Wrapper Class
class Window{
public:
Window();
~Window();
bool DefineClass(int ClassName, WNDPROC WindowProcedure);
bool DefineClass(int ClassName, WNDPROC WindowProcedure, int Menu);
bool CreateNewWindow(int ClassName, int WinTitle, DWORD Style, DWORD ExStyle, RECT WindowSize, bool Centered, HWND Parent, LPVOID lpParam);
bool CreateNewWindow(int ClassName, int WinTitle, DWORD Style, DWORD ExStyle, RECT WindowSize, bool Centered);
void Show(void);
void Show(int nCmdShow);
HWND GetWinHandle(void);
private:
HWND WinHandle;
std::wstring ClsName;
};
The AppClass Creates the Message Window and provides functions to pass information to the seperate windows...
class AppClass{
public:
AppClass(HINSTANCE hInstance, POINT MinScreenResolution);
~AppClass();
bool CreateMsgWindow(void);
int Error(int ErrorID);
std::wstring SetText(int TextID);
int Run(void);
int Run(int AcceleratorID);
void QueryScreenResolution(void);
bool CreateTrayIcon(void);
void KillTrayIcon(void);
HINSTANCE GetInstance(void);
POINT GetScreenResolution(void);
RECT GetMaxWindowResolution(void);
HWND GetMsgWindowHandle(void);
HWND GetWindowHandle(int ClassName, int WindowTitle);
private:
HINSTANCE AppInstance;
NOTIFYICONDATA NID;
RECT MaxWindowResolution;
POINT MinScreenResolution;
POINT ScreenResolution;
Window *MsgWindow;
int InitializeProgram(void);
};
Also, in case I failed to mention, just a hobby. This application is just a excercise in the Windows API plus I wanted to test if there is any benefit to a message window. And I am testing the effectiveness of encapsulating the Window Procedure Versus having it run outside of any specific class. I have some theories on the added overhead of encapsulating the procedure... So basically just a learning program.