Jump to content

Recommended Posts

Posted

More often than not, when have the need to run a process, I also have the need to do other things to it as well. For example, closing the process.

When I am working on an application with only one or two processes, it is easy enough to statically entered the text as a string in the script code. However, I am interested in a more dynamic approach.

After looking through the forums and documentation, I have not seen what I would call an "easy" way to get the window title from a program's name.

I have seen some very impressive work done on this subject, but it seems a bit overwhelming when in theory this is a pretty simple thing to be looking for. So I have been trying to come up with an alternative method, and while it does work (most of the time), I definitly think it could be improved upon. Remember, simplicity is the key here, and I think it is a goal that can be acheived.

Here is what I have come up with so far:

;

; Program Window Title at Launch
; Author BKAZDAN 2/7/08

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 2); I have found that 2 & 4 have both worked exactly the same for me

; Run this program and log its title
Func _ProgTitle($Program)
    
; Run the Program
    Run($ProgName)
    
; I am pretty sure I am doing something wrong here.
; This should wait until the program is loaded or 1000ms
; and then it should timeout.
; For now it is just acting as a 1000ms delay, but I would like to fix that.
    WinWaitActive("[LAST]","",1) 
; Return the title to where it was called from
    Return WinGetTitle("[ACTIVE]", "") 
EndFunc

;
;Same as above, but minimal code needed
;
Func _P($P)
    Run($p)
    WinWaitActive("[LAST]","",1) 
    Return WinGetTitle("[ACTIVE]", "")
EndFunc

;

;

; --------------------------------------------------------
; Program Window Title at Launch - Example
; Author BKAZDAN 2/7/08

; Allow a program to be chosen
Dim $ProgName = FileOpenDialog("Application",@ProgramFilesDir,"All Files(*.*)",2)

; Send the chosen program to _ProgTitle to run it and have its title logged
Dim $WinTitle = _ProgTitle($ProgName)

; A little message to report the title name, just to make sure it is correct.
MsgBox(0,"Application Title:", $WinTitle)

; Close the program we opened
WinClose($WinTitle)
;

I am very interested to see what could be done to improve upon this code.

Thanks

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
×
×
  • Create New...