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

查看:587
本文介绍了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,则我的对话框将出现在主对话框的左上角.如果将它们设置为一个数字,我可以将其粗略地猜测并测试一下,然后以不同的分辨率运行该应用程序,则该对话框将出现在不同的位置.无论如何,我真正想做的是将对话框相对于另一个控件放置在主对话框中(在本例中为选项卡控件).为什么我的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?

推荐答案

根据

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