Kot*_*sif 6 python windows ctypes messagebox python-3.x
语境:
我有一个小脚本,通过使用 Windows 内置消息框(参考:MSDN MessageBox)创建一个消息框来提醒用户事件,该消息框是使用ctypes. 此脚本适用于 Windows 操作系统。
问题:
目前,消息框将出现在所有其他窗口的顶部,但由于它是一个很小的窗口,用户可以轻松地单击另一个可以隐藏消息框的窗口。
我想要的是
我想让消息框始终位于其他窗口的顶部。如果这不能做到,那么有没有办法增加消息框的尺寸?
示例代码:
import ctypes
ctypes.windll.user32.MessageBoxW(0, text, title, 0x00010000)
Run Code Online (Sandbox Code Playgroud)
import ctypes
text = 'Using MB_SYSTEMMODAL'
title = 'Some Title'
ctypes.windll.user32.MessageBoxW(0, text, title, 0x1000)
Run Code Online (Sandbox Code Playgroud)
MB_SYSTEMMODAL(0x1000) 具有WS_EX_TOPMOST(0x40000) 样式。
该MessageBoxEx函数似乎仅使用WS_EX_TOPMOST(0x40000) 样式就可以很好地工作。
import ctypes
text = 'Using WS_EX_TOPMOST'
title = 'Some Title'
ctypes.windll.user32.MessageBoxExW(0, text, title, 0x40000)
Run Code Online (Sandbox Code Playgroud)
MessageBox 函数没有用于更改大小的参数。也许像 tkinter 或其他 gui 工具包这样的替代方案可能能够更改消息框大小(尽管如果它只是 MessageBoxW 的包装器,则可能不会),或者您可以创建一个自定义窗口来使用。
有关要使用的值,请参阅MSDN MessageBox 函数。
另请参阅MSDN MessageBoxEx 函数。