help with GUI definition

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

help with GUI definition

14 Feb 2014, 08:52

i'm working on a brute force type of GUI as a frontend to an image convert command line program. adding options and playing around some to get my feet wet on GUI defining. i'm having problem in one are on this code. when i added in the feature to get the image size, the routine that saves the location of the GUI broke. i've been beating my head against it and i'm sure i'm missing something stupid, but can someone take a look and tell me what i'm doing wrong?

thanks

;;
;;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
#SingleInstance,Force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

IniRead, formats, Image_Convert.ini, file formats
IniRead, gui_position, Image_Convert.ini, window position, gui_position, Center
IniRead, extension, Image_Convert.ini, Extensions

; full_inputfile = %1%
; Loop, %1%, 2
; full_inputfile := A_LoopFileLongPath
; inputfile :=full_inputfile

FileSelectFile, full_inputfile,, *.jpg;*.bmp
SplitPath, full_inputfile, inputfile
gosub, ImgSize

Gui, +Hwndgui_id
WinGetActiveTitle, Title
; msgbox, title is %Title%
Gui, Font, s10
Gui, Add, Text, x10 y5, %inputfile%

Gui, Font, s8
Gui, Add, Text, x10 y27 w90 h20, Output Format
Gui, Add, ComboBox, xp+70 y24 w45 h120 vExtension, %Extension%
Gui, Add, Checkbox, xp+85 y20 h30 vOverwrite, Overwrite File?
Gui, Add, Checkbox, xp+0 y42 h30 vSamedate, Keep Date/Time?
Gui, Add, Text, x10 y42 h20, Resize
Gui, Add, Text, x31 y55 h20, [px]
Gui, Add, Text, x82 y55 h20, [percent]
Gui, Add, Edit, x10 y70 w27 h15 vXSize, %wide%
Gui, Add, Edit, x45 y70 w27 h15 vYSize, %High%
Gui, Add, Edit, x90 y70 w27 h15 vPercent, 100
Gui, Add, Text, x10 y95 w100 h20, Standard Ratios
Gui, Add, Text, x142 y72, Rotation Angle (CW)
Gui, Add, Slider, x125 y88 w130 Tooltip vAngle Range0-359, 0
Gui, Add, Text, x160 y120, Crop Pixels
Gui, Add, Button, x10 y180 w45 h14 greload, Reload
Gui, Add, Button, x250 y5 w10 h10 gEditAHK,
GuiControlGet, Radio
Gui, Add, Radio, x10 y110 w120 h20 vStd1, VGA (640 x 480)
Gui, Add, Radio, x10 y126 w120 h20 vStd2, SVGA (800 x 600)
Gui, Add, Radio, x10 y142 w120 h20 vStd3, XGA (1024 x 768)
Gui, Add, Radio, x10 y158 w120 h20 vStd4, SXGA- (1280 x 960)
Gui, Add, Button, x155 y150 w55 h25 vAdd gBtnDoIt, Run
Gui, Add, Button, x160 y175 w45 h20 gBtnCancel, Cancel

Gui, Show, %gui_position% ; w270 h200

Return

GuiClose:
Gosub Saveloc
ExitApp

BtnDoIt:
Gui, Submit
GoSub Saveloc
run nconvert -out %Extension% -resize %XSize% %YSize% -rotate %Angle% %inputfile%
return
ExitApp

BtnCancel:
Gosub Saveloc
ExitApp

Saveloc:
WinGetPos, gui_x, gui_y,,, %Title%
msgbox, x is %gui_x% and y is %gui_y%
IniWrite, x%gui_x% y%gui_y%, Image_Convert.ini, window position, gui_position
return

ImgSize:
WinSetTitle, Size
gui, 2:add,picture,hwndmypic,%inputfile%
controlgetpos,,,wide,high,,ahk_id %mypic%
gui, 2:destroy
return

Reload:
reload
Return

EditAHK:
run notepad.exe "Image_Convert.ahk"
Return

;;
;;
Guest

Re: help with GUI definition

14 Feb 2014, 09:02

As far as I know you can't use one variable for x and y at the same time, you need to save the x and y position as individual variables, read them back as individual variables and use them as individual variables.

So not:

Gui, Show, %gui_position% ;

but

IniWrite, %gui_x%, Image_Convert.ini, window position, gui_X
IniWrite, %gui_y%, Image_Convert.ini, window position, gui_Y
; and the IniRead the same

Gui, Show, x%gui_x% y%gui_y%
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: help with GUI definition

14 Feb 2014, 10:20

this is the same routine i use on other scripts so i know it works, but i went ahead and modified it to try your suggestion. no luck though. it looks like for some reason, the gui coordinates are not being retrieved.
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: help with GUI definition

14 Feb 2014, 10:34

think i got it:

old code:
ImgSize:
WinSetTitle, Size
gui, 2:add,picture,hwndmypic,%inputfile%
controlgetpos,,,wide,high,,ahk_id %mypic%
gui, 2:destroy
return

new code:
ImgSize:
WinSetTitle, Size
gui, 2:add,picture,hwndSize,%inputfile%
controlgetpos,,,wide,high,,ahk_id %Size%
gui, 2:destroy
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: OrangeCat and 288 guests