jakemoffatt wrote:
The following script takes an average of 20-25% of my CPU while it is running.
What the script does is constantly looks for programs that begin with "Visual DataFlex Studio" and when it finds them, it trims off that text, so that just the "workspace" and "filename" that are loaded into the program appear on the taskbar.
Any tips?
You are inconsistant with your program title, note that 12.1 is shown both before and after Studio; suggest using a program title variable
(not in your case, but a simple variation like this could cause the 'test and rename' function to never rename anything.)
Code:
# IfWinActive, Visual DataFlex 12.1 Studio
Escape::WinClose, Visual DataFlex 12.1 Studio
If WinExist("Visual DataFlex Studio")
StringReplace, Title, Title, Visual Dataflex Studio 12.1 -
The goto statement should be before the hotkey definitions (which includes #IfWinActive)
helpfile wrote:
The Top of the Script (the Auto-execute Section)
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.
Code:
#IfWinActive, Visual DataFlex 12.1 Studio
goto, run
Escape::WinClose, Visual DataFlex 12.1 Studio
As written, this is like a drum-roll with no ending. I don't know the details of the underlying code, but there are a lot of instructions executed needlessly, not even a chance to 'take a breath' so to speak.
Code:
Loop
{
RenameVDF()
CloseImageMan()
}
See the listing below to see the tips implemented. I left out the hotkey and the coded that you had commented out.
Please review the whole listing, there are some variations required for DFS that are not the same as for NotepadCode:
; tested with Notepad, STMM = 2: anywhere in title
SetTitleMatchMode, 2
program = Notepad
; Untested with Visual Dataflex, STMM = 1: must start with the specified
;program = %Visual Dataflex Studio 12.1%
;SetTitleMatchMode, 1
;msgbox '- %program%'
;exitapp
loop
{
; WinWaitActive, %program%,, 2 ; for testing purposes
; WinWait, %program%,, 20 ; as an alternative you could trigger on existance,
; instead of 'active window'
WinWaitActive, %program%,, 20
if (ErrorLevel=1)
{
msgbox,,, not found, .5 ; for testing purposes
continue
}
WinGetTitle, Title
StringReplace, newTitle, Title, - %program% ; for notepad
; StringReplace, newTitle, Title, %program% - ; for Visual DataFlex
WinSetTitle, %Title%, , %newTitle%
}
Improvements on the above script including commenting out the 'not found' msgbox
and changing the timeout parameter of the preferred winwait??? variant.