让 Win32 MessageBox 出现在其他程序之上 [英] Have Win32 MessageBox appear over other programs

查看:34
本文介绍了让 Win32 MessageBox 出现在其他程序之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始学习 Python 并编写了一个小脚本,当某个网站更改内容时会通知我.然后我将它作为计划任务添加到 Windows,以便它可以每 10 分钟运行一次.我想立即收到有关网站更改的通知,因此我添加了一个 win32ui MessageBox,如果脚本检测到网站已更改,则会弹出该消息框.这是我用于 MessageBox 的小代码片段(我知道是富有想象力的文本):

win32ui.MessageBox("网站已更改.", "网站更改", 0)

我的问题是,我大部分时间都在使用远程桌面,所以当 MessageBox 弹出时,它位于远程桌面会话的后面,有什么方法可以强制 MessageBox 出现在它上面吗?

在类似的说明中,当脚本运行时,命令行在我不想要的远程桌面会话上非常短暂地打开,有什么办法可以阻止这种行为?

我对 Windows 特定的解决方案感到满意,因为我知道这可能意味着处理窗口管理器或可能是一种通知我而不是使用 MessageBox 的替代方法.

解决方案

当您从 Task Scheduler 启动任何内容时,Windows 会阻止任何简单"方式将您的窗口或对话框置于顶部.

>

  1. 第一种方法 - 使用 MB_SYSTEMMODAL(4096 值)标志.根据我的经验,它使 Msg 对话框始终在最前面".

    win32ui.MessageBox("网站已更改.", "网站更改", MB_SYSTEMMODAL)

  2. 第二种方式 - 尝试通过以下调用将您的控制台/窗口/对话框置于最前面.当然,如果你使用 MessageBox 你必须在调用 MessageBox 之前这样做(对于你自己创建的窗口).

    SetForegroundWindow(Wnd);带上窗口到顶部(Wnd);SetForegroundWindow(Wnd);

对于控制台窗口的闪烁,您可以尝试在隐藏状态下启动Python.例如,使用 ConEmu、'HidCon' 或 cmdow.参考他们的参数,比如:

ConEmu -basic -MinTSA -cmd C:\Python27\python.exe C:\pythonScript.py或者CMDOW/RUN/MIN C:\Python27\python.exe C:\pythonScript.py

I've recently started learning Python and wrote a little script that informs me when a certain website changes content. I then added it as a scheduled task to Windows so it can run every 10 minutes. I'd like to be informed of the website changing right away so I added a win32ui MessageBox that pops up if the script detects that the website has changed. Here's the little code snippet I'm using for the MessageBox (imaginative text, I know):

win32ui.MessageBox("The website has changed.", "Website Change", 0)

My issue is this, I spend most of my time using remote desktop so when the MessageBox does pop up it sits behind the remote desktop session, is there any way to force the MessageBox to appear on top of it?

On a similar note when the script runs the command line opens up very briefly over the remote desktop session which I don't want, is there any way of stopping this behaviour?

I'm happy with Windows specific solutions as I'm aware it might mean dealing with the windowing manager or possibly an alternative way to inform me rather than using a MessageBox.

解决方案

When you start anything from Task Scheduler, Windows blocks any "easy" ways to bring your windows or dialogs to top.

  1. First way - use MB_SYSTEMMODAL (4096 value) flag. In my experience, it makes Msg dialog "Always on top".

    win32ui.MessageBox("The website has changed.", "Website Change", MB_SYSTEMMODAL)
    

  2. Second way - try to bring your console/window/dialog to the front with Following calls. Of course, if you use MessageBox you must do that (for your own created window) before calling MessageBox.

    SetForegroundWindow(Wnd);
    BringWindowToTop(Wnd);
    SetForegroundWindow(Wnd);
    

As for flickering of the console window, you may try to start Python in a hidden state. For example, use ConEmu, ‘HidCon’ or cmdow. Refer to their parameters, something like:

ConEmu -basic -MinTSA -cmd C:\Python27\python.exe C:\pythonScript.py
    or
CMDOW /RUN /MIN C:\Python27\python.exe C:\pythonScript.py

这篇关于让 Win32 MessageBox 出现在其他程序之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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