Jump to content
snaileater

Limiting moves of a borderless window ...

Recommended Posts

snaileater

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 ...

Share this post


Link to post
Share on other sites
reb

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

Share this post


Link to post
Share on other sites
reb

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

Share this post


Link to post
Share on other sites
snaileater

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 ...

Share this post


Link to post
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

  • Similar Content

    • Reziskonh
      By Reziskonh
      Hi, everybody
      I look for GUI whose behavior similar to the message of an email client or antivirus
      In other words:
          Any PC screen able to calculate the size
          To consider the Task bar size
          To find the lower corner on the right/below and to nestle on it

      Notes:
      In GUI the GUICtrlCreateEdit field (as option) - that can be received and displayed through variable information
      Thanks a lot
      PS
      I use the translator, excuse if something is not clear
       

    • VollachR
      By VollachR
      Hi,
      I'd like to show a progress bar for an operation performed by an external program my script is running silently, I want to show it in a GUI I created using the GUICtrlCreateProgress but I have no idea how to do it.
      The important thing to point out is that there's no way of knowing how long the external program will run, as it is a file splitter and it depends on the size of file it splits and the split parts size.
      Can someone point me in the right direction or give me an example how to do so?
      This is my RunWait command:
      RunWait($MYFILES1 & '\fsplit.exe -split ' & $Size & ' mb ' & $File & " -f " & $File & "." & $extension) It uses multiple variables declared and set earlier in the script, how will I got about having the progress of that command shown using GUICtrlCreateProgress ? Is it possible?
      Thank you.
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry and I hope to find the answer here
      I want to create a graphical user interface
      but I want to hide the system menu
      I mean the window menu
      Is this possible?
      If is possible please give me how to do that
      Thanks in advance
    • helmar
      By helmar
      I was playing around with simple GUI creation.  I tend to like parameter driven coding (in prior life (years ago) as Clipper/FoxPro/dBase coder).  Just wanted to see what I could do with a GUI.
      #Region options, includes Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode #include <GUIConstantsEx.au3> #EndRegion options, includes Global Const $nCols = 2, $nRows = 6, $nSpacer = 10, $nBtnWidth = 150, $nBtnHeight = 30 Global $xName = 0, $xID = 0 Global $nGUIWidth = ($nCols * $nBtnWidth) + (($nCols + 1) * $nSpacer) Global $nGUIHeight = ($nRows * $nBtnHeight) + (($nRows + 1) * $nSpacer) Global $hMainGUI = GUICreate("Calculated GUI", $nGUIWidth, $nGUIHeight, -1, -1) For $xRows = 1 to $nRows ;in this arrangement, tabbing is left to right, then next row For $xCols = 1 to $nCols ;reverse the order of this line with the prior line for top to bottom tabbing, then next col $xName += 1 $xID += 1 Global $Dummy = GUICtrlCreateButton("Button" & $xName, _ ($nBtnWidth * ($xCols - 1)) + (($xCols - 1) * $nSpacer) + $nSpacer, _ ($nBtnHeight* ($xRows - 1)) + (($xRows - 1) * $nSpacer) + $nSpacer, _ $nBtnWidth, _ $nBtnHeight) GUICtrlSetOnEvent($xID+2, "Handler") Next Next GUISetOnEvent($GUI_EVENT_CLOSE, "CloseApp") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func CloseApp() Exit EndFunc Func Handler() MsgBox(0,0,"Button " & @GUI_CtrlId - 2) EndFunc  
    • Gowrisankar
      By Gowrisankar
      Dear members,
      I'm trying to move unread mails from Inbox to a different folder using OutlookEx UDF.
      But its not working for me. I'm not sure what mistake I do.
      I get the error code 6 when the following is executed. From the UDF it is observed that  "No or an invalid item has been specified".
      Note : The UDF version is 1.3.3.1. AutoIt version (v3.3.14.2).
      #include <OutlookEX.au3> Global $oOutlook = _OL_Open() If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended) Global $aOL_Item = _OL_ItemFind($oOutlook, "*\Inbox", $olMail, "[UnRead]=True", "", "", "Subject", "", 1) If $aOL_Item[0][0] = 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemMove Example Script", "Could not find a task item in folder 'Outlook-UDF-Test\SourceFolder\Tasks'. @error = " & @error) _ArrayDisplay($aOL_Item, "OutlookEX UDF: _OL_ItemFind Example Script - Unread mails") _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "*\Outlook-UDF-Test\TargetFolder\Mail") If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemMove Example Script", "Error moving specified task. @error = " & @error) Any help is deeply appreciated. Thanks in advance.
      Thanks and regards,
      Gowrisankar R.
×