【问题标题】:.net UIAutomation simple example in C++.net UIAutomation C++ 中的简单示例
【发布时间】:2013-03-30 18:49:29
【问题描述】:

我在 .Net 中通过 UIAuomation Clients API 并且必须使用 C++ 而不是 C#。这是因为 SendInput 函数仅在 C++ 中可用,并且似乎是将鼠标点击发送到任何应用程序的最可靠方法(与此问题相同:How to manipulate a control without any pattern implemented?)。

由于缺少有关 msdn 的文档,现在我正在努力使用 C++ 版本的 UIAutomation API。有人可以告诉如何使用CreatePropertyCondition、UIA_NamePropertyId 和“Windows Media Player”创建 PropertyCondition。

char *name = new char[30];
strcpy(name, "Windows Media Player");
VARIANT vt;
vt.vt = VT_CARRAY; // This is probably wrong
vt.pcVal = name;
hr = g_pAutomation->CreatePropertyCondition(UIA_NamePropertyId, vt, &condition);
if(!SUCCEEDED(hr)){
    printf("Cannot createpropertycondition in getWMP\n");
    return hr;
}

我总是进入if 条件。 g_pAutomation 变量工作正常,我能够很好地获取 RootElement。

还有一个简单教程/示例(C++ 语言)的链接将非常有用。

谢谢

【问题讨论】:

  • 有点离题,但是...你看过类似inputsimulator.codeplex.com或白色的东西吗?
  • 我尽量不使用任何第三方代码,只坚持 .NET 的能力。我也确实看到了其他一些开源的东西。谢谢

标签: microsoft-ui-automation


【解决方案1】:

你应该试试:

VARIANT vt;
vt.vt = VT_BSTR;
vt.bstrVal = SysAllocString(windowName);

浏览 MSDN 非常困难,但我设法找到了一个示例: http://msdn.microsoft.com/en-us/library/windows/desktop/ff625913(v=vs.85).aspx

【讨论】:

    猜你喜欢
    • 2010-11-25
    • 2010-12-13
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    • 2011-08-21
    • 2011-10-12
    相关资源
    最近更新 更多