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

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

问题描述

有没有办法在C ++ MFC中创建一个无模式的对话框,它始终保持在应用程序的其他窗口的顶部?我想像在Visual Studio 2005中的查找对话框 - 它在顶部,但你仍然可以编辑底层文本。

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.

(如果它做任何差异,它不是MDI;它是一个基于对话框的应用程序)

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

推荐答案

西方


使您的对话框保持在顶部



有没有看到有
的程序是一个总是停留在顶部选项?好了
令人难以置信的事情是,你可以
使你的对话框保持在顶部与
一行代码。只需将
下面一行放到对话框类的
OnInitDialog()函数中即可。

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);

基本上我们所做的是使用
SetWindowPos函数来更改
我们的对话窗口的Z顺序。 We
使我们的对话框保持在所有
其他窗口的顶部,移动到顶级
的Z顺序。现在,即使你
激活一些其他窗口,我们的窗口
将保持在顶部。但我建议你
,以确保你知道你的
正在做什么,当你这样做,因为它
可能会烦人,如果他们不能得到
你的窗口当他们
想要这样做时。

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天全站免登陆