calsoftware
asked on
Create Window failure
static wchar_t g_szClassName[] = L"MyTestApp";
static HINSTANCE g_hInst = NULL;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClass;
HWND hwnd;
MSG Msg;
g_hInst = hInstance;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = NULL;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndCl
{
MessageBox(0, L"Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
L"",
WS_OVERLAPPEDWINDOW & ~WS_BORDER,
CW_USEDEFAULT, CW_USEDEFAULT, 320, 240,
NULL, NULL, GetModuleHandle(NULL), NULL);
DWORD x = GetLastError();
if(hwnd == NULL)
{
MessageBox(0, L"Window Creation Failed!", L"Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
ShowWindow(hwnd, SW_HIDE);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
In the above code snippet the hwnd is always NULL, Any ideas
Thanks all
ASKER
Nope doesn't work.The GetLastError() code is 0.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The code you posted does not contain WndProc.
ASKER
Well i didn't post that, as it's trivial. But i do have a wndproc
check the code I posted - it works always. It can be start point.
ASKER
Thanks it works, the hwnd is not null any more, but when i change
ShowWindow(hWnd, nCmdShow); to ShowWindow(hWnd, SW_HIDE); the windproc function does nothing.. there are no events flowing.
ShowWindow(hWnd, nCmdShow); to ShowWindow(hWnd, SW_HIDE); the windproc function does nothing.. there are no events flowing.
Because this function really does nothing. You need to add the handlers you need there.
ASKER
OK. Thanks
Try this code:
hwnd = CreateWindowEx(0,
g_szClassName, g_szClassName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
NULL, NULL, hInstance, NULL);