对话框、内部控件位置

14 篇文章 0 订阅

一、了解下几个函数

1、movewindow

了解下:MoveWindow

自己塞进去的是屏幕坐标

 CrvtFaultRodDlg* dlg = new CrvtFaultRodDlg();
  if (dlg != NULL)
  {
    BOOL ret = dlg->Create(IDD_DlgCrvtFaultRod, NULL);
    if (ret) //Create failed.
    {
      RECT rect;
      {
        RECT rect1;
        dlg->GetWindowRect(&rect1);//获取窗口高宽
        int px = GetSystemMetrics(SM_CXFULLSCREEN);//获取屏幕高宽
        int py = GetSystemMetrics(SM_CYFULLSCREEN);
        int wx = rect1.right - rect1.left;
        int wy = rect1.bottom - rect1.top;
        rect.left = (px - wx) / 2;
        rect.top = (py - wy) / 2;
        rect.bottom = rect.top + wy;
        rect.right = rect.left + wx;
      }
      dlg->MoveWindow(&rect);
      dlg->ShowWindow(SW_SHOW);
    }
  }

2、GetWindowRect

了解下 GetWindowRect ​​​​​​

        获取 CWnd 的屏幕坐标

3、GetClientRect

了解下 GetClientRect

        获取 CWnd 工作区的尺寸。

4、ClientToScreen

了解下 ClientToScreen

        函数将指定点的工作区坐标转换为屏幕坐标

5、ScreenToClient 

了解下 ScreenToClient 

        函数将屏幕上指定点的屏幕坐标转换为工作区坐标。

二、使用示例

1、对话框内使用(GetClientRect

 RECT rect;
 GetWindowRect(&rect);

主窗口全屏,此时 rect 左,上,0,0 ;

主窗口不全屏,此时 rect 左,上,非0,非0 ;

        因此上述用法不合理,需要将屏幕坐标统一转到工作区。使用ScreenToClient 。

  RECT rect;
  GetWindowRect(&rect);
  ScreenToClient2(rect);
  bool BRe = mTab.Create( TCS_FIXEDWIDTH | WS_CHILD | WS_VISIBLE, // TCS_TABS 边框绘制
    rect, this, IDC_TABRod);
  if (!BRe)   return;

2、GetTitleBarInfo

void  ScreenToClient2(RECT& rect)
{
  ScreenToClient(&rect);
  TITLEBARINFO  re;
  re.cbSize = sizeof(TITLEBARINFO);
  if (GetTitleBarInfo(&re))
  {
    RECT& rcTitleBar = re.rcTitleBar;
    ScreenToClient(&rcTitleBar);
    rect.top = rect.top + abs(rcTitleBar.top) + 5;
    rect.bottom = rect.bottom + abs(rcTitleBar.bottom) + 5;
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ma_Hong_Kai

微信 2936729162

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值