始终在前的对话框 [英] Always-in-front dialogs

查看:11
本文介绍了始终在前的对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 C++ MFC 中创建一个 modeless 对话框,该对话框始终位于应用程序中其他窗口的顶部?我的想法有点像 Visual Studio 2005 中的查找"对话框 - 它位于顶部,但您仍然可以编辑基础文本.

(如果有什么不同,那就不是 MDI;它是一个基于对话框的应用程序)

解决方案

注意:这在 Windows 10 下不起作用,在 Windows 7 和 8 下可能不起作用(报告各不相同).p>

来自 Nish:

<块引用>

###让你的对话框保持在顶部

你没看过有始终保持领先"选项?好令人难以置信的是,你可以让你的对话保持在最前面一行代码.简单地说对话类中的以下行OnInitDialog() 函数.

SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

基本上我们正在做的是使用要更改的 SetWindowPos 函数我们对话窗口的 Z 顺序.我们让我们的对话始终处于首位将其他窗口移到顶部Z 顺序.现在即使你激活另一个窗口,我们的窗口将保持在顶部.但我会建议你确保你确切地知道你的当你这样做的时候正在做,因为它如果他们不能得到,可能会惹恼人们当他们挡住你的窗户时想这样做.

正如您在评论中提到的,上面的行使窗口位于每个应用程序的顶部.你需要这样做

SetWindowPos(&this->wndTop,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

使窗口仅位于您的应用程序之上.

Is there a way to create a modeless dialog box in C++ MFC which always stays on top of the other windows in the application? I'm thinking sort of like the Find dialog in Visual Studio 2005 - where it stays on top, but you can still edit the underlying text.

(If it makes any difference, it's not MDI; it's a dialog-based app)

解决方案

Note: This does not work under Windows 10, and may not work under Windows 7 and 8 (Reports vary).

From Nish:

###Making your dialog stay on top

Haven't you seen programs which have an "always-stay-on-top" option? Well the unbelievable thing is that you can make your dialog stay on top with just one line of code. Simply put the following line in your dialog class's OnInitDialog() function.

SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

Basically what we are doing is to use the SetWindowPos function to change the Z-order of our dialog window. We make our dialog stay on top of all other windows by moving it to the top of the Z-order. Now even when you activate some other window, our window will stay on top. But I'd advise you to make sure you know exactly what you are doing when you do this, for it might annoy people if they can't get your window out of the way when they want to do that.

As you mentioned in the comments, the above line makes the window sit on top of every application. You'll need to do

SetWindowPos(&this->wndTop,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

To make a window sit on top of only your application.

这篇关于始终在前的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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