C++/(MFC)On Sizing 윈도우 리사이징 컨트롤 크기 조정

  1. // header
  2. RECT prevClientRect;
  3. BOOL m_bSizing;
  4. // Constructor
  5. m_bSizing = FALSE;
  6. ZeroMemory(&prevClientRect, sizeof RECT);
  7. // OnInitDialog
  8. ...
  9. GetWindowRect(&prevClientRect);
  10. ScreenToClient(&prevClientRect);
  11. m_bSizing = TRUE;
  12. ...
  13. // 
  14. void CLogDialog::DockChildControl(RECT rect)
  15. {
  16.     ScreenToClient(&rect);
  17.     int diffBottom = rect.bottom - prevClientRect.bottom;
  18.     int diffTop = rect.top - prevClientRect.top;
  19.     int diffLeft = rect.left - prevClientRect.left;
  20.     int diffRight = rect.right - prevClientRect.right;
  21.     CRect childWndRect;
  22.     // IDOK
  23.     GetDlgItem(IDOK)->GetWindowRect(&childWndRect);
  24.     ScreenToClient(&childWndRect);
  25.     childWndRect.bottom += diffBottom;
  26.     childWndRect.top += diffBottom;
  27.     childWndRect.left += diffRight;
  28.     childWndRect.right += diffRight;
  29.     GetDlgItem(IDOK)->MoveWindow(childWndRect.left, childWndRect.top, childWndRect.Width(), childWndRect.Height());
  30.     GetDlgItem(IDOK)->RedrawWindow();
  31.     // Log List
  32.     m_listLog.GetWindowRect(&childWndRect);
  33.     ScreenToClient(&childWndRect);
  34.     childWndRect.bottom += diffBottom;
  35.     childWndRect.top += diffTop;
  36.     childWndRect.left += diffLeft;
  37.     childWndRect.right += diffRight;
  38.     m_listLog.MoveWindow(childWndRect.left, childWndRect.top, childWndRect.Width(), childWndRect.Height());
  39.     m_listLog.RedrawWindow();
  40.     // Line
  41.     GetDlgItem(IDC_STATIC_LINE)->GetWindowRect(&childWndRect);
  42.     ScreenToClient(&childWndRect);
  43.     childWndRect.bottom += diffBottom;
  44.     childWndRect.top += diffBottom;
  45.     childWndRect.left += diffLeft;
  46.     childWndRect.right += diffRight;
  47.     GetDlgItem(IDC_STATIC_LINE)->MoveWindow(childWndRect.left, childWndRect.top, childWndRect.Width(), childWndRect.Height());
  48.     GetDlgItem(IDC_STATIC_LINE)->RedrawWindow();
  49.     prevClientRect = rect;
  50. }
  51. void CLogDialog::OnSize(UINT nType, int cx, int cy)
  52. {
  53.     CDialogEx::OnSize(nType, cx, cy);
  54.     if (m_bSizing)
  55.     {
  56.         RECT rect;
  57.         GetWindowRect(&rect);
  58.         DockChildControl(rect);
  59.     }
  60. }

이 글에는 0 개의 댓글이 있습니다.