Moving a borderless window ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Moving a borderless window ?

Post by TI-994A »

Michael Vogel wrote:... how to keep #PB_EventType_LeftClick events working?
This should do it nicely:

Code: Select all

Enumeration
  #MainWindow
  #Canvas
  #CanvasMenu
EndEnumeration

Procedure CanvasProc(hWnd, uMsg, wParam, lParam)
  Static winX, winY
  Shared sysProc
  Select uMsg
    Case #WM_LBUTTONDOWN
      winX = WindowX(#MainWindow)
      winY = WindowY(#MainWindow)
      SendMessage_(WindowID(#MainWindow), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
      SendMessage_(GadgetID(#Canvas), #WM_LBUTTONUP, #MK_LBUTTON, lParam)
    Case #WM_LBUTTONUP 
      If winX = WindowX(#MainWindow) And winY = WindowY(#MainWindow)
        DisplayPopupMenu(#CanvasMenu, WindowID(#MainWindow))
      EndIf
  EndSelect
  ProcedureReturn CallWindowProc_(sysProc, hWnd, uMsg, wParam, lParam)
EndProcedure

CreatePopupMenu(#CanvasMenu)
MenuItem(1, "Left single click...")

wFlags = #PB_Window_ScreenCentered | #PB_Window_BorderLess
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 500, 500, "", wFlags)
CanvasGadget(#Canvas, 5, 5, 490, 490)
SetWindowColor(#MainWindow, #Red)
sysProc = SetWindowLongPtr_(GadgetID(#Canvas), #GWL_WNDPROC, @CanvasProc())

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Michael Vogel
Addict
Addict
Posts: 2677
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Moving a borderless window ?

Post by Michael Vogel »

Hm,
good idea to use the control key, thanks - anyhow it is still tricky for me, because the window seems be glued now to the mouse cursor and even when I release the control key, the window follows the cursor. This wouldn't be a problem, but I need another click to "free" the window - and this should not start an action. I added

Code: Select all

Case #WM_LBUTTONUP
		If Down
			Down=0
		EndIf
now, this seems to work now.

Now I try to do some finetuning, a first click in the top area produces four (!) events here, must check that as well.

Code: Select all

Enumeration
	#MainWindow
	#MenuQuit
EndEnumeration

Define p.POINT,m.POINT
Global Counter

Procedure ShowCounter()

	StartDrawing(CanvasOutput(0))
	DrawText(10,10,"Counter "+Str(counter),#Black,#White)
	DrawText(400,10,"Down "+Str(Down),#Black,#White)
	LineXY(0,50,500,50,#Red)
	DrawingMode(#PB_2DDrawing_Outlined)
	Box(0,0,500,500,#Blue)
	StopDrawing()

EndProcedure

WinID=OpenWindow(#MainWindow,0,0,500,500,"", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
SetWindowColor(#MainWindow,#Red)
CanvasGadget(0,0,0,500,500);   <------
AddKeyboardShortcut(#MainWindow,#PB_Shortcut_Escape,#MenuQuit)

ShowCounter()
StickyWindow(#MainWindow,1)
HideWindow(#MainWindow,0)

Repeat
	Select WaitWindowEvent()

	Case #PB_Event_CloseWindow
		Break

	Case #PB_Event_Menu
		If EventGadget()=#MenuQuit
			Break
		EndIf

	Case #PB_Event_Gadget
		Select EventGadget()
		Case 0
			If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
				;If GetAsyncKeyState_(#VK_CONTROL) & 32768 = 0
				If GetKeyState_(#VK_CONTROL)&128=0
					Debug FilterButton
					If 1;FilterButton=0
						x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
						y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
						If y<55
							Counter+1
							ShowCounter()
						Else
							StartDrawing(CanvasOutput(0))
							Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
							StopDrawing()
						EndIf
					Else
						FilterButton=0
					EndIf
				EndIf
			EndIf
		EndSelect

	Case #WM_MOUSEMOVE
		GetCursorPos_(m.POINT)
		ScreenToClient_(WindowID(#MainWindow),m)
		If Down
			Down=2
			ResizeWindow(#MainWindow,WindowX(#MainWindow)+m\x-p\x,WindowY(#MainWindow)+m\y-p\y,#PB_Ignore,#PB_Ignore)
		EndIf

	Case #WM_LBUTTONUP
		If Down
			Down=0
			; FilterButton=1
		EndIf

	Case #WM_LBUTTONDOWN
		;If GetAsyncKeyState_(#VK_CONTROL) & 32768 = 32768
		If GetKeyState_(#VK_CONTROL)&128
			GetCursorPos_(p.POINT)
			ScreenToClient_(WindowID(#MainWindow),p)
			Down = 1
		Else
			Down = 0
			Debug "Null"
		EndIf

	EndSelect
ForEver
User avatar
Michael Vogel
Addict
Addict
Posts: 2677
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Moving a borderless window ?

Post by Michael Vogel »

Michael Vogel wrote:Hm,
good idea to use the control key, thanks - anyhow it is still tricky for me, because the window seems be glued now to the mouse cursor and even when I release the control key, the window follows the cursor. This wouldn't be a problem, but I need another click to "free" the window - and this should not start an action. I added

Code: Select all

Case #WM_LBUTTONUP
		If Down
			Down=0
		EndIf
now, this seems to work now.

Now I try to do some finetuning, a first click in the top area produces four (!) events here, must check that as well.

Code: Select all

Enumeration
	#MainWindow
	#MenuQuit
EndEnumeration

Define p.POINT,m.POINT
Global Counter

Procedure ShowCounter()

	StartDrawing(CanvasOutput(0))
	DrawText(10,10,"Counter "+Str(counter),#Black,#White)
	DrawText(400,10,"Down "+Str(Down),#Black,#White)
	LineXY(0,50,500,50,#Red)
	DrawingMode(#PB_2DDrawing_Outlined)
	Box(0,0,500,500,#Blue)
	StopDrawing()

EndProcedure

WinID=OpenWindow(#MainWindow,0,0,500,500,"", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
SetWindowColor(#MainWindow,#Red)
CanvasGadget(0,0,0,500,500);   <------
AddKeyboardShortcut(#MainWindow,#PB_Shortcut_Escape,#MenuQuit)

ShowCounter()
StickyWindow(#MainWindow,1)
HideWindow(#MainWindow,0)

Repeat
	Select WaitWindowEvent()

	Case #PB_Event_CloseWindow
		Break

	Case #PB_Event_Menu
		If EventGadget()=#MenuQuit
			Break
		EndIf

	Case #PB_Event_Gadget
		Select EventGadget()
		Case 0
			If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
				;If GetAsyncKeyState_(#VK_CONTROL) & 32768 = 0
				If GetKeyState_(#VK_CONTROL)&128=0
					Debug FilterButton
					If 1;FilterButton=0
						x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
						y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
						If y<55
							Counter+1
							ShowCounter()
						Else
							StartDrawing(CanvasOutput(0))
							Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
							StopDrawing()
						EndIf
					Else
						FilterButton=0
					EndIf
				EndIf
			EndIf
		EndSelect

	Case #WM_MOUSEMOVE
		GetCursorPos_(m.POINT)
		ScreenToClient_(WindowID(#MainWindow),m)
		If Down
			Down=2
			ResizeWindow(#MainWindow,WindowX(#MainWindow)+m\x-p\x,WindowY(#MainWindow)+m\y-p\y,#PB_Ignore,#PB_Ignore)
		EndIf

	Case #WM_LBUTTONUP
		If Down
			Down=0
			; FilterButton=1
		EndIf

	Case #WM_LBUTTONDOWN
		;If GetAsyncKeyState_(#VK_CONTROL) & 32768 = 32768
		If GetKeyState_(#VK_CONTROL)&128
			GetCursorPos_(p.POINT)
			ScreenToClient_(WindowID(#MainWindow),p)
			Down = 1
		Else
			Down = 0
			Debug "Null"
		EndIf

	EndSelect
ForEver
Some moments later...
...I was able to put all pieces together, now it works fine (hopefully :) ) - so it's time to thank you both once again (I will have now also a closer look into TI-99A's code)...

Code: Select all

Select EventType()

			Case #PB_EventType_MouseMove
				GetCursorPos_(MoveEnd)
				ScreenToClient_(WinApps,MoveEnd)
				If ControlMode&%10
					ResizeWindow(#WinApps,WindowX(#WinApps)+MoveEnd\x-MoveStart\x,WindowY(#WinApps)+MoveEnd\y-MoveStart\y,#PB_Ignore,#PB_Ignore)
				Else
					CursorUpdate(); Highlights buttons etc.
				EndIf

			Case #PB_EventType_LeftButtonUp
				ControlMode&%01

			Case #PB_EventType_LeftButtonDown
				If GetAsyncKeyState_(#VK_CONTROL)&$8000=$8000
					ControlMode=%11
					GetCursorPos_(MoveStart)
					ScreenToClient_(WinApps,MoveStart)
				Else
					ControlMode=%00
				EndIf

			Case #PB_EventType_LeftClick
				Debug ControlMode
				If ControlMode=#Null
					Click(); Action!
				EndIf
			:
			:
mestnyi
Addict
Addict
Posts: 1000
Joined: Mon Nov 25, 2013 6:41 am

Re: Moving a borderless window ?

Post by mestnyi »

Post Reply