MightyWeird Posted April 1, 2021 Posted April 1, 2021 (edited) 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 April 1, 2021 by MightyWeird
Nine Posted April 1, 2021 Posted April 1, 2021 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 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Belini Posted April 1, 2021 Posted April 1, 2021 @Nine and the sources how do you stay in the same proportion? My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ
Nine Posted April 1, 2021 Posted April 1, 2021 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
MightyWeird Posted April 1, 2021 Author Posted April 1, 2021 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! expandcollapse popup#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)
pixelsearch Posted April 1, 2021 Posted April 1, 2021 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 expandcollapse popup; 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 "I think you are searching a bug where there is no bug... don't listen to bad advice."
Nine Posted April 1, 2021 Posted April 1, 2021 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]) ..... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now