Quantcast
Channel: Windows Desktop Development for Accessibility and Automation forum
Viewing all articles
Browse latest Browse all 585

Can you add an IUIAutomation event handler from within the handler itself?

$
0
0

I'm implementing a COM shell extension handler. After the handler is loaded by File Explorer, I'd like to use IUAutomation to handle certain UI events (element selections). I was hoping to handle the events right within my class, so that the event handler would have access to member variables. So I added the IUIAutomationEventHandler interface and methods to my existing class. And in my class's setup methods (like FinalConstruct(), etc.), after obtaining the IUIAutomation object and performing other prep work, I did something like this:

pAutomation->AddAutomationEventHandler(   
     UIA_SelectionItem_ElementSelectedEventId,
     pRootElement,
     TreeScope_Subtree,
     NULL, 
     (IUIAutomationEventHandler*)this
);

This seems to work, EXCEPT in my testing, I've found that each element selection event gets fired twice. Now I'm not sure if that's because I added the event handler from within the handler itself. I also know that using IUIAutomation presents a number of threading issues, and maybe my setup violates those rules. So I was wondering if my approach is not permissible, and/or how to solve the issue of firing twice. Does the addition of the event handler have to take place on a different thread? And if so, how would one go about doing that within a COM class? Or is it important to place the entire IUIAutomation handler in a different class, and then just share data through global variables? Thank you very much for any insight.




Viewing all articles
Browse latest Browse all 585

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>