How to move a borderless window?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

Well, I think the subject tells all about my problem. Can you help me?
I wanna move a window with the param: #PB_Window_Borderless.

Cu @ll, merendo
--
I've been hiding - What am I hiding from???
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by traumatic.

you can 'fake a drag on the captionbar' by putting the following into your window callback procedure:

Code: Select all

If Msg=#WM_LBUTTONDOWN ;mousebutton clicked...
   ; fool windows telling that the user is
   ; actually dragging the application caption bar
   SendMessage_(hWnd, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
you could of course easily extend this to only work when a certain region of you window has been clicked...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

Thanks. The code works (though I don't know how to create a windowcallback :wink: ) But please tell me: How to extend the callback that it only works in one region???

Cu @ll, merendo
--
I've been hiding - What am I hiding from???
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by traumatic.

lParam holds the mouse coordinates

Code: Select all

mouse_x.w = lParam       ; x-coord
mouse_y.w = lParam >> 16 ; y-coord
you could test if the mouse is in the desired part of your window and only then do the sendmessage_() thingy
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by traumatic.

i made a small example for you (there are always different ways to do this of course):

this will only allow dragging on the upper 60 px. (my > 16

If (my < 60)
SendMessage_(hWnd, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
EndSelect
ProcedureReturn DefWindowProc_(hWnd, Msg, wParam, lParam)
EndProcedure


hWnd = OpenWindow(0, 0, 0, 320, 240, #PB_Window_Borderless, "test4merendo")
SetWindowCallback(@WndProc())

Repeat
If PeekMessage_(@WndProcMsg, 0, 0, 0, #PM_REMOVE) ; check if there is a message for this window
If WndProcMsg = #WM_QUIT : EndIf
; else translate and dispatch the message to this window
TranslateMessage_(@WndProcMsg)
DispatchMessage_(@WndProcMsg)
EndIf
ForEver
[/code]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

STRIKE!!! It works! Big thanks, traumatic. You've really helped me.

Cu @ll, merendo
--
I've been hiding - What am I hiding from???
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

Well, i've made it a little differently...

Procedure MoveCallBack(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
mouse_x.w = lParam ; x-coord
mouse_y.w = lParam >> 16 ; y-coord
If mouse_x.w > 0 And mouse_x.w 255 And mouse_y.w < 300
conditionsdone = 1 ; Test if the mouse is inside the right region. If so, allow to move the window (vari conditionsdone)
Else
conditionsdone = 0
EndIf
If Message=#WM_LBUTTONDOWN And conditionsdone ;mousebutton clicked... and check if the vari allows to move...
; fool windows telling that the user is
; actually dragging the application caption bar
SendMessage_(WindowID, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
ProcedureReturn Result
EndProcedure

Cu @ll, merendo
--
I've been hiding - What am I hiding from???
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Or you could save yourself some typing and NOT pu t it in a callback...

Code: Select all

Repeat
  EventID=WaitWindowEvent()
  Select EventID
    Case #PB_Event_CloseWindow
    quit=1
  
    Case #WM_LBUTTONDOWN
      ReleaseCapture_()
      SendMessage_(hWnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
       
  EndSelect
Until quit=1
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by traumatic.

just one thing:
lParam doesn't always hold the mouse-coordinates
e.g. in case #WM_SIZE it holds the width and the height
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by traumatic.
Originally posted by Paul

Or you could save yourself some typing and NOT pu t it in a callback...
i said there are about a thousand different ways :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

And YOUR way, traumatic, was the first one I got to know, so it's the one i'm gonna use. Very simple, isn't ìt? :wink:

Cu @ll, merendo
--
I've been hiding - What am I hiding from???
Post Reply