Python如何使MessageboxW保持在所有其他窗口之上? [英] Python How to keep MessageboxW on top of all other windows?

查看:218
本文介绍了Python如何使MessageboxW保持在所有其他窗口之上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:

我有一个小的脚本,它通过使用Windows内置消息框创建消息框来提醒用户事件(参考:

I have a small script that alerts the user of an event by creating a message box using the Windows in built message box (Ref: MSDN MessageBox) which is imported using ctypes. This script is for Windows OS.

问题:

当前,消息框将显示在所有其他窗口的顶部,但是由于它是一个很小的窗口,因此用户可以轻松地单击另一个可以隐藏该消息框的窗口.

Currently, the message box will appear on top of all other windows, but because it's such a small window, a user can easily click onto another window which could hide the message box.

我想要的

我想使消息框始终位于其他窗口的顶部.如果无法做到这一点,那么是否有办法增加消息框的尺寸?

I want to keep the message box always on top of other windows. If this can't be done, then alternatively is there a way to increase the dimensions of the message box?

示例代码:

import ctypes

ctypes.windll.user32.MessageBoxW(0, text, title, 0x00010000)

推荐答案

import ctypes

text = 'Using MB_SYSTEMMODAL'
title = 'Some Title'

ctypes.windll.user32.MessageBoxW(0, text, title, 0x1000)

MB_SYSTEMMODAL(0x1000)具有WS_EX_TOPMOST(0x40000)样式.

MB_SYSTEMMODAL (0x1000) has the WS_EX_TOPMOST (0x40000) style.

MessageBoxEx函数似乎可以很好地使用 WS_EX_TOPMOST(0x40000)样式.

The MessageBoxEx function seems to work good with using just the WS_EX_TOPMOST (0x40000) style.

import ctypes

text = 'Using WS_EX_TOPMOST'
title = 'Some Title'

ctypes.windll.user32.MessageBoxExW(0, text, title, 0x40000)

MessageBox函数没有用于更改大小的参数.可能 像tkinter或其他gui工具包这样的替代品可能能够 更改消息框的大小(尽管如果只是包装,则可能不会) (适用于MessageBoxW),也可以创建一个自定义窗口来使用.

The MessageBox function has no parameters to change size. Perhaps an alternative like tkinter or another gui toolkit might be able to change messagebox size (though it maybe not if it just a wrapper for MessageBoxW) or you could perhaps create a custom window to use.

请参见 MSDN MessageBox函数获取要使用的值.

See MSDN MessageBox function for values to use.

另请参见 MSDN MessageBoxEx功能.

这篇关于Python如何使MessageboxW保持在所有其他窗口之上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