The reason for asking about this is that in the following code, if I return 0 in the WM_NCDESTROY handler, I get an invalid memory access when the window is created for the second time. This leads me to think that PB also needs to free some resources under the hood (props, etc.). Indeed, returning the result from the old Proc (the one before subclassing) works fine.
Any thoughts on this?
Code: Select all
Procedure WinCB(hWnd, uMsg, wParam, lParam)
OldParentCallback = GetProp_(hWnd, "MainWindowProc")
If OldParentCallback <> 0
Select uMsg
Case #WM_NCDESTROY
SetWindowLongPtr_(hWnd, #GWL_WNDPROC, OldParentCallback)
RemoveProp_(hWnd, "MainWindowProc")
;Returning 0 does not work (invalid mem access)... Is it because PB also needs to free its gadget props internally?
ProcedureReturn 0
;But this works:
;ProcedureReturn CallWindowProc_(OldParentCallback, hWnd, uMsg, wParam, lParam)
EndSelect
;Call the old proc
ProcedureReturn CallWindowProc_(OldParentCallback, hWnd, uMsg, wParam, lParam)
EndIf
EndProcedure
For test = 0 To 1
If OpenWindow(0, 0, 0, 200, 40, Str(Test), #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OldParentCallback = SetWindowLongPtr_(WindowID(0), #GWL_WNDPROC, @WinCB())
SetProp_(WindowID(0), "MainWindowProc", OldParentCallback)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
CloseWindow(0)
EndIf
Next