Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Problems Unregistering Windows

Recommended Posts

I'm making a program which uses several windows. I thought I'd reduce the amount of coding in my program by making a function which does everything that is needed to open a window, since all of the windows I need are basically the same. In fact, the only way they really differ is that they all use different message procedures.

The code below, therefore, accepts a window class which already has a value in the .lpszClassName variable and the .lpfnWndProc variable. The rest of the window class in then filled with default values, the class in registered, a window is created and then the window class is immediately unregistered. After that graphics are enabled and the window is scaled, but that's incidental to the problem (I think). The function returns a handle to the window that it has created.

The problem is that the window classes aren't unregistering, so when I try to create the same window again the error message box pops up. You can see that I'm printing the return value of the UnregisterClass statement to the console, and the value that's printed out is always zero. I've read on msdn that this means that the statement has failed, for whatever reason. If anybody has any idea what is causing it to fail, I'd be extremely glad of any advice.

HWND OpenWindow(HINSTANCE Instance, int CmdShow,HDC* DeviceContext, HGLRC* RenderContext,const int WindowWidth, const int WindowHeight, const char* WindowTitle,WNDCLASS WindowClass) {/* Definition of the window class */WindowClass.hInstance = Instance;WindowClass.style = CS_DBLCLKS; WindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); WindowClass.lpszMenuName = NULL; WindowClass.cbClsExtra = 0; WindowClass.cbWndExtra = 0; WindowClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); /* If the window class fails to register then display message box and exit */if(!RegisterClass(&WindowClass)) {MessageBox(HWND_DESKTOP, "Window registration failed", "Error", MB_OK | MB_ICONWARNING);return NULL;}/* Creation of window */HWND WindowHandle; WindowHandle = CreateWindow(WindowClass.lpszClassName, WindowTitle,WS_OVERLAPPEDWINDOW |WS_CLIPCHILDREN,CW_USEDEFAULT, CW_USEDEFAULT, WindowWidth, WindowHeight,HWND_DESKTOP, NULL, Instance, NULL);printf("%i, ", UnregisterClass(WindowClass.lpszClassName, Instance));/* Draws the window to the screen */ShowWindow(WindowHandle, CmdShow); /* Activates graphics for the window */EnableGraphics(WindowHandle, DeviceContext, RenderContext);/* Sets the viewport and viewing mode for the window */int WindowShape[4];glGetIntegerv(GL_VIEWPORT, WindowShape);ResizeWindow(WindowShape[2], WindowShape[3]);return WindowHandle;}

Share this post


Link to post
Share on other sites

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  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.