GadgetOllie Posted December 11, 2008 Share Posted December 11, 2008 I'm new to AutoIt and I'm amazed at what this software can do. I've only been using AutoIt for a little over a week so I'm sure my code isn't as professional or a streamlined as some of the more "seasoned" users (but hey, I'm giving it a try). I'm using a program called My Voice Controller to run my system by voice command and AutoIt fits in perfectly, allowing me to write scripts to automate everything by voice. Example...This code goes to the internet, retrieves the current stock price on Microsoft, puts it on the clipboard where it returns to My Voice Controller and speaks the results when I give the voice command "What's Microsoft Stock doing". Same for weather, the Dow Jones Industrial Average, etc. (pretty cool stuff)...Thanks AutoIt!!! CODE#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.1 Author: Gadget Ollie Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here If FileExists("C:\Temp\") Then Real() Else DirCreate("C:\Temp\") Real() EndIf Func Real() InetGet ( "http://download.finance.yahoo.com/d/quotes.csv?s=MSFT&f=l1c1p2", "c:\temp\quote.txt", 1) $fil = FileRead("C:\Temp\quote.txt", 1000) $array = Stringsplit ( $fil,",") $Price=$array[1] $Change = $array[2] $PercentChange=$array[3] If $change=0 Then $change= " . The stock is unchanged from the opening price." ElseIf $change < 0 Then $change=" . The stock is down by "&StringMid($change,2)&" points" Else $change=" . The stock is up by "&StringMid($change,2)&" points" EndIf $StockPrice="the current price is $"&$Price &$Change ClipPut($StockPrice) FileDelete ( "C:\Temp\quote.txt" ) EndFunc Exit Anyway, in programming some scripts to use with My Voice Controller, I noticed an issue with 2 functions (WinGetClientSize and _WinAPI_GetClientHeight). Both return the incorrect window height where WinGetPos returns a different value for the window height (the correct value). Even using the AutoIt Window Info tool, the window height comes back correctly (different than what is returned from the WinGetClientSize and _WinAPI_GetClientHeight functions but the same as the WinGetPos function). Anyone else notice this or am I doing something incorrect? I searched the forum and couldn't find anything on this issue. The code is to center the active window on the display taking the width of the taskbar into consideration (using a voice command to "Center Window")...Btw, some of the code comes from the wonderful examples provided by users on this forum and I try to give credit where credit is due. CODE; get Active Window (Title)(Text) ; Author - SmOke_N & Valuater ; modified by Gadget Ollie -- Original code from AutoIt examples forum Dim $winname, $wintxt $MyText = WinGetText(FindActiveWindow()) $MyTitle = WinGetTitle(FindActiveWindow()) $winsize = WinGetPos($winname, $wintxt) ;added G.O. $Taskbar = ControlGetPos("[CLASS:Shell_TrayWnd]", "Running Applications", "[CLASS:ToolbarWindow32; INSTANCE:2]");added to take taskbar width into consideration G.O. Local $y = (((@DesktopHeight - $Taskbar[3]) / 2) - ($winsize[3]) / 2);added G.O. Local $x = (@DesktopWidth / 2) - ($winsize[2] / 2);added G.O. WinMove($winname, $wintxt, $x, $y);added G.O. Func FindActiveWindow() Local $HidOpt = Opt("WinDetectHiddenText", 1);0=don't detect, 1=do detect Local $w_WinList = WinList() For $i = 1 To $w_WinList[0][0] If $w_WinList[$i][0] <> "" And BitAND(WinGetState($w_WinList[$i][1]), 2) _ And BitAND(WinGetState($w_WinList[$i][1]), 8) Then Return $w_WinList[$i][0] Next Opt("WinDetectHiddenText", $HidOpt);0=don't detect, 1=do detect EndFunc ;==>FindActiveWindow This code now works with the WinGetPos function, properly centering the window in the Available Screen space where the other two functions were always off by 50 pixels or so. Link to comment Share on other sites More sharing options...
ResNullius Posted December 11, 2008 Share Posted December 11, 2008 (edited) ClientSize is differenet than the Window size.ClientSize is the size of the window minus the top border/title bar, as well as the bottom and left and right borders.Can't recall if menu bars are included in client size or not. Edited December 11, 2008 by ResNullius Link to comment Share on other sites More sharing options...
GadgetOllie Posted December 11, 2008 Author Share Posted December 11, 2008 Well, that certainly explains it. Thanks for the reply! Link to comment Share on other sites More sharing options...
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