gpt4 book ai didi

python ctypes messagebox出现在所有程序下

转载 作者:行者123 更新时间:2023-11-28 16:43:35 33 4
gpt4 key购买 nike

我是 Python 新手,我需要一个消息框。我使用了 ctypes 但它会在所有其他程序下打开消息框。我怎样才能让它高于所有程序??

import ctypes
def run(x=0):
STOP = False
x += 5
MessageBox = ctypes.windll.user32.MessageBoxA
reply = MessageBox(None, 'text', 'title', 1)
if reply == 1 and not STOP:
threading.Timer(3, run).start()
else:
STOP = True;

最佳答案

您正在为 MessageBoxhWnd 参数传递 NULL。来自documentation :

A handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.

因此,消息框没有所有者窗口。这意味着它很可能出现在其他窗口后面。理想情况下,您应该在应用程序中传递适当所有者窗口的窗口句柄。拥有的窗口总是出现在它们的所有者之上。这绝对是控制哪些窗口显示在其他窗口之上的最正常方式。

但是,我怀疑您可能很难想出这样一个窗口句柄。在这种情况下,您可能会发现在 uType 参数(参数编号 4)中包含 MB_TOPMOST 标志可以满足您的需要。

不过,很难确定您的确切需求是什么,因为您所要求的显然无法实现。你问那个窗口

be above all programs

嗯,这显然是不可能的,这可以通过证明矛盾来证明。假设您的窗口显示在所有其他窗口之上。如果您的 window 可以做到这一点,那么另一个 window 也可以。显然,您不能让两个不同的窗口显示在所有其他窗口之上。

关于python ctypes messagebox出现在所有程序下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16237719/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com