PyHANDLE在win32中的包含模块是什么?

huangapple go评论73阅读模式
英文:

What is the containing module of PyHANDLE in win32?

问题

我一直在使用Python标准库中的win32部分,然后我遇到了PyHANDLE对象,但是我找不到用于注释目的的模块。有人知道它的模块吗?提前感谢。

英文:

I've been working with win32 in Python standard library when I came across PyHANDLE objects but I couldn't to find its module for annotation purposes. Does anyone know its module?
Thanks in advance.

答案1

得分: 0

根据pywin32文档PyHANDLEpywintypes.HANDLE类型的对象。

> PyHANDLE对象
一个Python对象,表示一个win32 HANDLE。

> 评论
这个对象包装了一个win32 HANDLE对象,在对象销毁时会自动关闭它。为了保证清理,您可以调用PyHANDLE::Close或win32api::CloseHandle。大多数接受句柄对象的函数也接受整数 - 但是,鼓励使用句柄对象。

以下帖子引用了上述文档。

以下文档页面显示了如何创建PyHANDLE对象(但遗漏了导入语句)。


创建PyHANDLE对象的示例(包括导入语句):

import pywintypes

PyHANDLE = pywintypes.HANDLE()

似乎PyHANDLE是一个表示pywintypes.HANDLE()类型对象的命名约定。

我想真正的用例是包装作为整数返回的Windows句柄。

示例:

import pywintypes
import win32gui
import cv2
import numpy as np

cv2.imshow('window', np.zeros((100, 100), np.uint8))

hwnd = win32gui.FindWindow(None, "window")  # 以整数形式返回句柄

PyHANDLE = pywintypes.HANDLE(hwnd)  # 使用HANDLE对象包装整数
英文:

According to the documentation of pywin32, PyHANDLE is and object of type pywintypes.HANDLE.

>PyHANDLE Object
A Python object, representing a win32 HANDLE.

>Comments
This object wraps a win32 HANDLE object, automatically closing it when the object
is destroyed. To guarantee cleanup, you can call either PyHANDLE::Close, or
win32api::CloseHandle.
Most functions which accept a handle object also accept an integer - however,
use of the handle object is encouraged.

The following post quatutes the above documentation.

The following documentation page shows how to create the PyHANDLE object (but misses the import statement).


Example for creating PyHANDLE object (including the import statement):

import pywintypes

PyHANDLE = pywintypes.HANDLE()

It seems that PyHANDLE is a naming convention for an object of type pywintypes.HANDLE().

I suppose the true use case is for wrapping an Windows handle that returned as an integer.

Example:

import pywintypes
import win32gui
import cv2
import numpy as np

cv2.imshow('window', np.zeros((100, 100), np.uint8))

hwnd = win32gui.FindWindow(None, "window")  # Return handle as an integer

PyHANDLE = pywintypes.HANDLE(hwnd)  # Wrap the integer with HANDLE object

huangapple
  • 本文由 发表于 2023年6月12日 21:46:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457304.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定