2014-09-15

源代码

目录

引用程序集
实现提供程序接口
分发客户端提供程序
注册和配置客户端提供程序
WinForm Sample
参考

引用程序集[1]


 返回

  • UIAutomationClient.dll
  • UIAutomationProviders.dll
  • UIAutomationTypes.dll 

实现提供程序接口[2]


 返回

以下示列实现提供程序接口:IRawElementProviderSimple

 1     class WindowProvider : IRawElementProviderSimple
 2     {
 3         IntPtr providerHwnd;
 4         public WindowProvider(IntPtr hwnd)
 5         {
 6             providerHwnd = hwnd;
 7         }
 8         internal static IRawElementProviderSimple Create(
 9             IntPtr hwnd, int idChild, int idObject)
10         {
11             System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("WinFormServer");
12             if (processes.Length == 0)
13                 return null;
14             //Check if the target is specified process
15             //If yes, create and run provider instance
16             if (processes[0].MainWindowHandle != hwnd)
17                 return null;
18             else
19                 return new WindowProvider(hwnd);
20         }
21         ProviderOptions IRawElementProviderSimple.ProviderOptions
22         {
23             get
24             {
25                 //Return ClientSideProvider as the implementation is in client
26                 return ProviderOptions.ClientSideProvider;
27             }
28         }
29         IRawElementProviderSimple IRawElementProviderSimple.HostRawElementProvider
30         {
31             get
32             {
33                 return AutomationInteropProvider.HostProviderFromHandle(providerHwnd);
34             }
35         }
36         object IRawElementProviderSimple.GetPropertyValue(int aid)
37         {
38             if (AutomationProperty.LookupById(aid) ==
39                 AutomationElementIdentifiers.NameProperty)
40             {
41                 //Our UIA.Name property implementation
42                 //In production code, usually it uses Win32 or MSAA to get real information
43                 return "UIA Client Implementation";
44             }
45             else
46             {
47                 return null;
48             }
49         }
50         object IRawElementProviderSimple.GetPatternProvider(int iid)
51         {
52             //Return null means it does not support any Pattern Provider
53             return null;
54         }
55     }
View Code

相关文章:

  • 2021-08-02
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
猜你喜欢
  • 2022-02-22
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2021-08-21
  • 2022-12-23
相关资源
相似解决方案