始终位于最前面的对话框

发布于 2024-07-14 15:42:16 字数 171 浏览 6 评论 0原文

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

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

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温折酒 2024-07-21 15:42:16

注意:这不适用于 Windows 10,并且可能不适用于 Windows 7 和 8(报告有所不同)。

来自 完成

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

你没见过有这样的程序吗?
“始终保持领先”选项? 出色地
令人难以置信的是你可以
让你的对话框保持在最上面
一行代码。 简单地说
对话框类中的以下行
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);

“使窗口仅位于您的应用程序之上”的操作。

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.

挽清梦 2024-07-21 15:42:16

对于 Windows 7 或更高版本,接受的答案失败。 (或者也许是我)
但是将非模式对话框设置为弹出窗口而不是子对话框可以解决这个问题。
它现在定位在主对话框窗口中,但您可以编写代码来约束任何地方。
使用无边框或顶部栏使其成为一个简单的窗口。

The accepted answer fails for Windows 7 or above. (Or perhaps its me)
But making the modeless dialog as popup instead of child solves it.
It now gets positioned wrt main dialog window but you can write code to constrain anywhere.
Using the no border or top bar makes it a simple window.

不弃不离 2024-07-21 15:42:16

它在 Microsoft Windows 版本 10.0.18362.476 中对我有用。 必须将 SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); 放在 OnInitDialog 中,并将对话框设置为 >弹出窗口

It worked for me in Microsoft Windows Version 10.0.18362.476. Had to put SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); in OnInitDialog and make the dialog as a PopUp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文