Olson Posted February 5, 2014 Author Posted February 5, 2014 Changed to your code and the first msgbox still returns a NULL.
Olson Posted February 5, 2014 Author Posted February 5, 2014 So this makes no sense. The previous code gave Width=NULL, Height=Some Number, Resolution=Some Number. So I decided to check resolution first by: ;;[autoit] HotKeySet("{F7}","size") Func size() Send("!I") Send("z") $resolution = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]");reads the current resolution, change resolution with the correct control msgbox("tvt","Hello",$resolution) If $resolution <> "100.000" Then ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]", "100");set the resolution control, change resolution with the correct control $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 width, change width with the correct control msgbox("tvt","Hello",$height) 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 ;add other actions "to click ok" etc EndFunc ;;[/autoit] While 1 Sleep(100) WEnd And now Height and Width are correct and Resolution is NULL. I can't get my head around the first lookup always being NULL.
AdmiralAlkex Posted February 5, 2014 Posted February 5, 2014 Is the Send() opening the window? Then the first ControlGetText() always fail because you are not waiting long enough for the window to be created before trying to read from it. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
LongBowNZ Posted February 5, 2014 Posted February 5, 2014 HotKeySet("{F9}", "size") While 1 Sleep(100) WEnd Func size() Send("!I") Send("z") WinWaitActive("Resize") $width = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]");reads the current width, change width with the correct control MsgBox(0, "Hello", "Width: " & $width) $height = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]");reads the current height, change height with the correct control MsgBox(0, "Hello", "Height: " & $height) $resolution = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]");reads the current resolution, change resolution with the correct control MsgBox(0, "Hello", "Resolution: " & $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 Try this. Also I don't know if you saw my edit before, to delete the "Send("z")" if you don't need to send "z".
Moderators JLogan3o13 Posted February 5, 2014 Moderators Posted February 5, 2014 @Olson, it finally dawned on me what application you're trying to automate (always a good idea to state this up front, helps us help you). This works for me in the latest version of Paint Shop Pro, though from the class names you have listed it looks like you're running an older version. Nevertheless, you should be able to change the CLASS:AfxWnd90u to CLASS:AfxWnd42 and it should work. WinActivate("Corel PaintShop Pro", "") Send("+s") ;Open the resize menu, in this version at least $Width = ControlGetText("Resize", "", "[CLASS:AfxWnd90u; INSTANCE:1]") $Height = ControlGetText("Resize", "", "[CLASS:AfxWnd90u; INSTANCE:2]") $Resolution = ControlGetText("Resize", "", "[CLASS:AfxWnd90u; INSTANCE:3]") $pixelWidth = ControlGetText("Resize", "", "[CLASS:AfxWnd90u; INSTANCE:4]") $pixelHeight = ControlGetText("Resize", "", "[CLASS:AfxWnd90u; INSTANCE:5]") If $Height < $Width Then ControlSetText("Resize", "", "[CLASS:AfxWnd90u; INSTANCE:2]", "4000.0") ElseIf $Width < $Height Then ControlSetText("Resize", "", "[CLASS:AfxWnd90u; INSTANCE:1]", "4000.0") EndIf ControlSetText("Resize", "", "[CLASS:AfxWnd90u; INSTANCE:3]", "100") ControlClick("Resize", "", "[CLASS:Button; INSTANCE:14]") "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!
Olson Posted February 6, 2014 Author Posted February 6, 2014 So the code is working, but not all the time. If a step takes too long it will skip the next instructions. Here is how it stands now: expandcollapse popupHotKeySet("{F7}", "size") While 1 Sleep(100) WEnd Func size() Send("!I") Send("E") Send("6") sleep(3000) ;WinWaitActive( ;WinWaitActive("Resize") Send("+R") sleep(3000) ;WinWaitActive("Resize") ;WinWaitActive("Resize") Send("+S") sleep(3000) ;WinWaitActive("Resize") $resolution = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]");reads the current resolution, change resolution with the correct control If $resolution <> "100.000" Then ControlSetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:5]", "100");set the resolution control, change resolution with the correct control $width = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:1]");reads the current width, change width with the correct control ;MsgBox(0, "Hello", "Width: " & $width) $height = ControlGetText("Resize", "", "[CLASS:AfxWnd42; INSTANCE:2]");reads the current height, change height with the correct control ;MsgBox(0, "Hello", "Height: " & $height) ;MsgBox(0, "Hello", "Resolution: " & $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 ;add other actions "to click ok" etc ControlClick("Resize", "", "[CLASS:Button; INSTANCE:14]") sleep(3000) Send("!A") Send("s") Send("h") sleep(3000) Send("!A") Send("s") Send("h") ;send("^c") ;sleep(1000) ;WinWaitActive("Resize") ;send("^v") EndFunc
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