Jump to content
  • Advertisement
Sign in to follow this  
zap85

error when creating window..

This topic is 4107 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!