如何将我的窗口投影为前台的活动窗口
打开了一些窗口,并且从我的流程中,我想再启动一个窗口(高优先级),用户必须在其中输入凭据。我想将此凭据窗口置于前台,反过来,它可能会给用户带来良好的体验,因为他不需要手动选择凭据窗口。而且这是一次性启动,绝对不烦人,但强制用户输入凭据。
实现这一目标的最佳方法是什么?我不认为模拟鼠标点击是个好主意。有没有办法将消息发送到其余窗口以失去焦点?这样当我启动窗口时,它就会出现在前台。
There were some windows opened, And from my process I want to launch one more window(high priority) in which user has to enter credentials. And i want to put this credentials window to foreground, in turn it might give good experience to user as he need not manually select the credentials window. And this is one time launching, definitely not annoying but compulsory for user to enter creds.
what is the best way to achieve this? I don't think simulating mouse click is good idea. Is there a way to send msg to rest of windows to lose their focus? so that when i launch my window, it will come foreground.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这对我有用,无需使用
SetWindowPos
使窗口“始终位于顶部”:我在聊天应用程序中使用它,这样新的聊天消息就可以窃取焦点(显然是可选的,因为有些用户不这样做像这样。)
This works for me without having to use
SetWindowPos
to make the window 'always on top':I use this in a chat application so a new chat message can steal focus (optional obviously as some users don't like this.)
您需要使用 SetWindowPos 调用 < code>wndTopMost 参数将您的窗口设置在所有其他窗口的顶部。
You need to call SetWindowPos with
wndTopMost
parameter to set your window at the top of all other windows.此 UI 模式(输入强制值的窗口)通常称为模式对话框。在 MFC 中,您需要查找
CDialog::DoModal
。即,您从CDialog
派生凭据窗口,然后调用继承的DoModal
方法。模式对话框会阻止用户在应用程序的其他窗口中进行输入,因此会自动移动到被阻止的窗口之前。
This UI pattern (window to enter mandatory values) is commonly known as a modal dialog. In MFC, you'd look for
CDialog::DoModal
. I.e. you derive your credential window fromCDialog
, and then call the inheritedDoModal
method.A modal dialog blocks user input in other windows in your app, and therefore is automatically moved before the blocked windows.
用户期望程序仅在应有的时候进入前台。这种技术使程序能够违反该契约,窃取前景并破坏设计。在不考虑其他选项的情况下,请勿应用此选项。例如,使用相关窗口之间的所有者窗口关系,并在需要时使用AllowSetForegroundWindow() 传递成为前台的能力。
Users expect programs to only come to the foreground when they are supposed to. This technique enables programs to violate that contract, stealing foreground and subverting the design. Do not apply this without considering other options. For example using the owner window relationship between related windows and passing the ability to become foreground, when needed, using AllowSetForegroundWindow().