I need a window, that more or less behaves like a popup menu. That means a click somewhere outside of the window (i.e. the window loses its focus) will close the window.
I know that sounds easy to do, but I'm not able to get my testcode running without an IMA (when I try to open the window again)...
Code: Select all
Macro LOWORD(Value)
Value & $FFFF
EndMacro
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
If IsWindow(1)
If uMsg = #WM_ACTIVATE And LOWORD(wParam) = #WA_INACTIVE ;window loses focus
If hWnd = WindowID(1)
CloseWindow(1)
EndIf
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(0,0,0,320,240,"parent",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0,10,10,100,25,"Show Popup")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case 0
quit = 1
Case 1
CloseWindow(1)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 0
If IsWindow(1) = 0
If OpenWindow(1,0,0,250,120,"Popup",#PB_Window_SystemMenu, WindowID(0))
ButtonGadget(1,10,10,100,25,"Close Popup")
SetWindowCallback(@WinCallback(), 1)
EndIf
EndIf
Case 1
If IsWindow(1)
CloseWindow(1)
SetWindowCallback(#Null, 1)
EndIf
EndSelect
EndSelect
Until quit = 1
EndIf