Jump to content

Limiting moves of a borderless window ...


Recommended Posts

Hi,

i'm trying to limit the moves of a borderless GUI. i'm on an example taken from Moving and Resizing PopUp GUIs.

I'm using the _SendMessage function so far :

While 1     
    Switch GUIGetMsg()         
    Case $GUI_EVENT_PRIMARYDOWN             
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)   
    EndSwitch
Wend

I would like to add some constrain on the X,Y coords of the window (for ex. forbid X exceeding 1000) ...

How could i achieve that ? It Seems to me that i have to follow two events at the same time (EVENT_PRIMARYDOWN + EVENT_MOUSEMOVE) but i'm not sure to be on the right track ...

Could anybody help me ?

Thanks ...

Link to comment
Share on other sites

WinGetPos  returns an arry 

     $aArray[0] = X position
    $aArray[1] = Y position
    $aArray[2] = Width
    $aArray[3] = Height

if x y exceeds your desired position then reset window to what you want.

MEASURE TWICE - CUT ONCE

Link to comment
Share on other sites

Hi,

i'm trying to limit the moves of a borderless GUI. i'm on an example taken from Moving and Resizing PopUp GUIs.

I'm using the _SendMessage function so far :

I would like to add some constrain on the X,Y coords of the window (for ex. forbid X exceeding 1000) ...

How could i achieve that ? It Seems to me that i have to follow two events at the same time (EVENT_PRIMARYDOWN + EVENT_MOUSEMOVE) but i'm not sure to be on the right track ...

Could anybody help me ?

Thanks ...

This Limits the x,y co-ordinates

; Original code - martin
#include <GuiconstantsEx.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
Global Const $SC_DRAGMOVE = 0xF012
Local $xlimit = 300, $xlimit2 = 900, $Ylimit = 300, $Ylimit2 = 500
Local $Pos, $mP[1]
HotKeySet("{ESC}", "On_Exit")

local $hGUI = GUICreate("X", 100, 100, -1, -1, $WS_POPUP)
GUISetBkColor(0x00FF00, $hGUI)
$hButton = GUICtrlCreateButton("Test", 10, 35, 80, 30)
GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_PRIMARYDOWN
            _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
        Case $hButton
            On_Button()
    EndSwitch
    Checkx()
WEnd

Func On_Button()
    MsgBox(0, "Hi", "Button Pressed")
EndFunc   ;==>On_Button

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

Func Checkx()
    $Info = GUIGetCursorInfo($hGUI)
    if $Info[2] = 1  then return

$Pos = WinGetPos($hGUI,"") ; x, y, width, height
if $Pos > $xlimit or $Pos < $xlimit2 then
    MsgBox(0,"","Returned")
    return
EndIf

Select

    Case $Pos[0] < $xlimit and $Info[2] = 0
        WinMove($hGUI,"",$xlimit,$Pos[1])
        if $Pos[1] < $ylimit Then WinMove($hGUI,"",$Pos[0], $ylimit)
        if $Pos[1] > $ylimit2 Then WinMove($hGUI,"",$Pos[0], $ylimit2)

    Case $Pos[0] > $xlimit2 and $Info[2] = 0
        WinMove($hGUI,"",$xlimit2,$Pos[1])
        if $Pos[1] < $ylimit Then WinMove($hGUI,"",$Pos[0], $ylimit)
        if $Pos[1] > $ylimit2 Then WinMove($hGUI,"",$Pos[0], $ylimit2)

    Case $Pos[0] > $xlimit and $Info[2] = 0
        if $Pos[1] < $ylimit Then WinMove($hGUI,"",$Pos[0], $ylimit)
        if $Pos[1] > $ylimit2 Then WinMove($hGUI,"",$Pos[0], $ylimit2)


EndSelect
EndFunc

 

MEASURE TWICE - CUT ONCE

Link to comment
Share on other sites

Thanks for spending some time on my question Reb but your code is not doing what i would like :

Your code allow the user to go out the "restricted area" and then check whether the moved window respect the x,y limitations.

What i would like is a way to force the x,y limitations during the move ...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...