Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WinEventHook SYSTEM_DIALOGSTART never raised
#1
Dear Sirs,

it seems that event for starting system dialog #32770 is never raised (see sample script below).
Only event for dialog end is catched.
I'm trying to get the selected path of choosen file(s) after hitting button (Open/Save/SaveAs ...) on the system dialog cn:#32770. Therefore I try to use a general Hook but DialogEnd message seems to be too late because window might be already released.
My idea was to start a timer to detect changes of path value (cn:#32770, id: 41477) at DialogStart and stop timer later after DialogEnd is raised - but without luck till now.
If anyone has an idea how to implemente such a hook to catch the user selected filepath, please let me know.
 
Code:
Copy      Help
// script "TestEventHook.cs"

using Au.Triggers;

script.setup(trayIcon: true, sleepExit: true);

ActionTriggers Triggers = new();
  new WinEventHook(EEvent.SYSTEM_DIALOGEND, EEvent.SYSTEM_DIALOGEND, k => {
    var cf = new wndChildFinder(id: 41477);
    bool found = k.w.IsMatch(cn: "#32770", contains: cf);
    print.it($"SYSTEM_DIALOGEND found={found} => {k}");
  });


  new WinEventHook(EEvent.SYSTEM_DIALOGSTART, EEvent.SYSTEM_DIALOGSTART, k => {
    var cf = new wndChildFinder(id: 41477);
    bool found = k.w.IsMatch(cn: "#32770", contains: cf);
    print.it($"SYSTEM_DIALOGSTART found={found} => {k}");
  });


Triggers.Run();
#2
Sometimes Open/Save dialog does not raise the event. Use window trigger instead.

Code:
Copy      Help
// script "TestEventHook.cs"
using Au.Triggers;

script.setup(trayIcon: true, sleepExit: true);
print.clear();

ActionTriggers Triggers = new();

#if !true

new WinEventHook(EEvent.SYSTEM_DIALOGEND, EEvent.SYSTEM_DIALOGEND, k => {
    var cf = new wndChildFinder(id: 41477);
    bool found = k.w.IsMatch(cn: "#32770", contains: cf);
    print.it($"SYSTEM_DIALOGEND found={found} => {k}");
});

new WinEventHook(EEvent.SYSTEM_DIALOGSTART, EEvent.SYSTEM_DIALOGSTART, k => {
    var cf = new wndChildFinder(id: 41477);
    bool found = k.w.IsMatch(cn: "#32770", contains: cf);
    print.it($"SYSTEM_DIALOGSTART found={found} => {k}");
});

#elif use_window_trigger_instead

//this code can be genarated by menu > TT > New trigger, or hotkey Ctrl+Shift+Q > Triggers > Window trigger
Triggers.Window[TWEvent.ActiveNew, null, "#32770", contains: "c 'SHELLDLL_DefView' ShellView", later: TWLater.Destroyed] = o => {
    if (o.Later is 0) {
        print.it("Trigger", o.Window);
    } else if (o.Later is TWLater.Destroyed) {
        print.it("later: Destroyed");
    }
};

#else

//this code shows how to set a window trigger and listen for all UI element events generated in that window. Then use chosen events.

Dictionary<wnd, WinEventHook> hooks = [];
Triggers.Options.ThreadOfTriggers();
Triggers.Window[TWEvent.VisibleNew, null, "#32770", contains: "c 'SHELLDLL_DefView' ShellView", later: TWLater.Destroyed] = o => {
    if (o.Later is 0) {
        print.it("Trigger", o.Window);
        
#if !true //log all events in the trigger window
        print.clear();
        int index = 0;
        var hook = new WinEventHook(EEvent.MIN, EEvent.MAX, k => {
            if (k.w.Window != o.Window) return;
            print.it(index++, k.event_, k.w);
        }, 0, o.Window.ThreadId);
#else //use a chosen event
        string address = null, fileName = null;
        var hook = new WinEventHook([EEvent.OBJECT_NAMECHANGE, EEvent.OBJECT_VALUECHANGE, EEvent.OBJECT_INVOKED], k => {
            if (k.w.Window != o.Window) return;
            try {
                switch ((k.event_, k.w.ClassName, k.w.ControlId)) {
                case (EEvent.OBJECT_NAMECHANGE, "ToolbarWindow32", 1001): //editable toolbar
                    address = k.w.Name;
                    break;
                case (EEvent.OBJECT_VALUECHANGE, "Edit", 1148): //file name
                    fileName = k.w.ControlText;
                    break;
                case (EEvent.OBJECT_INVOKED, "Button", 1): //button Open or Save
                    print.it(address, fileName);
                    break;
                default: return;
                }

                
                print.it(k.event_, k.w, k.w.ControlId);
            }

            catch (Exception ex) { print.warning(ex); }
        },
0, o.Window.ThreadId);
#endif
        hooks.Add(o.Window, hook);
    }
else if (o.Later is TWLater.Destroyed) {
        print.it("later: Destroyed");
        
        if (hooks.Remove(o.Window, out var hook)) hook.Dispose();
    }
};


#endif

Triggers.Run();
#3
Thank you Gintaras for pointing me the right way.
Your sample code works well and is very elegant.
Problem solved.


Forum Jump:


Users browsing this thread: 1 Guest(s)