Hi Jose,
I encountered a behavior with CWindow that I'd like your opinion on. It appears that the life-cycle of a window created with pWindow (CWindow) can only handle creating the window exactly once. If you DIM pWindow, create the window, destroy the window (and set its hWindow to Null), create the window a second time which will then result in an error. This is because you can not manually set the window handle to null. If you change the code to allow manually setting the window handle to null then it will still fail because CWindow attempts to RegisterClass a second time resulting in the Atom = 0 error. Therefore, it seems that in order to recreate the same window over and over you need to DIM pWindow, create the window, destroy the window, DELETE pWindow (which will unregister the class in the destructor).
In my case, I want to keep the pWindow variable alive through multiple creation/destroy of the window. Basically, re-use the pWindow variable over and over.
I had to make two changes to CWindow to make this happen:
(1) Modify the Set for the hWindow.
' =====================================================================================
' Sets the window handle
' =====================================================================================
Private Property CWindow.hWindow (ByVal HWnd As HWnd)
' IF m_hwnd = NULL THEN m_hwnd = hwnd
m_hwnd = HWnd
End Property
' =====================================================================================
(2) Modify the Create code to test for an existing Atom.
If m_wAtom = 0 Then
m_wAtom = CWindow_RegisterClass(m_wszClassName, m_hInstance, lpfnWndProc)
' If m_wAtom = 0 Then Exit Function
End If
What do you think? Would you be okay with changing the code of CWindow to allow the behaviour I've described above?