SetWindowPos() 函数不移动窗口? [英] SetWindowPos() function not moving window?

查看:30
本文介绍了SetWindowPos() 函数不移动窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话框,我想将它放在另一个对话框中,并相对于主对话框上的一个控件进行定位.

I have a dialog that I want to place within another dialog and position relative to one of the controls on the main dialog.

void CspAceDlg::DrawResultsArea()
{
    CWnd* pTabCtl = GetDlgItem(IDC_BUILDTABS);
    CRect rectTabCtl; // Allocate CRect for control's position.
    pTabCtl->GetWindowRect(&rectTabCtl);
    int resX = rectTabCtl.right + 15;
    int resY = rectTabCtl.top;
    //RESULTS AREA
    results.Create(IDD_RESULTSDIALOG, this);
    results.SetWindowPos(this, resX, resY, /*608, 19, */175, 135, SWP_SHOWWINDOW);
    results.ShowWindow(SW_SHOW);
}

我的问题是我的对话框资源 (IDD_REULTSDIALOG) 具有称为 X Pos 和 Y Pos 的属性,它们似乎覆盖了我的 SetWindowPos()(资源编辑器中的小属性选项卡不会让我将这些留空).如果我将这些属性设置为 0, 0 我的对话框将出现在主对话框的左上角.如果我将它们设置为一个数字,我可以猜测并测试将其大致放置在我想要的位置,但是以不同的分辨率运行应用程序会导致对话框出现在不同的位置.无论如何,我真正想做的是将对话框相对于我的主对话框上的另一个控件(在本例中为我的选项卡控件)放置.为什么我的 SetWindowPos() 被忽略,我该如何解决?我应该使用不同的功能吗?

My problem is that my dialog resource (IDD_REULTSDIALOG) has properties called X Pos and Y Pos that seem to be overriding my SetWindowPos() (and the little property tab in the resource editor won't let me leave these blank). If I set these properties to 0, 0 my dialog appears in the top left corner of the main dialog. If I set them to a number I can guess-and-test place it roughly where I want, but then running the application on different resolutions causes the dialog to appear in different spots. What I really want to do anyway is place the dialog relative to another control on my main dialog (in this case my tab control). Why is my SetWindowPos() being ignored, and how do I fix this? Should I be using a different function?

推荐答案

根据 SetWindowPos,如果传入SWP_SHOWWINDOW,窗口不会移动:

According to the documentation for SetWindowPos, if you pass in SWP_SHOWWINDOW, the window will not be moved:

如果设置了 SWP_SHOWWINDOW 或 SWP_HIDEWINDOW 标志,则无法移动窗口或调整窗口大小.

If the SWP_SHOWWINDOW or SWP_HIDEWINDOW flag is set, the window cannot be moved or sized.

这篇关于SetWindowPos() 函数不移动窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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