ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • SDI에서의 스크롤뷰 구현
    MFC 2010. 5. 24. 14:39


    프로젝트 진행 중 스크롤뷰 형태로 바꿔야 할 경우가 생겼다.
    그럼 바꿔보자.

    1.  CTestView.h 파일의 상속을 변경한다

    class CTestView : public CView   =>   class CTestView : public CScrollView


    2.  CTestView.cpp 파일의 OnInitialUpdate() 함수에서 아래 내용을 추가한다.

    CRect rlClientRect;
    GetClientRect(&rlClientRect);

    CSize sizeTotal;
    sizeTotal.cx = 0;       // 스크롤로 확장하고 싶은 x축 사이즈
    sizeTotal.cy = 1200;   // 스크롤로 확장하고 싶은 y축 사이즈

    SetScrollSizes(MM_TEXT, sizeTotal);  // 스크롤바 설정


    3.  CTestView.cpp 파일의 OnPaint()함수에서 드로잉시 스크롤한 만큼의 좌표를 보정해줘야 한다.

    CPoint scrollpos = GetScrollPosition();
    dc.BitBlt(-scrollpos.x,-scrollpos.y,rlClientRect.right,1200,&MemDC, 0, 0, SRCCOPY);


    4.  각종 좌표를 입력 받는 메세지 함수(예를 들어 LBUTTON_DOWN 등)에서 입력 좌표를 보정해 준다.

    void CTestView::OnLButtonDown(UINT nFlags, CPoint point)
    {

             CPoint scrollpos = GetScrollPosition();
             point = point + scrollpos;

              ......

             CView::OnMouseMove(nFlags, point);
    }

    생각했던 것 만큼 어렵지 않은 듯....

Designed by Tistory.