Jump to content

GUI X Y Position


 Share

Recommended Posts

I have a script that runs on a number of different systems where the desktops are a different width and height.

I have been trying to get my mind around how to maintain the x y position of each Gui window irrespective of the desktops width and height so that the user interface of the script pretty much has the same look and feel given any screen size and the windows are keep in view.

I was thinking that you could base the calculation on expressing the x and y position of the window as a percentage of the corresponding desktop width and height which when applied to any desktop width or height gives a close proximity solution for the x y position for each window based on the desktop on which the script is running.

The x y co-ordinate percentage on which the x y position of the window is based could be read from registry (where the script is installed) or an INI file in order to be able to calculate and determine the x y positions of the window based on the desktop width or height on which it is running.

Is there a better or more accurate solution.

Ant..

Edited by anixon
Link to comment
Share on other sites

I had the same issue and here's what I did;

; Screen Resolution Identifier
$g_ScrWidth = @DesktopWidth ; 1280
$g_ScrHeight = @DesktopHeight ; 960

; GUI Location Depeding on Screen Resolution: Min 800x600
Switch $g_ScrWidth
    Case 1280
        $guiloc_x = 200     
    Case 1024
        $guiloc_x = 50
    Case 800
        $guiloc_x = 50
EndSwitch
Switch $g_ScrHeight
    Case 960
        $guiloc_y = 700
    Case 768
        $guiloc_y = 578
    Case 600
        $guiloc_y = 410
EndSwitch
GuiCreate("" & $title, 825, 185, $guiloc_x, $guiloc_y)
Edited by aslani

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

Thanks to everyone for their input. What I have decided to do is to write a utility (not yet done) that will allow me to reset the INI file x y references to -1 and then allow the user to set and save the position of each window based on their own desktop. These are some code snippet for saving the x y position. In this case it supports the same menu but in two different configurations - horizontal and vertical where $mCPos determines which menu is active.

Case $msg = $GUI_EVENT_PRIMARYDOWN
    $mp = MouseGetPos()

    $wp = WinGetPos($pTitle)

    While _IsPressed("01")

        $newp = MouseGetPos()

        WinMove($pTitle, '', $wp[0] + $newp[0] - $mp[0], $wp[1] + $newp[1] - $mp[1])

    WEnd

    calculateWindowPos()

    $wPos = -1

    $hPos = -1

    If $mCPos = 1 Then

        If $MenuCPos1 <> $xPos Or $MenuCPos2 <> $yPos Then

            GUIDelete()

            $section = "section25"

            $value1 = $xPos

            $value2 = $yPos

            $posFlag = 1

            SaveChanges()

            ExitLoop

        EndIf

    Else

        If $MenuCPos3 <> $xPos Or $MenuCPos4 <> $yPos Then

            GUIDelete()

            $section = "section26"

            $value1 = $xPos

            $value2 = $yPos

            $posFlag = 1

            SaveChanges()

            ExitLoop

        EndIf

    EndIf


    ;Calculate the position of the active Window
    Func calculateWindowPos()

        $wp = WinGetPos($pTitle)

        $xPos = $wp[0]

        $yPos = $wp[1]

        $wPos = $wp[2]

        $hPos = $wp[3]

    EndFunc   ;==>calculateWindowPos

    ;Save the Changes
    Func SaveChanges()

        ;Save Changes

        If $value1 >= 0 Then

            IniWrite(@ScriptDir & "\image.ini", $section, "value1", $value1)

        EndIf

        If $value2 >= 0 Then

            IniWrite(@ScriptDir & "\image.ini", $section, "value2", $value2)

        EndIf

        ;Read MenuA Position

        $MenuAPos1 = IniRead(@ScriptDir & "\image.ini", "section23", "value1", "-1")

        $MenuAPos2 = IniRead(@ScriptDir & "\image.ini", "section23", "value2", "-1")

        ;Read MenuB Position

        $MenuBPos1 = IniRead(@ScriptDir & "\image.ini", "section24", "value1", "-1")

        $MenuBPos2 = IniRead(@ScriptDir & "\image.ini", "section24", "value2", "-1")

        ;Read MenuC Horizontal Position

        $MenuCPos1 = IniRead(@ScriptDir & "\image.ini", "section25", "value1", "-1")

        $MenuCPos2 = IniRead(@ScriptDir & "\image.ini", "section25", "value2", "-1")

        ;Read MenuC Vertical Position

        $MenuCPos3 = IniRead(@ScriptDir & "\image.ini", "section26", "value1", "-1")

        $MenuCPos4 = IniRead(@ScriptDir & "\image.ini", "section26", "value2", "-1")

        ;Read MenuC Position Switch

        $mCPos = IniRead(@ScriptDir & "\image.ini", "section27", "value1", "1")

        $mCStart = IniRead(@ScriptDir & "\image.ini", "section27", "value2", "1")

        ;Read MenuD Position

        $MenuDPos1 = IniRead(@ScriptDir & "\image.ini", "section28", "value1", "-1")

        $MenuDPos2 = IniRead(@ScriptDir & "\image.ini", "section28", "value2", "-1")

        ;Read MenuE Position for MenuA

        $MenuEPos1 = IniRead(@ScriptDir & "\image.ini", "section29", "value1", "-1")

        $MenuEPos2 = IniRead(@ScriptDir & "\image.ini", "section29", "value2", "-1")

        ;Read MenuE Position Position for MenuB

        $MenuEPos3 = IniRead(@ScriptDir & "\image.ini", "section30", "value1", "-1")

        $MenuEPos4 = IniRead(@ScriptDir & "\image.ini", "section30", "value2", "-1")

        ;Read Google Earth Image Position Portrait

        Global $geImagePos1 = IniRead(@ScriptDir & "\image.ini", "section31", "value1", "-1")

        Global $geImagePos2 = IniRead(@ScriptDir & "\image.ini", "section31", "value2", "-1")

        ;Read Google Earth Image Position Landscape

        Global $geImagePos3 = IniRead(@ScriptDir & "\image.ini", "section32", "value1", "-1")

        Global $geImagePos4 = IniRead(@ScriptDir & "\image.ini", "section32", "value2", "-1")

        ;Display Message

        If $posFlag = 1 Then

            $message = " Menu Position Saved"

            DisplayMessage()

        EndIf

        $posFlag = ""

    EndFunc   ;==>SaveChanges

 

Ant..

Edited by Melba23
Fixed tags
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...