http://www.purebasic.fr/english/viewtop ... =0#p339508
GoodNPlenty wrote:Here's what happens: when you minimize PureBasic, UltraMon removes the window buttons by posting WM_CLOSE to the button window. By default UltraMon creates the window for the buttons in the application process, meaning that the message loop of the application gets the posted message. Usually a message loop will forward all messages to the associated window procedure, but if the application doesn't do this and instead processes the WM_CLOSE message directly, this could cause the behavior you're seeing.
Thanks GoodNPlenty, that helped me finding a workaround!
Note: #WM_CLOSE = #PB_Event_CloseWindow on Windows.
Looks like Purebasic forwards this #WM_CLOSE of UltraMon to us. So I wrote a workaround to forward #WM_CLOSE only if it is coming from
our own PureBasic windows.
The problem I had:
PureBasic Windows always get closed on minimize when using the window flags #PB_Window_MinimizeGadget and #PB_Window_SizeGadget together.
Without the flag #PB_Window_SizeGadget it does not happen!
Simple example:
Code: Select all
If OpenWindow(0, 0, 0, 400, 200, "PureBasic Window", #PB_Window_SystemMenu |
#PB_Window_ScreenCentered |
#PB_Window_MinimizeGadget |
#PB_Window_MaximizeGadget |
#PB_Window_SizeGadget )
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
EndIf
If I press the minimize window button (or window system menu 'minimize'), the program ends, because a #PB_Event_CloseWindow (#WM_CLOSE) message arrived.
Here is my workaround:
Code: Select all
;------------------------------------------------------------------------------------
;
; Workaround for compatibility problem with UltraMon and Purebasic programs
;
;------------------------------------------------------------------------------------
Global NewMap WM_CLOSE_MAP.i()
Procedure WindowCallback(hWnd, msg, wParam, lParam)
If msg = #WM_CLOSE
WM_CLOSE_MAP(Str(hWnd))=1 ; set WM_CLOSE_MAP for this PB window
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
SetWindowCallback( @WindowCallback() )
Procedure.i New_WaitWindowEvent(timeout)
;
; block #PB_Event_CloseWindow if the window has not received #WM_CLOSE before
;
If timeout = -1
event = WaitWindowEvent()
Else
event = WaitWindowEvent(timeout)
EndIf
If event = #PB_Event_CloseWindow And WM_CLOSE_MAP( Str(WindowID(EventWindow()) ) ) = 0
event = 0
EndIf
ProcedureReturn event
EndProcedure
Procedure.i New_WindowEvent()
;
; block #PB_Event_CloseWindow if the window has not received #WM_CLOSE before
;
event = WindowEvent()
If event = #PB_Event_CloseWindow And WM_CLOSE_MAP( Str(WindowID(EventWindow()) ) ) = 0
event = 0
EndIf
ProcedureReturn event
EndProcedure
Procedure.i New_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags, ParentWindowID)
;
; clear WM_CLOSE_MAP for the new window
;
win = OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title$, Flags, ParentWindowID)
If win
If window = #PB_Any
WM_CLOSE_MAP(Str(WindowID( win )))=0
Else
WM_CLOSE_MAP(Str(WindowID(window)))=0
EndIf
EndIf
ProcedureReturn win
EndProcedure
Macro WaitWindowEvent(timeout=-1)
New_WaitWindowEvent(timeout)
EndMacro
Macro WindowEvent()
New_WindowEvent()
EndMacro
Macro OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title, Flags= #PB_Window_SystemMenu, ParentWindowID=0)
New_OpenWindow(Window, x, y, InnerWidth, InnerHeight, Title, Flags, ParentWindowID)
EndMacro
;------------------------------------------------------------------------------------
;
; End UltraMon workaround
;
;------------------------------------------------------------------------------------
If OpenWindow(0, 0, 0, 400, 200, "PureBasic Window", #PB_Window_SystemMenu |
#PB_Window_ScreenCentered |
#PB_Window_MinimizeGadget |
#PB_Window_MaximizeGadget |
#PB_Window_SizeGadget )
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
EndIf
The workaround only forwards #WM_CLOSE / #PB_Event_CloseWindow if it is coming from a PureBasic window callback.
Tested with PB5.11 and PB5.20b17 (each x86 and x64), running UltraMon 3.2.2
blueznl wrote:Dunno' when, but somewhere starting from 5.xx PureBasic and UltraMon no longer like each other... If I enable UltraMon then the PureBasic IDE will close when I use the 'move to other screen' buttons of UltraMon... It would be nice to get that compatibility back again.
Can you test the workaround, please? For me it happened only on minimize. With 'move to other screen' I didn't have the problem here.