I have been trying recently to create a window class using the Windows API in C++. However, whenever I attempt to call ShowWindow, the function sets the last error to 1400 (ERROR_INVALID_WINDOW_HANDLE). After trying for a while, I stumbled across the following example: http://blogs.msdn.com/b/oldnewthing/archive/2005/04/22/410773.aspx#comments
Even creating a new project (I use MSVC Express 2008) and copying the code exactly (which I hate to do), I discovered that, while the code successfully created a window, the ShowWindow function still reported error 1400. Here is an excerpt from the code found at the above link:
int PASCAL
WinMain(HINSTANCE hinst, HINSTANCE, LPSTR, int nShowCmd)
{
g_hinst = hinst;
if (SUCCEEDED(CoInitialize(NULL))) {
InitCommonControls();
RootWindow *prw = RootWindow::Create();
if (prw) {
ShowWindow(prw->GetHWND(), nShowCmd);
int error = GetLastError(); //Line added by me, error gets set to 1400.
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
CoUninitialize();
}
return 0;
}
(The full code can be found at the above link)
If anyone has any ideas on how to have the window handle as a member variable of a class without receiving error 1400 on ShowWindow, I would greatly appreciate some help.