Jump to content

Get previous active window (not current)


Recommended Posts

Hi guys.

Writing another script again to help out my "lovely" staff. But need some help.

Current Issue:

We open different format docs word, excel, adobe etc

When users press print they are presented with a popup (its actually a program [CLASS:#32770]) 

They must then type a matter number that this doc reffers to into this pop up so they can bill for the printing.

What I want:

Type the matter number in automatically when the popup appears.

The scripts so Far:

Get title from document

Strip down title to just the document number

Lookup a temp file (created by our doc management program) and get matter number out of it.

The issue:

My script currently only gets the matter number from a document when hotkey is pressed as im still testing.

But should I run the GetMatter function every time a window changes? and winwait for the popup to then type in the number? (not sure how to do the first bit)

But Would that use a lot of processing power?

If that isn't a good option could I winwait for the popup then somehow switch back to the LAST active window and get the title?

Thanks for any help and hope my question isnt to confusing :)

Here is my current code for testing.

;Gets title of current open window
;Trims down title to get doc Number
;Gets matter number from prf File

;TO DO - Send matter number to equitrack when pop occurs

;Run only one version of script
#include <Misc.au3>
_Singleton ("EqFiller")




;Hotkeys used for testing
HotKeySet("!d", "GetMatter")
HotKeySet("{ESC}", "Terminate")
HotKeySet("!f", "Check")

;Global $matternum
;~ If not WinActivate ("[CLASS:#32770]") Then
;~    GetMatter ()
;~ ElseIf WinActivate ("[CLASS:#32770]") Then
;~    MsgBox (0,"MatterNum", $matternum)
;~ Endif

While 1
    Sleep(100)
WEnd

Func GetMatter ()
;Location of checked out docs
$temppath = "C:\NRPortbl\matters\" & @UserName

;Get title of current window so we can find doc number
;Might need to change as eqtrack would be current open window
$title = WinGetTitle("[CLASS:OpusApp]")
;Active Window
;WinSetState ("[CLASS:#32770]","",@SW_Hide)
$active = WinGetTitle("")
;AcrobatSDIWindow
;XLMAIN

;Find position of hash sign in window title as doc number follows this
$Start = StringInStr  ($title, "#")
;Trim the window title from the hash sign (plus one character over) and for 8 characters long
$tempdocnum = StringMid ($title,$Start+1,8)
;Convert v1 or v2 (versions) to _1 or _2
$docnum = StringReplace ($tempdocnum,"v","_")

;Testing
;MsgBox(0, "Full title read was:", $active & @LF & $title & @lf & $start & @lf & $tempdocnum & @lf & $docnum)

;Open loked file (prf) using doc number
$locfile = FileOpen ($temppath & "\" & $docnum & ".prf")
;Read line 18 (should contain matter number)
$tempMatter = FileReadLine ( $locfile,18)
;Trim the words off the start so we just endup with matter Number
$Matternum = StringTrimLeft ($tempMatter, 7)

;Testing
;MsgBox (0,"Matter number from PRF file", $tempMatter & @lf & $matternum)

;Close File
FileClose ($locfile)

MsgBox (0,"MatterNum", $matternum)
;WinSetState ("[CLASS:#32770]","",@SW_SHOW )
EndFunc

Func Terminate()
    Exit 0
 EndFunc   ;==>Terminate

Func Check()
$title = WinGetTitle("[CLASS:OpusApp]")
$state = WinGetState ($title)
$active = WinGetTitle("")
$activestate = WinGetState ("$active")
MsgBox (0,"","Title=" & $title &@lf&  "State=" & $state &@lf& "Active title=" & $active &@lf& "Active State=" & $activestate)
EndFunc
Link to comment
Share on other sites

Sorry that script is using the [CLASS:OpusApp] For word2007 as a majority of our documents are word docs.

But at any one time a user may have open several word docs a pdf and maybe excel. So the script should really word for all classes.

....or even any type of file if possible, but returning blank if no matter# is found.

I think its more the script logic I need help with :)

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...