// Find out if the window was created
if( !hWnd ) // If the window was not created,
return 0; // stop the application
// Display the window to the user
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
// Decode and treat the messages
// as long as the application is running
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
// If the user wants to close the application
case WM_DESTROY:
// then close it
PostQuitMessage(WM_QUIT);
break;
default:
// Process the left-over messages
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
// If something was not done, let it go
return 0;
}
LPCWSTR = Long Pointer Constant WIDE String
In other words a pointer to a UNICODE string is expected.
constchar *WndName = "A Simple Window"; This is a normal
8 bit ascii string.
With Microsoft Visual Studio, the default program setup is for the USE of UNICODE string - hence the problem.
To prevent this problem always wrap your strings literals with the _TEXT macro like this when coding for with Microsoft Windows;
constchar *WndName = _TEXT("A Simple Window");
(Note you can also use _T("string") in Visual Studio, but I don't think DEV C++ understands _T);
The _TEXT macro either does nothing (not in UNICODE code) or it prepends the L in front of the string literal to indicate a UNICODE string if in UNICODE mode. See my next post below about the L directive.