Jump to content

Recommended Posts

Hi,

 

I am trying to make my script running on different resolutions.

Currently I hardcode every button location for every resolution (see code below) (works fine btw)

Is this the way?, is there a better way do do this?

My gui is full screen, user is not able to resize it.

 

Switch @DesktopWidth
    Case "1920"
        $picheight = 300
        $Picwidth = 1820
        $Picstartleft = @DesktopWidth / 2 - $Picwidth / 2
      Case "1024"  
      etc etc

I would like to scale everything based on resolution. This means the location  and size of the buttons , labels etc.

 

Is there a golden path on how to achive this?, or should i just leave this as it is? (working fine this way, but a lot of work to check every resolution)

(yes I searched the forums and tried tens of examples, but I could not find something i can work with)

Thank you

Edited by MightyWeird
Link to post
Share on other sites

Yes it is kind of easy to do.  You need to make a GUI like you want with right positioning of controls for one specific resolution, then calculate the new position if the resolution change. 

Ex : lets say you have a pic positioned at 100, 100 with 200 height and 500 width for a 1024 resolution.  And now you want to get coordinates for you new current resolution, you could use something like this :

#include <Constants.au3>
#include <Array.au3>

Global Const $STD_WIDTH = 1024
Global Const $STD_HEIGHT = 768

Local $aCoord = GetCoordinates (100, 100, 500, 200)
; $idPic = GUICtrlCreatePic("", $aCoord[0], $aCoord[1], $aCoord[2], $aCoord[3])
_ArrayDisplay($aCoord)

Func GetCoordinates($iLeft, $iTop, $iWidth, $iHeight)
  Local $aCoord [] = [ _
    Int(@DesktopWidth/$STD_WIDTH*$iLeft), _
    Int(@DesktopHeight/$STD_HEIGHT*$iTop), _
    Int(@DesktopWidth/$STD_WIDTH*$iWidth), _
    Int(@DesktopHeight/$STD_HEIGHT*$iHeight) _
    ]
  Return $aCoord
EndFunc

 

Link to post
Share on other sites

You mean the images ?  You would need to resize them accordingly with _GDIPlus_ImageResize.  But I thought OP was only interested in how to calculate new coords. ;)

Link to post
Share on other sites

 

Took some time to figure it out. But what if i have multiple pictures / buttons etc. I dont want to create a function for every button!?

Do I need to put the buttons in a array or something?

 

Thanks!

 

 

 

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <Array.au3>



Global Const $STD_WIDTH = 1024
Global Const $STD_HEIGHT = 768

Example()

Func Example()
    ; Create a GUI with various controls.
;~     Local $hGUI = GUICreate("Example",1024,768)
    Local $hGUI = GUICreate("Example",@DesktopWidth,@DesktopHeight)


Local $btn1Coord = GetCoordinates (310, 370, 85, 25)
$btn1 = GUICtrlCreateButton("OK", $btn1Coord[0], $btn1Coord[1], $btn1Coord[2], $btn1Coord[3])


Local $aCoord = GetCoordinates (0, 100, 1024,300)
$idPic = GUICtrlCreatePic(@ScriptDir & "\Resources\test.jpg", $aCoord[0], $aCoord[1], $aCoord[2], $aCoord[3])

_ArrayDisplay($aCoord)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 Local $idButton_Notepad = GUICtrlCreateButton("Run Notepad", 120, 170, 85, 25)

 

Link to post
Share on other sites

Just tried this with the script "SampleControls.au3" found in Autoit
Added some lines indicated with "<=============" and it seems to work : as soon as the GUI size changes (to match screen resolution) then all controls are resized accordingly.
Clicking on Close button once will expand the Gui, for example to the new display resolution etc...

Try to run the script directly from where it's located in AutoIt (subfolder example => gui) so you'll have access to the images to be displayed in the script, which will have a larger size when the GUI expands

; AutoIt GUI Example
; Created: 17/01/2005 - CyberSlug
; Modifed: 05/12/2011 - guinness
; Modifed: 09/06/2014 - mLipok

#Region INCLUDE
#include <AVIConstants.au3>
#include <GuiConstantsEx.au3>
#include <TreeViewConstants.au3>
#EndRegion INCLUDE

Opt("GUIResizeMode", 1) ;0=no resizing, <1024 special resizing <=================

#Region GUI
$hGUI = GUICreate("Sample GUI", 400, 400) ;  <=================
GUISetIcon(@SystemDir & "\mspaint.exe", 0)
#EndRegion GUI

