I'm not really sure of the purpose of your script but I know that the use case likely will require you to make some changes to better suit your particular needs. So here are a few examples that use the same basic concept of causing an event in a window to get it to run a routine.
This shows how you can load something into your clipboard and then trigger the gui routine to update the picture with the contents of the clipboard.
Code: Select all
;*****************************************************************************************************
;*****************************************************************************************************
;*****************************************************************************************************
;Script 1
#SingleInstance, Force
Gui, New, +AlwaysOnTop
Gui, Add, Picture, xm ym w200 h200 hwndPicHwnd, ImagePath.png
Gui, Show,, My Image gui title
Gui, Add, Checkbox, x-100 y0 w10 h10 gUpdatePicture hwndCheckboxHwnd Disabled,
return
GuiClose:
*ESC:: ExitApp
UpdatePicture:
GuiControl, , % PicHwnd , % Clipboard
return
;*****************************************************************************************************
;*****************************************************************************************************
;*****************************************************************************************************
;Script 2
#SingleInstance, Force
return
*ESC::ExitApp
;&&&&&&&&&&&&&&&&&&&&&
F1::
Backup := ClipboardAll
sleep, 30
Clipboard := "Image\Path.png"
sleep, 30
Control, % ( Tog := !Tog ) ? ( "Check" ) : ( "UnCheck" ) , , Button1 , My Image gui title
Sleep, 100
Clipboard := Backup
return
;&&&&&&&&&&&&&&&&&&&&&
;*****************************************************************************************************
;*****************************************************************************************************
;*****************************************************************************************************
This second example takes the original code and has the window resized based on the new images size. [ Ratio can also be used ]
Code: Select all
;*****************************************************************************************************
;*****************************************************************************************************
;*****************************************************************************************************
;Script 1
#SingleInstance, Force
Gui, New, +AlwaysOnTop
Gui, Add, Picture, xm ym w200 h200 hwndPicHwnd, Image.png
Gui, Show,, My Image gui title
ImageList := ""
Loop, Path\*.png
ImageList .= A_LoopFileFullPath "|"
Gui, Add, ListBox, x-100 y0 w10 h10 gUpdatePicture hwndListHwnd Disabled, % ImageList
return
GuiClose:
*ESC:: ExitApp
UpdatePicture:
;Get the currently selected item in the listbox
GuiControlGet, out , , % ListHwnd
;add a picture control to a non-existing gui and set it with the new image so that the size of the image can be obtained.
Gui, FakeGui:Add, Picture, +hwndFakePicHwnd, % out
;get the size of the control ( "pos" becomes: posX, posY, posW, posH )
GuiControlGet, pos , FakeGui:pos , % FakePicHwnd
;Destroy the fake gui without ever having shown it. Free memory.
Gui, FakeGui:Destroy
;Change the width and height of the original picture control ( or use the new ratio between width/height and a fixed max/min size )
GuiControl, MoveDraw, % PicHwnd , % " w" posW " h" posH
;Update the picture control with the new image
GuiControl, , % PicHwnd , % out
;resize the window to adjust for the new picture size ( adding a position i.e. x/y is an option )
Gui, Show, AutoSize
return
;*****************************************************************************************************
;*****************************************************************************************************
;*****************************************************************************************************
;Script 2
#SingleInstance, Force
Index := 1
return
*ESC::ExitApp
;&&&&&&&&&&&&&&&&&&&&&
F1::
Control, Choose , % Index++ , ListBox1 , My Image gui title
return
;&&&&&&&&&&&&&&&&&&&&&
;*****************************************************************************************************
;*****************************************************************************************************
;*****************************************************************************************************
Related to resizing the picture control is how to move additional controls around based on the new image size.
So here is where you can find an example of storing the data for your controls in a structure that allows for easier manipulation of their values and positions.
Reposition Gui Controls
.
![Image](https://www.autohotkey.com/boards/download/file.php?id=22597)
.
Here is a more complex example that uses a relative relationship between different controls.
So for example, the text control is related to the 0/0 position of the window and the button is positioned relative to the text controls position
and the checkbox is relative to the button, and on and on.
Once any value is changed, the controls can be looped and their positions updated based on the relationships.
Relative Positioning
.
![Image](https://www.autohotkey.com/boards/download/file.php?id=22598)
.
This is an example of what a typical relationship looks like.
Code: Select all
Button.X := Text.X + Text.W + Margin
and that is written out as a string:
Code: Select all
;The "X", "W", etc. are based off the control that is partnered with this one.
... , X: "X + W + 10" , ...
The expressions that can currently be used are limited but the use of new expressions can be added in by following the same concept as the others use.
That's likely way more than you will ever need to know but someone else might find it useful.