【问题标题】:How to minimize window using Ctypes in python如何在python中使用Ctypes最小化窗口
【发布时间】:2020-11-29 18:05:55
【问题描述】:

为了最大化我们可以这样做

查询中的 elif '最大化':

 speak('Ok sir!')

 user32 = ctypes.WinDLL('user32')

 SW_MAXIMISE = 3

 hWnd = user32.GetForegroundWindow()

 user32.ShowWindow(hWnd, SW_MAXIMISE)

 speak('done sir!')

【问题讨论】:

  • 为了提供帮助,请给出一个可以运行的最小示例
  • 什么?您需要我们为您查找 SW_MINIMIZE 的值吗?
  • 第一件事第一件事:你确定你输入的所有内容都正确吗?真的是SW_MAXIMISE吗?异常(错误)说明了什么?

标签: python module ctypes minimize maximize


【解决方案1】:

确保设置.argtypes.restypeHWND 被定义为一个指针,如果不指定,64 位系统将不会正确传递或返回参数,因为 ctypes 假定 int(32 位)。

import ctypes
from ctypes import wintypes as w

user32 = ctypes.WinDLL('user32')
user32.GetForegroundWindow.argtypes = ()
user32.GetForegroundWindow.restype = w.HWND
user32.ShowWindow.argtypes = w.HWND,w.BOOL
user32.ShowWindow.restype = w.BOOL

# From https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
SW_MAXIMIZE = 3
SW_MINIMIZE = 6

hWnd = user32.GetForegroundWindow()
user32.ShowWindow(hWnd, SW_MINIMIZE)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 2021-03-18
    • 2011-02-17
    相关资源
    最近更新 更多