Posts: 795
Threads: 136
Joined: Feb 2009
Hi Gintaras and all,
i tried to create a filter function to intercept #32770 windows class, and close automagically some that are annoying.
First i created a filter function, triggered by #32770 class windows, from template, which calls function A with f as parameter.
/
Allows starting macro only in certain window.
function# iid FILTER&f
Manage32770(&f)
ret iid
Then i try to search for childs in f.hwnd window, to see if i close it or not.
I must inspect childs of f.hwnd, and for instance, look if one contains some text.
function Manage32770
function FILTER'&f
_s.getwintext(f.hwnd)
out _s
_s.getwinclass(f.hwnd)
out _s
_s.getwinexe(f.hwnd)
out _s
int h=WinC("Texttosearchfor" "" 0 "" "#32770")
Problem 1: i always get a message saying the filter function is too long, though i thought that the Manage32770 function will handle it alone.
Is there a way to get out the filter function immediatly and leave the manage32770 function do its job on its own?
Problem 2: i can't find the proper way to enumerate childs of f.hwnd, either by WinC, or Acc getchildobjects.
I know you'll save my bacon....
thanks
Posts: 12,066
Threads: 140
Joined: Dec 2002
1. Replace
Manage32770(&f)
to
mac "Manage32770" "" f.hwnd ;;note: don't pass &f, because the variable will be already destroyed
and replace
function FILTER'&f
to
function hwnd
2.
Use function child() and array.
Or don't use filter function but instead call Manage32770 from macro.
Posts: 795
Threads: 136
Joined: Feb 2009
Wonderful, as usual.
I never thought i could call a function via mac procedure.
Just changing as you said made my old code working, and i can now access childs.
you're a god.
Cheers
Posts: 795
Threads: 136
Joined: Feb 2009
Just a detail:
i'd like a variable value to be retained between sucessive calls of Manage32770 function.
how to declare it and where.
Posts: 12,066
Threads: 140
Joined: Dec 2002
Use global variable. Declaration can be like
int+ g_globalVariable
Declare where it is used first time. Can declare same variable in many places.
If the variable will be used in single thread, instead use thread variable.
int- t_threadVariable
Declare in all functions where used.
Posts: 795
Threads: 136
Joined: Feb 2009
OK just to be sure.
My setup owns a function triggered at QM launch : QMStartProc
Say I put a global variable in it, available for ANY macro/function in Qm, anytime.
Q1. I should then declare it in QMStartProc -> int+ g_globalVariable=100. Correct?
Q2. For using it in a macro later, say Macro1 , I type too the declaration in Macro1 -> int+ g_globalVariable
What is it's value then, 100? What if I declare it like int+ g_globalVariable=50 in Macro1??
Q3. I use a Filter function, and want a variable *ONLY* in this function, but global to keep it's value available between
filter function calls.
Do I use int+ g_globalVariableinFilterFunction? Will it be accessible to other function?
If i put int+ g_globalVariable, will it's be 100 or 50 (Macro1 called before Filter function)
Sorry for the noise, but it's a bit unclear for me.
Thanks
Posts: 12,066
Threads: 140
Joined: Dec 2002
Macro Macro243
;GLOBAL VARIABLES
;Case A:
int+ g_globalVariable ;;declare a global variable. If already exists, do nothing.
g_globalVariable=100 ;;assign a value
;Case B:
int+ g_globalVariable=100 ;;declaration and assignment in single statement
;Cases A and B are equivalent.
;Case B is just a shorter way to declare and assign.
;int+ g_globalVariable does not change the value.
;g_globalVariable=100 is executed in both cases, every time.
;The variable has the value assigned last time, regardless whether it was case A or B.
;Global variables are shared by all functions. Currently QM does not have a local scope for global variables.
;__________________________________
;THREAD VARIABLES
;Case C:
int- g_gthreadVariable ;;declare a thread variable. If already exists, do nothing.
g_gthreadVariable=100 ;;assign a value
;Case D:
int- g_gthreadVariable=100 ;;declaration and assignment in single statement
;In case C, assignment is executed every time.
;In case D, assignment is executed once.
;If int- (like in the example), the variable is shared between all functions of current thread. Anyway, need to declare in all functions where used.
;If int--, the variable is not shared. If same declaration is in other function, it is other variable.
;__________________________________
;More info in QM Help topic "Variable storage and scope".
All filter functions run in one special thread. Therefore thread variables can be used to keep value available between filter function calls.
But if you run a function with mac, the function runs in own thread, therefore need to use global variables.
Posts: 795
Threads: 136
Joined: Feb 2009
OK, a bit clearer, as long as i can translate
Quote:the variable is shared between all functions of current thread
by
the variable is shared between by all functions and macros that are called from the first one which declares/initialize it and only by this one.
Thanks
Posts: 12,066
Threads: 140
Joined: Dec 2002
Quote:the variable is shared between by all functions and macros that are called from the first one which declares/initialize it and only by this one.
Not exactly. The variable is shared between all functions of current thread where the variable is declared.
For example, macro A declares int- t_test. Macro A calls function B. Function B also declares int- t_test. This way A and B use the same variable t_test.
Another example. Function C is called multiple times in thread. Function C declares int- t_test or int-- t_test. Variable t_test retains its value between function calls.
Posts: 795
Threads: 136
Joined: Feb 2009
OK, seems the last called function is the dominant then.
Q1:
If i follow you:
A -> int- global=20
A calls B where global becomes 30
C is called numerous times, adds 10 each time, so after 3 calls, global=60
If I call B then after all C calls, then global becomes again 30. Correct?
Id i call D which sets global+100, it's 130 and so on?
Q2: To store global after thread closed, i suppose I must read a file storing it's last value and assign from that?
Q3: Is this variable behavior scheme usable in exe?
Posts: 12,066
Threads: 140
Joined: Dec 2002
Q1. Probably correct. You can easily test.
Q2, 3. May need to store variable values in a file or registry if the macro runs in exe or separate process.
Posts: 795
Threads: 136
Joined: Feb 2009
Seems OK so far in my tests. Thanks
|