move window without title bar

Just starting out? Need help? Post your questions and find answers here.
User avatar
doctorized
Addict
Addict
Posts: 854
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

move window without title bar

Post by doctorized »

I am making a custom Message Requester window with better icions and bigger font.
My custom title bar is this:

Code: Select all

ContainerGadget(#MRE_Cont1, 0,0,WndWidth,30)
	TextGadget(#MRE_Title,0,0,WndWidth,30,"  " + Title, #SS_CENTERIMAGE)
	SetGadgetColor(#MRE_Title,#PB_Gadget_BackColor,$FFF4EF)
	CloseIcon = CatchImage(#PB_Any, ?CloseStart, ?CloseEnd - ?CloseStart)
	ImageGadget(#MRE_Close, WndWidth-32,-1,32,32,ImageID(CloseIcon))
CloseGadgetList()
and I make the window like:

Code: Select all

If Window <> 0
	OpenWindow(#MRE_Window,#PB_Ignore,#PB_Ignore, 400, 300, "", #PB_Window_WindowCentered|#PB_Window_Invisible|#PB_Window_BorderLess,WindowID(Window))
Else
	OpenWindow(#MRE_Window,#PB_Ignore,#PB_Ignore, 400, 300, "", #PB_Window_WindowCentered|#PB_Window_Invisible|#PB_Window_BorderLess)
EndIf
Var Window is used when I have a parent window. What can I do to be able to move this window?
Mesa
Enthusiast
Enthusiast
Posts: 345
Joined: Fri Feb 24, 2012 10:19 am

Re: move window without title bar

Post by Mesa »

not resizable:

Code: Select all

Procedure Exit()
		End
EndProcedure

Procedure LeftMouseDown()
		Shared MouseDown, OffsetX, OffsetY
		MouseDown = #True
		offsetX = WindowMouseX(0)
		OffsetY = WindowMouseY(0)
EndProcedure

Procedure LeftMouseUp()
		Shared MouseDown
		MouseDown = #False
EndProcedure

Procedure MouseMove()
		Shared MouseDown, OffsetX, OffsetY
		If MouseDown And GetGadgetAttribute(1,#PB_Canvas_Buttons)&#PB_Canvas_LeftButton
				ResizeWindow(0,DesktopMouseX()-OffsetX,DesktopMouseY()-OffsetY,#PB_Ignore,#PB_Ignore)
		EndIf
EndProcedure

If OpenWindow(0, 0, 0, 800, 600, "Moveable window", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
		ButtonGadget(0,10,10,100,25,"Exit")
		BindEvent(#PB_Event_Gadget,@Exit(),0,0,#PB_EventType_LeftClick)
		
		CanvasGadget(1,120,10,200,200)
		BindEvent(#PB_Event_Gadget,@LeftMouseDown(),0,1,#PB_EventType_LeftButtonDown)
		BindEvent(#PB_Event_Gadget,@LeftMouseUp()  ,0,1,#PB_EventType_LeftButtonUp)
		BindEvent(#PB_Event_Gadget,@MouseMove()    ,0,1,#PB_EventType_MouseMove)
		
		If StartDrawing(CanvasOutput(1))
				Box(0,0,OutputWidth(),OutputHeight(),RGB(0,0,128))
				StopDrawing()
		EndIf
		
		Repeat:WaitWindowEvent():ForEver
EndIf
resizable:

Code: Select all

OpenWindow(1,0,0,800,600,"rezizable",#WS_SIZEBOX|#PB_Window_BorderLess|#PB_Window_ScreenCentered)

ButtonGadget(1,10,10,60,20,"Close")

Repeat
    Select WaitWindowEvent()
        Case #PB_Event_CloseWindow, #PB_Event_Gadget
            Break
        Case #WM_LBUTTONDOWN
            SendMessage_(WindowID(1), #WM_NCLBUTTONDOWN, #HTCAPTION , #Null)
    EndSelect
ForEver
M.
User avatar
doctorized
Addict
Addict
Posts: 854
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: move window without title bar

Post by doctorized »

Mesa wrote:not resizable:
.........
resizable:
..........

M.
Can it be attached to a TextGadget?
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: move window without title bar

Post by Saki »

@Mesa
This is cleverly done with the small procedures and the BindEvent.

Another important little things is missing.
The support for DPI Aware, otherwise it does not go with scaling over 100%...
On 4K it looks like the gadget just disappears when you click on it.

Try EnableExplicit, this works so not with Shared

Code: Select all

Procedure RightMouseDown()
  Shared MouseDown, OffsetX, OffsetY
  MouseDown=#True
  offsetX=WindowMouseX(window_ID)/DesktopResolutionX()
  OffsetY=WindowMouseY(window_ID)/DesktopResolutionY()
EndProcedure

Procedure MouseMove()
  Shared MouseDown, OffsetX, OffsetY
  If MouseDown And GetGadgetAttribute(canvas_ID,#PB_Canvas_Buttons)&#PB_Canvas_RightButton
    ResizeWindow(window_ID, DesktopMouseX()/DesktopResolutionX()-OffsetX, DesktopMouseY()/DesktopResolutionY()-OffsetY, #PB_Ignore, #PB_Ignore)
  EndIf
EndProcedure
地球上の平和
User avatar
doctorized
Addict
Addict
Posts: 854
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: move window without title bar

Post by doctorized »

@Saki
Yew, you are right. I have a 27-inches screen, 2K resolution, and with high scalings the window moves suddenly to the left. I added canvas on the back and everything is fine now. Thank you both for you answers!
Post Reply