Unregister WindowProc

Started by
9 comments, last by Madhed 13 years, 6 months ago
Quote:Original post by FrEEzE2046
Calling DestroyWindow can't be the solution. IMHO this function doesn't do anything else than sending the message WM_QUIT to the specified handle.


Your humble opinion is wrong. ;)

from the MSDN docs:

Quote:
DestroyWindow Function

Destroys the specified window. The function sends WM_DESTROY and WM_NCDESTROY messages to the window to deactivate it and remove the keyboard focus from it. The function also destroys the window's menu, flushes the thread message queue, destroys timers, removes clipboard ownership, and breaks the clipboard viewer chain (if the window is at the top of the viewer chain).


After calling DestroyWindow() no messages will be sent to the window... since it does not exist anymore. Visually as well as logically.

A window class is, indeed, some kind of class or template or blueprint or whatever you want to call it. There can be multiple instances of this window class and you should only call UnregisterClass() when all instances of that specific class are already destroyed.

EDIT:
Oh, I just figured I missed some of your posts. It seems to me you're mixing up the concepts of window classes and windows a bit.
Treat the window class as a class and the window as an instance of that class.

The registration of the window class should reside in some static member function or outside of the class definition since it registers a class and not an instance of that class. It must occur before any D3DWindow is created.
Likewise the unregistration of the window class must occur after all D3DWindows are deleted.

You are right in passing the pointer to your D3DWindow instance via LPCREATEPARAMS.
When you receive the create message in the WndProc, store this pointer in some window related storage area. (there are multiple possible solutions to this and some seem to have negative side-effects. SetWindowLongPtr() seems to be the most straight-forward approach to me and has worked so far)
When the WndProc gets called by ProcessMessage() retrieve the pointer via GetWindowLongPtr() and cast it to D3DWindow. From there on you can access the D3DWindow instance.
When you delete an instance of D3DWindow call DestroyWindow(). Since that function destroys every evidence left of the window, you can be sure that all following calls to your WndProc will not return a pointer to that deleted object via GetWindowLongPtr().

[Edited by - Madhed on October 17, 2010 7:43:35 PM]

This topic is closed to new replies.

Advertisement