Posts: 795
Threads: 136
Joined: Feb 2009
Hi Gintaras, hi all
I've a toolbar attached to a program main window.
It gives access to numerous functions based on the window component (files, edit boxes, lists etc) to treat files on folders in listview.
When I change folders, some variables (global ones) needs to be reinitialized to default values. The routines I use sometimes miss the point, so I created a "init" function to reset all needed variables. But sometimes
results are bad too. My best bet is then to close (destroy) the toolbar itself and switch again the main program windows to restart a "fresh" toolbar initialisation (done in the WM_INITDIALOG condition of the hook function).
Can it be done by code?
Thanks
Posts: 12,097
Threads: 142
Joined: Dec 2002
Why/how results are bad when calling "init" function?
Posts: 795
Threads: 136
Joined: Feb 2009
why, no idea, i would not ask for help if i knew...
How, some variables don't go back to their default values, or i don't know how reset them, as a personal type variable containing 3 int, 2 str, 1 array of string for instance....
Posts: 12,097
Threads: 142
Joined: Dec 2002
Macro Macro2779
type personal i1 i2 i3 str's1 str's2 ARRAY(str)a1
personal+ g_x
;...
;assign an empty local variable. If some members are file handles, bitmap handles or something other that need to free/close explicitly, free them before.
personal _e; g_x=_e
Posts: 795
Threads: 136
Joined: Feb 2009
yes, mainly windows handles involded, will try that..
Any suggestion for restart my toolbar from inside function (via a pressed button???)
Posts: 12,097
Threads: 142
Joined: Dec 2002
Free hanldes - I mean execute the same code as is in destructor, if the type has destructor and does not have operator=. Then QM shows a warning when assingning variable.
Function RestartToolbar
;Call this from a toolbar to close it and open new.
;EXAMPLE (toolbar button)
;Restart toolbar :RestartToolbar
int hTB(TriggerWindow) hOwner(GetToolbarOwner(hTB)) iid(getopt(itemid 3))
clo hTB
mac iid hOwner
Posts: 795
Threads: 136
Joined: Feb 2009
Ok, will try
BTW, my type definition includes an Acc variable, and when used in initialisation routine i get this
type MYDATA int'nombre str'Chemin ARRAY(str)'Nom str'Genre int'M int'H POINT'_m Acc'liste
Most COM objects cannot be global (+). Or may need <help>lock. Need to release explicitly.
Can you provide an exemple of getting an Acc'liste working???? I need several global Acc variables or an ARRAY(Acc)...either in MYDATA or declaring Acc+ op gives error
Posts: 795
Threads: 136
Joined: Feb 2009
restartToolbar function is great thanks
Posts: 12,097
Threads: 142
Joined: Dec 2002
Now I tested this
Macro Macro2781
Acc+ g_accTest
if !g_accTest.a
,int w=win("This PC" "CabinetWClass")
,g_accTest.Find(w "LISTITEM" "Downloads" "class=DirectUIHWND" 0x1005)
out g_accTest.Name
;next time:
;Error (RT) in <open ":13564: /145">Macro2781: 0x800401FD, Object is not connected to server. <help #IDP_ERR>?
It means that an Acc object is invalid in other threads, and therefore global variables does not have sense. There are possible alternatives, but not easy. Better change your code so that would not need non-temporary Acc variables.
Posts: 795
Threads: 136
Joined: Feb 2009
1. my initial code is not using global variables at all, but it needs to recode again and again the same routines to locate the same Acc objects (either directly or via functions)
But, maybe it's useless as I have a powerful laptop (i7 + 24Go of RAM)...
2. Is it really useful to mess like I do with global variables, or multiple functions (one for each Acc object retrieval) is fast and is not impacting the speed/memory use of my toolbar?
I ask, because it's not easy to decide.
3. Is it possible to return an Acc object, a global variable from a function?
Posts: 12,097
Threads: 142
Joined: Dec 2002
Finding an accessible object in some windows is slow. You can see it in dialog 'Find accessible object' when you click Test. In code you can measure speed with PerfFirst/PerfNext/PerfOut.
But caching accessible objects in global variables would be useful only if these find-object functions are called so frequently that you see increased CPU usage of qm.exe process in Task Manager or Process Explorer.
If finding is too slow, at first I would try to make it faster. For example, try to find a temporary object, then search in it.
3. Possible, but it would be the same object, invalid in other threads. Maybe possible to marshal it to another thread, I'll read about it and try.
Posts: 795
Threads: 136
Joined: Feb 2009
for point 3., i do it by passing a function an Acc object by reference, seems quick and easier
function Acc'&a
maybe not worth the extra work from you...
Posts: 795
Threads: 136
Joined: Feb 2009
is it possible to send for exemple Ctrl+A to Acc variable, without using mouse to select it first??????
I want to select all files in a LIST role Acc object..
Posts: 12,097
Threads: 142
Joined: Dec 2002
Macro Macro2784
int w=win("This PC" "CabinetWClass")
act w
Acc a.Find(w "LIST" "Items View" "class=DirectUIHWND" 0x1005)
a.Select(1)
key Ca
Posts: 795
Threads: 136
Joined: Feb 2009
Ok, done
Last one for the moment, i have an item in a OUTLINEITEM Acc
I'ts a folder, and I need to get it's full path. For the moment, i only can acheive that from Shift+right menu, and click on the item copying path to clipboard.
Any idea?
Posts: 12,097
Threads: 142
Joined: Dec 2002
Posts: 12,097
Threads: 142
Joined: Dec 2002
Tested: accessible objects can be marshaled to other threads with CoMarshalInterThreadInterfaceInStream and CoGetInterfaceAndReleaseStream.
But probably nobody would use it, because would need to write quite much code for each object. Etc etc.
Posts: 795
Threads: 136
Joined: Feb 2009
yes, far beyond my skills, will try something else..
Last question : when i can, i access a context menu( (mouse right button) from the record feature of QM, quick and convenient
But sometimes, context menu changes due to files selection, some items appearing and some diseappearing depending of the kind of files.
Question : how to access a right menu item from its text, not by position or id???
Posts: 795
Threads: 136
Joined: Feb 2009
Gintaras Wrote:Macro Macro2784
int w=win("This PC" "CabinetWClass")
act w
Acc a.Find(w "LIST" "Items View" "class=DirectUIHWND" 0x1005)
a.Select(1)
key Ca
does not work (no selection done), but my workaround does, so no problem...
Posts: 12,097
Threads: 142
Joined: Dec 2002
Quote:Last question : when i can, i access a context menu( (mouse right button) from the record feature of QM, quick and convenient
But sometimes, context menu changes due to files selection, some items appearing and some diseappearing depending of the kind of files.
Question : how to access a right menu item from its text, not by position or id???
Macro Macro2787
;#region Recorded 2016-01-25 19:33:34
;int w1=act(win("Downloads" "CabinetWClass"))
;rig 235 310 w1 1 ;;list 'Items View', editable text 'Name'
;lef 58 251 wait(15 WV win("" "#32768")) 1 ;;menu item 'Copy path'
;;men 31057 child("ShellView" "SHELLDLL_DefView" w1) ;;
;#endregion
int w1=act(win("Downloads" "CabinetWClass"))
rig 235 310 w1 1 ;;list 'Items View', editable text 'Name'
int w2=wait(15 WV win("" "#32768")) ;;popup menu
Acc a.Find(w2 "MENUITEM" "Run as administrator" "" 0x1001 3)
a.DoDefaultAction
Posts: 795
Threads: 136
Joined: Feb 2009
Excellent thanks as usual...
|