#Region MENU
Local $idMenu1 = GUICtrlCreateMenu("Menu &One")
Local $idMenu2 = GUICtrlCreateMenu("Menu &Two")
GUICtrlCreateMenu("Menu Th&ree")
GUICtrlCreateMenu("Menu &Four")
GUICtrlCreateMenuItem('SubMenu One &A', $idMenu1)
GUICtrlCreateMenuItem('SubMenu One &B', $idMenu1)
#EndRegion MENU

#Region CONTEXT MENU
Local $idContextMenu = GUICtrlCreateContextMenu()
GUICtrlCreateMenuItem("Context Menu", $idContextMenu)
GUICtrlCreateMenuItem("", $idContextMenu) ; Separator
GUICtrlCreateMenuItem("&Properties", $idContextMenu)
#EndRegion CONTEXT MENU

#Region PIC
GUICtrlCreatePic("logo4.gif", 0, 0, 169, 68)
GUICtrlSetTip(-1, '#Region PIC')
GUICtrlCreateLabel("Sample Pic", 75, 1, 53, 15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xFFFFFF)
#EndRegion PIC

#Region AVI
GUICtrlCreateAvi("SampleAVI.avi", 0, 180, 10, 32, 32, $ACS_AUTOPLAY)
GUICtrlSetTip(-1, '#Region AVI') ; TODO
GUICtrlCreateLabel("Sample avi", 175, 50)
GUICtrlSetTip(-1, '#Region AVI - Label')
#EndRegion AVI

#Region TAB
GUICtrlCreateTab(240, 0, 150, 70)
GUICtrlCreateTabItem("One")
GUICtrlSetTip(-1, '#Region TAB1')
GUICtrlCreateLabel("Sample Tab with TabItems", 250, 40)
GUICtrlCreateTabItem("Two")
GUICtrlSetTip(-1, '#Region TAB2')
GUICtrlCreateTabItem("Three")
GUICtrlSetTip(-1, '#Region TAB3')
GUICtrlCreateTabItem("")
#EndRegion TAB

#Region COMBO
GUICtrlCreateCombo("Sample Combo", 250, 80, 120, 100)
GUICtrlSetTip(-1, '#Region COMBO')
#EndRegion COMBO

#Region PROGRESS
GUICtrlCreateProgress(60, 80, 150, 20)
GUICtrlSetTip(-1, '#Region PROGRES')
GUICtrlSetData(-1, 60)
GUICtrlCreateLabel("Progress:", 5, 82)
GUICtrlSetTip(-1, '#Region PROGRES - Label')
#EndRegion PROGRESS

#Region EDIT
GUICtrlCreateEdit(@CRLF & "  Sample Edit Control", 10, 110, 150, 70)
GUICtrlSetTip(-1, '#Region EDIT')
#EndRegion EDIT

#Region LIST
GUICtrlCreateList("", 5, 190, 100, 90)
GUICtrlSetTip(-1, '#Region LIST')
GUICtrlSetData(-1, "A.Sample|B.List|C.Control|D.Here", "B.List")
#EndRegion LIST

#Region ICON
GUICtrlCreateIcon("explorer.exe", 0, 175, 120)
GUICtrlSetTip(-1, '#Region ICON')
GUICtrlCreateLabel("Icon", 180, 160, 50, 20)
GUICtrlSetTip(-1, '#Region ICON - Label')
#EndRegion ICON

#Region LIST VIEW
Local $idListView = GUICtrlCreateListView("Sample|ListView|", 110, 190, 110, 80)
GUICtrlSetTip(-1, '#Region LIST VIEW')
GUICtrlCreateListViewItem("A|One", $idListView)
GUICtrlCreateListViewItem("B|Two", $idListView)
GUICtrlCreateListViewItem("C|Three", $idListView)
#EndRegion LIST VIEW

#Region GROUP WITH RADIO BUTTONS
GUICtrlCreateGroup("Sample Group", 230, 120)
GUICtrlCreateRadio("Radio One", 250, 140, 80)
GUICtrlSetTip(-1, '#Region GROUP WITH RADIO BUTTONS- RADIO1')
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateRadio("Radio Two", 250, 165, 80)
GUICtrlSetTip(-1, '#Region GROUP WITH RADIO BUTTONS- RADIO2')
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
#EndRegion GROUP WITH RADIO BUTTONS

