Jump to content

Evaluate conditions


Olson
 Share

Recommended Posts

So I'm very new to AutoIt so I'm sure this will be a silly question.

In my program that I'd like to automate, when I press ALT-I, this window pops up:

psp_resize.jpg

What I'd like to do is change whichever is smaller, Width or Height, to 4000.  And then I want to change Resolution to 100.

How would I go about doing something like this?

Link to comment
Share on other sites

  • Moderators

Hi, Olsen, welcome to the forum. I would suggest beginning with the AutoIt Window Info Tool (Au3Info or Au3Info_X64, in the same directory where you installed AutoIt). This will tell you more about the window and its controls. Hover over the different areas, such as where it is showing the Width and Height, and see if they return Control information on the Control tab. If so, you can then grab that information using the Control commands in the help file (ControlGetText, ControlSetText, etc.).

See what you can work out on your own. If you get stuck, feel free to post what you have (even if it isn't working quite right) and we'll do our best to assist.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I was unable to use Help.  I'm using Scite as an editor.

So far I have:

Send("!I")

send("z")

And then using the cool "Info" program, I learned that:

The window title is "Resize"

ClassnameNN for Width is AfxWnd421

ClassnameNN for Height is AfxWnd421

So then to find out if I'm on the right track, I tried:

HotKeySet("+{F8}","size")

   Func size()
      Send("!I")
      send("z")
      x=ControlGetText("AfxWnd421")
      MsgBox(x)
   EndFunc

And then I found out that I'm not providing enough info for ControlGetText, and not sure how to proceed.

Link to comment
Share on other sites

You will need the correct control information. Check what is shown in the "Advanced Mode" section of the Window Info Tool.


[autoit]]HotKeySet("+{F8}","size")

Func size()
    Send("!I")
    $width = ControlGetText("Resize", "", "height");reads the current height, change height with the correct control
    $height = ControlGetText("Resize", "", "width");reads the current width, change width with the correct control
    $resolution = ControlGetText("Resize", "", "resolution");reads the current resolution, change resolution with the correct control
    If $width > $height Then; compare the 2
        ControlSetText("Resize", "", "height", "4000");set the height control, change height with the correct control
    Else
        ControlSetText("Resize", "", "width", "4000");set the width control, change width with the correct control
    EndIf
    If $resolution <> "100.000" Then ControlSetText("Resize", "", "resolution", "100");set the resolution control, change resolution with the correct control
    ;add other actions "to click ok" etc
EndFunc[/autoit]

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

if it works, keep in mind that nothing will happen if both dimensions are the same the way it is now, this can easily be changed.

also, from what i see in the screenshot, the dimensions are locked due to the "aspect ratio" being checked i guess, make sure you're able to change the values manually before you try it

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

In your code it looked like you had an extra bracket in "[autoit]]" So I have it like this:

[autoit]
HotKeySet("+{F8}","size")

Func size()
    Send("!I")
    $width = ControlGetText("Resize", "[CLASS:AfxWnd42; INSTANCE:1]", "height");reads the current height, change height with the correct control
    $height = ControlGetText("Resize", "[CLASS:AfxWnd42; INSTANCE:2]", "width");reads the current width, change width with the correct control
    $resolution = ControlGetText("Resize", "", "resolution");reads the current resolution, change resolution with the correct control
    If $width > $height Then; compare the 2
        ControlSetText("Resize", "[CLASS:AfxWnd42; INSTANCE:1]", "height", "4000");set the height control, change height with the correct control
    Else
        ControlSetText("Resize", "[CLASS:AfxWnd42; INSTANCE:2]", "width", "4000");set the width control, change width with the correct control
    EndIf
    If $resolution <> "100.000" Then ControlSetText("Resize", "[CLASS:AfxWnd42; INSTANCE:5]", "resolution", "100");set the resolution control, change resolution with the correct control
    ;add other actions "to click ok" etc
 EndFunc
 [/autoit]

And I'm getting the following error:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Photo Resell\size.au3"
C:\Photo Resell\size.au3 (1) : ==> Missing separator character after keyword.: 
[autoit] 
[autoit^ ERROR
>Exit code: 1    Time: 0.235

I just took out the autoit tags and it compiles but when I try to run the exe it never shows up on my taskbar like all the other scripts.

Link to comment
Share on other sites

Still won't run.  Current code is:

;;[autoit]
HotKeySet("{F9}","size")

Func size()
    Send("!I")
    Send("z")
    $width = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]");reads the current height, change height with the correct control
    $height = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]");reads the current width, change width with the correct control
    $resolution = ControlGetText("Resize", "", "resolution");reads the current resolution, change resolution with the correct control
    If $width > $height Then; compare the 2
        ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]", "4000");set the height control, change height with the correct control
    Else
        ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]", "4000");set the width control, change width with the correct control
    EndIf
    If $resolution <> "100.000" Then ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]", "100");set the resolution control, change resolution with the correct control
    ;add other actions "to click ok" etc
 EndFunc
 ;;[/autoit]
Link to comment
Share on other sites

$resolution = ControlGetText("Resize", "", "resolution");reads the current resolution, change resolution with the correct control
------------------------------------------------^

You probably need to get the class and instance instead of "resolution". Just like you did with the other two.

Edited by LongBowNZ
Link to comment
Share on other sites

try adding the while loop at the end, check my previous post! also, in the ControlSetText commands the controls are in the wrong order, let me explain:

you want to change whichever is smaller so if width is bigger than height you want to change height so it would be [CLASS:AfxWnd42; INSTANCE:2] and the other one should be instance 1.

or you can change > to <

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

Getting so close.  Height and Resolution are correct but Width is still null.

Current code:

;;[autoit]
HotKeySet("{F9}","size")

Func size()
    Send("!I")
    Send("z")
    $width = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]");reads the current height, change height with the correct control
    msgbox("tvt","Hello",$width)
    $height = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]");reads the current width, change width with the correct control
    msgbox("tvt","Hello",$height)
    $resolution = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]");reads the current resolution, change resolution with the correct control
    msgbox("tvt","Hello",$resolution)
    If $width > $height Then; compare the 2
        ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]", "4000");set the height control, change height with the correct control
    Else
        ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]", "4000");set the width control, change width with the correct control
    EndIf
    If $resolution <> "100.000" Then ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]", "100");set the resolution control, change resolution with the correct control
    ;add other actions "to click ok" etc
 EndFunc
 ;;[/autoit]
 
 While 1
Sleep(100)
WEnd

Thank you so much for holding my hand through this.

Link to comment
Share on other sites

Do you have height and width backwards? The comments after the 1st $width line say "reads the current height", and the comments after $height say width.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

;;[autoit]
HotKeySet("{F9}","size")

Func size()
    Send("!I")
    Send("z")
    $width = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]");reads the current width, change width with the correct control
    msgbox("tvt","Hello",$width)
    $height = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]");reads the current height, change height with the correct control
    msgbox("tvt","Hello",$height)
    $resolution = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]");reads the current resolution, change resolution with the correct control
    msgbox("tvt","Hello",$resolution)
    If $width < $height Then; compare the 2
        ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]", "4000");set the width control, change width with the correct control
    Else
        ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]", "4000");set the height control, change height with the correct control
    EndIf
    If $resolution <> "100.000" Then ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]", "100");set the resolution control, change resolution with the correct control
    ;add other actions "to click ok" etc
 EndFunc
 ;;[/autoit]
 
 While 1
Sleep(100)
WEnd

I changed the comparison from > to < and made the comments match the code. See if this works.

EDIT: Do you need to send "z" after "alt+i", if not, you should get rid of Send("z")

Edited by LongBowNZ
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...