There is no compilation errors. Though, the program is unable to create window after registering it. Any suggestions?
Code:
#include <windows.h>
#include <string>
using namespace std;
#define DisplayError(text, caption) MessageBox(NULL, text,caption, MB_ICONEXCLAMATION | MB_OK)
class Wnd
{
WNDPROC WinControls;
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
string WindowName;
bool child;
public:
Wnd() { }
void start(char * Tile , WNDPROC Procedure )
{
WindowName = Tile;
}
bool WndPrepare( HINSTANCE hInstance, int menuID, bool Menubuild = false )
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_NOCLOSE | CS_DBLCLKS;
wcex.lpfnWndProc = WinControls;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
if( Menubuild)
wcex.lpszMenuName = MAKEINTRESOURCE(menuID);
else
wcex.lpszMenuName = NULL;
wcex.lpszClassName = (LPCWSTR)WindowName.c_str();
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
if(!RegisterClassEx(&wcex))
{
DisplayError( L"HUGE ERROR MAN WINDOW CAN'T REGISTER)", L"ALERT" );
return false;
}
return true;
}
void WndBuild( HINSTANCE * hInstance, int nCmdShow)
{
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"NarraDream",(LPCWSTR)WindowName.c_str(), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, *hInstance, NULL);
if(!hwnd)
{
DisplayError(L"Could not create Window",L"ALERT");
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
}
int Run(void)
{
while (GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return (int) Msg.wParam;
}
};
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
Wnd wnd;
wnd.start("hey", WinProc);
wnd.WndPrepare(0, false);
wnd.WndBuild(&hInstance,nCmdShow);
return ( wnd.Run() );
}