<i id='FuUfO'><tr id='FuUfO'><dt id='FuUfO'><q id='FuUfO'><span id='FuUfO'><b id='FuUfO'><form id='FuUfO'><ins id='FuUfO'></ins><ul id='FuUfO'></ul><sub id='FuUfO'></sub></form><legend id='FuUfO'></legend><bdo id='FuUfO'><pre id='FuUfO'><center id='FuUfO'></center></pre></bdo></b><th id='FuUfO'></th></span></q></dt></tr></i><div id='FuUfO'><tfoot id='FuUfO'></tfoot><dl id='FuUfO'><fieldset id='FuUfO'></fieldset></dl></div>
      <bdo id='FuUfO'></bdo><ul id='FuUfO'></ul>
  • <small id='FuUfO'></small><noframes id='FuUfO'>

      <tfoot id='FuUfO'></tfoot>

      1. <legend id='FuUfO'><style id='FuUfO'><dir id='FuUfO'><q id='FuUfO'></q></dir></style></legend>

        如何将 POINT 结构传递给 Python 中的 ElementFromPoin

        时间:2023-09-11
      2. <tfoot id='AkFWD'></tfoot>

            <bdo id='AkFWD'></bdo><ul id='AkFWD'></ul>
            <i id='AkFWD'><tr id='AkFWD'><dt id='AkFWD'><q id='AkFWD'><span id='AkFWD'><b id='AkFWD'><form id='AkFWD'><ins id='AkFWD'></ins><ul id='AkFWD'></ul><sub id='AkFWD'></sub></form><legend id='AkFWD'></legend><bdo id='AkFWD'><pre id='AkFWD'><center id='AkFWD'></center></pre></bdo></b><th id='AkFWD'></th></span></q></dt></tr></i><div id='AkFWD'><tfoot id='AkFWD'></tfoot><dl id='AkFWD'><fieldset id='AkFWD'></fieldset></dl></div>

                  <legend id='AkFWD'><style id='AkFWD'><dir id='AkFWD'><q id='AkFWD'></q></dir></style></legend>

                  <small id='AkFWD'></small><noframes id='AkFWD'>

                    <tbody id='AkFWD'></tbody>
                  本文介绍了如何将 POINT 结构传递给 Python 中的 ElementFromPoint 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用方法 IUIAutomation::ElementFromPoint 在 Python 中使用 comtypes包裹.有很多示例如何在 C++ 中使用它,但在 Python 中没有.这个简单的代码在 64 位 Windows 10(Python 2.7 32 位)上重现了该问题:

                  I'm trying to use method IUIAutomation::ElementFromPoint in Python using comtypes package. There are many examples how to use it in C++, but not in Python. This simple code reproduces the problem on 64-bit Windows 10 (Python 2.7 32-bit):

                  import comtypes.client
                  
                  UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
                  UIA_dll.IUIAutomation().ElementFromPoint(10, 10)
                  

                  我收到以下错误:

                  TypeError: Expected a COM this pointer as first argument
                  

                  以这种方式创建 POINT 结构也无济于事:

                  Creating the POINT structure this way doesn't help as well:

                  from ctypes import Structure, c_long
                  
                  class POINT(Structure):
                      _pack_ = 4
                      _fields_ = [
                          ('x', c_long),
                          ('y', c_long),
                      ]
                  
                  point = POINT(10, 10)
                  UIA_dll.IUIAutomation().ElementFromPoint(point) # raises the same exception
                  

                  推荐答案

                  可以直接复用已有的 POINT 结构定义,像这样:

                  You can reuse existing POINT structure definition directly, like this:

                  import comtypes
                  from comtypes import *
                  from comtypes.client import *
                  
                  comtypes.client.GetModule('UIAutomationCore.dll')
                  from comtypes.gen.UIAutomationClient import *
                  
                  # get IUIAutomation interface
                  uia = CreateObject(CUIAutomation._reg_clsid_, interface=IUIAutomation)
                  
                  # import tagPOINT from wintypes
                  from ctypes.wintypes import tagPOINT
                  point = tagPOINT(10, 10)
                  element = uia.ElementFromPoint(point)
                  
                  rc = element.currentBoundingRectangle # of type ctypes.wintypes.RECT
                  print("Element bounds left:", rc.left, "right:", rc.right, "top:", rc.top, "bottom:", rc.bottom)
                  

                  要确定 ElementFromPoint 的预期类型是什么,您只需转到 python 设置目录(对我来说它是 C:Users<user>AppDataLocalProgramsPythonPython36Libsite-packagescomtypesgen) 并检查其中的文件.它应该包含由 comtypes 自动生成的文件,包括 UIAutomationCore.dll 的文件.有趣的文件名以 _944DE083_8FB8_45CF_BCB7_C477ACB2F897(COM 类型库的 GUID)开头.

                  To determine what's the expected type for ElementFromPoint, you can just go to your python setup directory (for me it was C:Users<user>AppDataLocalProgramsPythonPython36Libsite-packagescomtypesgen) and check the files in there. It should contains files automatically generated by comtypes, including the one for UIAutomationCore.dll. The interesting file name starts with _944DE083_8FB8_45CF_BCB7_C477ACB2F897 (the COM type lib's GUID).

                  该文件包含以下内容:

                  COMMETHOD([], HRESULT, 'ElementFromPoint',
                            ( ['in'], tagPOINT, 'pt' ),
                  

                  这告诉你它需要一个 tagPOINT 类型.这种类型被定义为文件的开头,如下所示:

                  This tells you that it expects a tagPOINT type. And this type is defined a the beginning of the file like this:

                  from ctypes.wintypes import tagPOINT
                  

                  之所以命名为 tagPOINT,是因为它在原始 Windows 中是这样定义的标题.

                  It's named tagPOINT because that's how it's defined in original Windows header.

                  这篇关于如何将 POINT 结构传递给 Python 中的 ElementFromPoint 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Python 和 Excel:覆盖现有文件总是提示,尽管 XlSa 下一篇:无法使用 PyQt4 将参数传递给 ActiveX COM 对象

                  相关文章

                  最新文章

                  • <bdo id='tegWe'></bdo><ul id='tegWe'></ul>
                  <tfoot id='tegWe'></tfoot>
                1. <small id='tegWe'></small><noframes id='tegWe'>

                      <legend id='tegWe'><style id='tegWe'><dir id='tegWe'><q id='tegWe'></q></dir></style></legend>

                    1. <i id='tegWe'><tr id='tegWe'><dt id='tegWe'><q id='tegWe'><span id='tegWe'><b id='tegWe'><form id='tegWe'><ins id='tegWe'></ins><ul id='tegWe'></ul><sub id='tegWe'></sub></form><legend id='tegWe'></legend><bdo id='tegWe'><pre id='tegWe'><center id='tegWe'></center></pre></bdo></b><th id='tegWe'></th></span></q></dt></tr></i><div id='tegWe'><tfoot id='tegWe'></tfoot><dl id='tegWe'><fieldset id='tegWe'></fieldset></dl></div>