요즘 만들고 있는 프로그램 기능 중에 master 윈도우를 움직일 때 slave 윈도우를 같이 움직여야 하는 기능이 있다.
이것을 구현하기 위해서는
step 1.
CFrameWnd를 상속받아 클래스를 만든다.
ex: class CZFrame : public CFrameWnd step 2.
CFrameWnd를 상속받아 만든 클래스의 메세지 중 윈도우의 위치가 바뀔 때마다 발생하는 메세지인 WM_WINDOWPOSCHANGING 을 처리하는 함수를 정의한다.
step 3.
step2에서 정의한 OnWindowPosChanging 함수에 현재 윈도우의 위치가 바뀔 때마다 parent 윈도우에 윈도우의 위치가 바뀌었다는 것을 알리기 위해 SendNotifyMessage를 보내는 코드를 작성한다.
void CZFrame::OnWindowPosChanging(WINDOWPOS* lpwndpos) { CFrameWnd::OnWindowPosChanging(lpwndpos);
CWnd* pParent = this->GetParent(); pParent->SendNotifyMessage( WM_NOTIFY, this->GetDlgCtrlID(), (LPARAM)lpwndpos ); }
step 4.
parent 윈도우의 view의 OnNotify 함수에서 master윈도우의 위치가 바뀔 때마다 slave 윈도우를 움직이는 코드를 작성한다.
BOOL CLineMoveTestView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { // TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다. WINDOWPOS* wndPos1; // master window의 위치
if( wParam == 100 ) // master window의 ID { wndPos1 = (WINDOWPOS*)lParam; // TRACE("Frame1 Position Change, (%3d,%3d) \r\n", wndPos->x, wndPos->y );
//---------slave window 이동------------------------// CRect rect; rect.left = wndPos1->x; rect.right = wndPos1->x +wndPos1->cx; rect.bottom = wndPos1->y+wndPos1->cy+100; //100은 slave와 master윈도우의 크기 rect.top = wndPos1->y+100;
pFrame2->MoveWindow(rect,TRUE); // slave window 이동 //------------------------------------------
this->Invalidate(); } }
|