Popup windows

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Popup windows

Post 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.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: Popup windows

Post by mestnyi »

+1
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Popup windows

Post by nco2k »

Code: Select all

Debug #WS_POPUP
Debug #PB_Window_BorderLess
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Popup windows

Post 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
Post Reply