Page 1 of 1

Popup windows

Posted: Wed Nov 01, 2017 7:40 pm
by Justin
To create custom menus, tool tips or drop down lists. They are different from borderless windows, they don't steal the focus from the main window i think.
WS_POPUP in windows and GTK_WINDOW_POPUP in linux, no idea on mac.

Re: Popup windows

Posted: Wed Nov 01, 2017 8:02 pm
by mestnyi
+1

Re: Popup windows

Posted: Wed Nov 01, 2017 8:12 pm
by nco2k

Code: Select all

Debug #WS_POPUP
Debug #PB_Window_BorderLess
c ya,
nco2k

Re: Popup windows

Posted: Wed Nov 01, 2017 11:25 pm
by Justin
I didn't know.
I had to do this to create a custom tooltip, menu or list in a canvas in windows.
So i am asking a crossplatform way to do this:

Code: Select all

EnableExplicit

Global.i winmain, event, b1, winchild, oldexstyle, canvas

Procedure evhandler()
	Debug "mm"
EndProcedure

Procedure evclick()
	CloseWindow(winchild)
EndProcedure

Procedure winmainproc(hwnd, msg.i, wparam.i, lparam.i)
	Select msg
		Case #WM_NCLBUTTONDOWN 
			If IsWindow(winchild)
				CloseWindow(winchild)
			EndIf
			ProcedureReturn #PB_ProcessPureBasicEvents
			
		Default : ProcedureReturn #PB_ProcessPureBasicEvents
	EndSelect
EndProcedure

Procedure winproc(hwnd.i, msg.i, wparam.i, lparam.i)
	Select msg
		Case #WM_MOUSEACTIVATE 
			ProcedureReturn #MA_NOACTIVATE
			
		Default : ProcedureReturn #PB_ProcessPureBasicEvents
	EndSelect
EndProcedure

winmain = OpenWindow(#PB_Any, 10, 10, 300, 200, "test")
SetWindowCallback(@winmainproc(), winmain)
b1 = ButtonGadget(#PB_Any, 0, 0, 80, 30, "test")

Repeat
	event = WaitWindowEvent()
	Select event
		Case #PB_Event_Gadget
			Select EventGadget()
				Case b1
					If IsWindow(winchild)
						CloseWindow(winchild) 
						
					Else
						winchild = OpenWindow(#PB_Any, 20, 40, 80, 80, "", #PB_Window_BorderLess | #PB_Window_NoActivate , WindowID(winmain))
						SetWindowCallback(@winproc(), winchild)
						canvas = CanvasGadget(#PB_Any, 0, 0, 80, 80)
						BindGadgetEvent(canvas, @evhandler(), #PB_EventType_MouseMove)
						BindGadgetEvent(canvas, @evclick(), #PB_EventType_LeftClick)
						If StartDrawing(CanvasOutput(canvas))
							DrawingMode(#PB_2DDrawing_Transparent)
							DrawText(0, 0, "ToolTip", RGB(0, 0, 0))
						StopDrawing()
						EndIf 
					EndIf 
			EndSelect
			
		Case #PB_Event_LeftClick
			If IsWindow(winchild) : CloseWindow(winchild) : EndIf 
			
		Case #PB_Event_DeactivateWindow
			If IsWindow(winchild) : CloseWindow(winchild) : EndIf 
	EndSelect
	
Until event = #PB_Event_CloseWindow