Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
filter by app
#1
I'm trying to filter a macro so that it only works within a certain window in a certain application, specifically Avid Xpress. The window I'm interested in is distinguished in the application only by its ID, as indicated in the QM status bar (id=2). The entire app appears as the same window name, but the id changes between the windows within the app.

How do I modify the win/wintest line so that it filters by the app and the window id?

Also, I want a macro to only run in Trillian Pro. But Trillian launches different window names based on the person I'm chatting with, so how do I filter based ONLY on the name of the app?

I tried

Code:
Copy      Help
if(win("" "" "Trillian")) ret iid

and

Code:
Copy      Help
if(win("" "Trillian" "")) ret iid

Code:
Copy      Help
if(win("" "" "C:\Program Files\Trillian\trillian.exe")) ret iid

but the macro still runs in other apps.

thanks!
Ze'ev
#2
If you are writing a filter function, please read "Filter function examples" in QM help (Example1).

Program: if it is for trigger, use scope rather than evaluate it in filter function. If it is in a macro, use wintest.

You should use wintest rather than win. Function win searches for specified window and returns window handle, so, if such window exists, the code allows macro to run. Function wintest examines window (first argument is window handle) and returns 1 if window's properties match other arguments. This handle, for example, can be f.hwnd (in filter function) or win() (active window).

QM status bar shows id for control (child window) under mouse pointer. Top-level window does not have id. You can, for example, search for window-specific control. Use function id or child. For example, following filter function allows trigger if window contains a child with text "Text" and class "Static":

Code:
Copy      Help
;/
function# iid FILTER&f

if(child("Text" "Static" f.hwnd)) ret iid

Following filter function allows trigger if window contains a child with id 2:

Code:
Copy      Help
;/
function# iid FILTER&f

if(id(2 f.hwnd)) ret iid

Of course, function child is better in this case, because many windows, even in the same app, can have a control with id 2.


Note: in current QM version, there is one bug in filter functions: for mouse-click triggers, it can give root owner window in f.hwnd. Use win() instead of f.hwnd.
#3
Alright! So this worked for Trillian filter:

Code:
Copy      Help
if(wintest(f.hwnd "" "" "Trillian")) ret iid

still have to test the Avid window id thingy...

Thanks!
Ze'ev
#4
I know if must be a filter function but I am not sure how to set it up.

The macro is a toolbar entry that activates a background process application. But if it is already active, re-starting it causes some problems. I want it to kill the macro, if the process is already running.

Thanks!
Stuart
#5
So you need a function like IsProcessRunning("processname")? Can be used ProcessNameToId or EnumProcessesEx:

if(qm.ProcessNameToId("processname" 0)) ret ;;exit if the process is running

If it has windows, also can be used win:

if(win("" "" "processname")) ret ;;exit if the process is running

This code can be placed at the beginning of the macro. Filter functions are used only with key/mouse/window triggers. If in a filter function, it would be:

if(!qm.ProcessNameToId("processname" 0)) ret iid ;;allow the macro to run if the process is not running

Note: "qm." here is used only as a hint that all dll functions exported by QM are in the qm category. Easier to find. But not necessary.

Note2: ProcessNameToId also finds processes running in other user sessions (fast user switching). In the latest QM version, added function ProcessNameToId2 that can find processes in all or only in current session.
#6
Thanks again, Gintaras,
I will give it a try later today!
Stuart
#7
Hi,
I have tried both

Code:
Copy      Help
if(qm.ProcessNameToId("synergys" 0))ret ;;exit if the process is running
else net("ds43mass" "pass" "OneBoxPacs")

and
Code:
Copy      Help
if(ProcessNameToId("synergys" 0))ret ;;exit if the process is running
else net("ds43mass" "pass" "OneBoxPacs")

and
Code:
Copy      Help
if(qm.ProcessNameToId("synergys" 0))ret ;;exit if the process is running
net("ds43mass" "pass" "OneBoxPacs")

I can't seem to find ProcessNameToId in the functions list to learn its syntax.

Thanks,
Stuart
#8
Returns process id.



exename - program name or full path.

allpids - address of array that receives process ids of all matching processes. Can be 0 if not needed.


Forum Jump:


Users browsing this thread: 1 Guest(s)