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

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

问题描述

有没有办法在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)

推荐答案

Nish


对话框保持在顶部



你没有看到有
的程序是永远在上的选项吗?那么
令人难以置信的事情就是你可以
让你的对话保持在顶部,只需
一行代码。只需将
以下行放在对话框类的
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顺序。我们
使我们的对话框保持在所有
其他窗口的顶部,将其移动到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.

-Adam

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

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