CreateWindowEx(): "Cannot find the file specified"
Hello,
Since hours I try to get my code running which is supposed to create a standard window using CreateWindowEx(). However, the returned handle is always NULL.
I called GetLastError() and received the error string. It reads:
"The system cannot find the file specified."
Uh, which file? The only files I'm implicitly dealing with are icon and cursor files. But I use default icons and I checked their handles in the debugger and everything seems to be okay. To be 100% sure I even created my own icons and loaded them using MAKEINTRESOURCE, but nope, still get this confusing error message. I couldn't create an own cursor file, but I tried to use other values like IDC_HAND, but again the same error.
I think I better post some code now:
Code:
HRESULT CMyApp::InitInstance()
{
HRESULT hr = 0;
WNDCLASSEX wc;
ZeroMemory( &wc, sizeof( WNDCLASSEX ) );
static TCHAR szClassName[] = _T("def_w32_app");
wc.cbSize = sizeof( WNDCLASSEX );
wc.hbrBackground = (HBRUSH) GetStockObject( COLOR_WINDOW );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hIconSm = wc.hIcon;
wc.lpszMenuName = NULL;
wc.hInstance = GetInstance();
wc.lpfnWndProc = ::WindowProc;
wc.lpszClassName = szClassName;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
hr = RegisterClassEx( &wc );
if( FAILED( hr ) )
{
CError e;
e.Display();
return E_FAIL;
}
DWORD dwStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
DWORD dwExStyle = NULL;
m_hWnd = CreateWindowEx( dwExStyle, szClassName, "Test Window", dwStyle, 100, 100, 800, 600, NULL, NULL, GetInstance(), NULL );
if( m_hWnd == NULL )
{
CError e;
e.Display();
return E_FAIL;
}
return S_OK;
}
There you go, the whole function as it is now. GetInstance() returns a handle to the instance of the running program. I checked the value, it's okay. The CError class will only call GetLastError() and display a message box. Everything else should be self explanatory.
Any idea what's going wrong here?