#Region UPDOWN
GUICtrlCreateLabel("UpDown", 350, 115)
GUICtrlSetTip(-1, '#Region UPDOWN - Label')
GUICtrlCreateInput("42", 350, 130, 40, 20)
GUICtrlSetTip(-1, '#Region UPDOWN - Input')
GUICtrlCreateUpdown(-1)
GUICtrlSetTip(-1, '#Region UPDOWN - Updown')
#EndRegion UPDOWN

#Region LABEL
GUICtrlCreateLabel("Green" & @CRLF & "Label", 350, 165, 40, 40)
GUICtrlSetTip(-1, '#Region LABEL')
GUICtrlSetBkColor(-1, 0x00FF00)
#EndRegion LABEL

#Region SLIDER
GUICtrlCreateLabel("Slider:", 235, 215)
GUICtrlSetTip(-1, '#Region SLIDER - Label')
GUICtrlCreateSlider(270, 210, 120, 30)
GUICtrlSetTip(-1, '#Region SLIDER')
GUICtrlSetData(-1, 30)
#EndRegion SLIDER

#Region INPUT
GUICtrlCreateInput("Sample Input Box", 235, 255, 130, 20)
GUICtrlSetTip(-1, '#Region INPUT')
#EndRegion INPUT

#Region DATE
GUICtrlCreateDate("", 5, 280, 200, 20)
GUICtrlSetTip(-1, '#Region DATE')
GUICtrlCreateLabel("(Date control expands into a calendar)", 10, 305, 200, 20)
GUICtrlSetTip(-1, '#Region DATE - Label')
#EndRegion DATE

#Region BUTTON
GUICtrlCreateButton("Sample Button", 10, 330, 100, 30)
GUICtrlSetTip(-1, '#Region BUTTON')
#EndRegion BUTTON

#Region CHECKBOX
GUICtrlCreateCheckbox("Checkbox", 130, 335, 80, 20)
GUICtrlSetTip(-1, '#Region CHECKBOX')
GUICtrlSetState(-1, $GUI_CHECKED)
#EndRegion CHECKBOX

#Region TREEVIEW ONE
Local $idTreeView_1 = GUICtrlCreateTreeView(210, 290, 80, 80)
GUICtrlSetTip(-1, '#Region TREEVIEW ONE')
Local $idTreeItem = GUICtrlCreateTreeViewItem("TreeView", $idTreeView_1)
GUICtrlCreateTreeViewItem("Item1", $idTreeItem)
GUICtrlCreateTreeViewItem("Item2", $idTreeItem)
GUICtrlCreateTreeViewItem("Foo", -1)
GUICtrlSetState($idTreeItem, $GUI_EXPAND)
#EndRegion TREEVIEW ONE

#Region TREEVIEW TWO
Local $idTreeView_2 = GUICtrlCreateTreeView(295, 290, 103, 80, $TVS_CHECKBOXES)
GUICtrlSetTip(-1, '#Region TREEVIEW TWO')
GUICtrlCreateTreeViewItem("TreeView", $idTreeView_2)
GUICtrlCreateTreeViewItem("With", $idTreeView_2)
GUICtrlCreateTreeViewItem("$TVS_CHECKBOXES", $idTreeView_2)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateTreeViewItem("Style", $idTreeView_2)
#EndRegion TREEVIEW TWO

$iInc = 0  ; <=================

#Region GUI MESSAGE LOOP
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            $iInc += 1  ; <================= etc...
            If $iInc = 2 Then ExitLoop
            WinMove($hGUI, "", 0, 0, 600, 600)
    EndSwitch
WEnd

GUIDelete()
#EndRegion GUI MESSAGE LOOP

 

Link to post
Share on other sites
8 minutes ago, MightyWeird said:

Do I need to put the buttons in a array or something?

You could do that, it is possible.  But unless I can calculate the position of the multiples buttons I wouldn't do it thru an array.  If the buttons are scattered randomly within the  GUI, I would prefer to create the buttons separately.  BTW do not create a new array for each control, use the same :

Local $aCoord

.....

$aCoord = GetCoordinates (310, 370, 85, 25)
$btn1 = GUICtrlCreateButton("OK", $aCoord[0], $aCoord[1], $aCoord[2], $aCoord[3])

$aCoord = GetCoordinates (0, 100, 1024,300)
$idPic = GUICtrlCreatePic(@ScriptDir & "\Resources\test.jpg", $aCoord[0], $aCoord[1], $aCoord[2], $aCoord[3])

.....

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...