Sign in to follow this  

error when creating window..

This topic is 3742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to create window using the following code but window creation fails. Resgistering the class works correctly. Any idea why this could be happening??? ATOM RegisterWindowClass(HINSTANCE hInstance) { WNDCLASSEX wcex; ATOM retVal; HINSTANCE hstnce = GetModuleHandle(0); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hIcon = LoadIcon((HINSTANCE)NULL, IDI_APPLICATION); wcex.hInstance = hInstance; wcex.lpszClassName = "BD_GraphicsWindowClass"; wcex.lpszMenuName = NULL; wcex.hIconSm = NULL; retVal=RegisterClassEx(&wcex); return retVal; } HWND MakeWindow(HINSTANCE hInstance) { HWND hWnd,hParentWnd; HDC screenDC; static int offset=10; uint16 windowWidth, windowHeight; DWORD lastError; HINSTANCE hstnce = GetModuleHandle(0); if((screenDC = GetDC(NULL))==NULL) return NULL; currentDisplayMode.width = GetDeviceCaps(screenDC, HORZRES); currentDisplayMode.height = GetDeviceCaps(screenDC, VERTRES); currentDisplayMode.bitDepth = GetDeviceCaps(screenDC,BITSPIXEL); ReleaseDC(NULL, screenDC); windowWidth=300;//currentDisplayMode.width; windowHeight=200;//currentDisplayMode.width*1080/1980; hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,"BD_GraphicsWindowClass", "BD_GraphicsWindow", WS_OVERLAPPEDWINDOW, 0, 0+offset, windowWidth, windowHeight, NULL, NULL, hstnce, NULL); offset+=100; lastError = GetLastError(); if (!hWnd) return NULL; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return hWnd; } the error code generated is 0x00000578 invalid window handle. help..

Share this post


Link to post
Share on other sites
I guess the WndProc might be the cause. Please show the code of WndProc.

Are you perhaps trying to access a global HWND handle in there? Be aware that your WndProc will be called during CreateWindow(Ex), before it returns.

Share this post


Link to post
Share on other sites
Yes, the WndProc was the problem. A condition in the WndProc was causing the DefWindowProc function to not get executed. Changing the condition and allowing the DefWinfowProc to execute solved the problem. Thanks...

Share this post


Link to post
Share on other sites

This topic is 3742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this