/**********************[다이알로그에다가 View 를 붙이자~~~~ ]***********************/


보통 작업할떄 다이알로그베이스로 많이 합니다. 간단하고 쉬어서 그럴껀데 그런데

이미지를 다룰려면 너무 복잡해집니다.. view처럼 아무곳에서ClientDC를 불러올수고 없고

그래서 요즘 제가 쓰는 방법이 다이알로그에 View를 붙이는 겁니다. 그럼면 정말 강력한 기능들을

쓸 수가 있습니다..

그럼 간략히 적어보면

우선 view클래스와 Document클래스 만듭니다..

다이알로그의 헤더에

 CFrameWnd m_Frame;
 CCreateContext pContex;
 CMyView *pView;<-뷰클래스
를 선언하고

다이알로그의 초기화 함수에서

  /* 뷰를 만드는 코드 */    
     CWnd* pFrameWnd = this;
     pContext.m_pCurrentDoc = new CMyDocument;<-도큐먼트클래스,
     pContext.m_pNewViewClass = RUNTIME_CLASS(CMyView);
     pView =(CMyView *) ((CFrameWnd*)pFrameWnd)->CreateView(&pContext);
     ASSERT(pView);
     pView->ShowWindow(SW_NORMAL);
                 pView->MoveWindows("원하는위치");
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
아참 그리고
뷰클래스의 헤더 부분을 요로게 하세요...
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class CMyDlg;<-붙일 다이알로그
class CMyView : public CView
{
 DECLARE_DYNCREATE(CMyView)
    friend class CMyDlg;<-선언
protected:
    CMyView();           // protected constructor used by dynamic creation
    virtual ~CMyView();
 
public:
    #ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif

protected:
    DECLARE_MESSAGE_MAP()
public:
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**************************************************************************************/



그냥 SDI 프로젝트에서 버튼을 누르면 뷰가 붙은 다이얼로그 창이 뜨게 만들었구요..


잘 동작하는거 같은데.. 다이얼로그에 붙은 뷰를 클릭하면 assertion failed이 남니다..


디버그를 해보면


int CView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message){

    int nResult = CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);

    if (nResult == MA_NOACTIVATE || nResult == MA_NOACTIVATEANDEAT)

        return nResult;   // frame does not want to activate


    CFrameWnd* pParentFrame = GetParentFrame();

    if (pParentFrame != NULL)

    {

        // eat it if this will cause activation

        ASSERT(pParentFrame == pDesktopWnd || pDesktopWnd->IsChild(pParentFrame)); --> 이부분에서 에러가.. 납니다.


        // either re-activate the current view, or set this view to be active

        CView* pView = pParentFrame->GetActiveView();

        HWND hWndFocus = ::GetFocus();

        if (pView == this &&

            m_hWnd != hWndFocus && !::IsChild(m_hWnd, hWndFocus))

        {

            // re-activate this view

            OnActivateView(TRUE, this, this);

        }

        else

        {

            // activate this view

            pParentFrame->SetActiveView(this);

        }

    }

    return nResult;

}


혹시 무슨문제인줄 아시면 좀 가르쳐주세요.. ^^;; 죄송합니다..
====================================================================================
답변
====================================================================================

이름은 생각이 안나나.. 질문답변에 올라와있는 글을 보고 해결하였습니다.


답을 올려주신분이 WM_MOUSEACTIVATE를 추가하라고 하셨는데..


class wizard에 WM_MOUSEACTIVATE라는 메세지가 없드라구요..


그래서 MyView.cpp에


BEGIN_MESSAGE_MAP(CMyView, CView)

    //{{AFX_MSG_MAP(CMyView)

    ON_WM_MOUSEACTIVATE()

    //}}AFX_MSG_MAP

END_MESSAGE_MAP()



int CMyView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)

{

    // TODO: Add your message handler code here and/or call default

   

//    return CView::OnMouseActivate(pDesktopWnd, nHitTest, message);

    return MA_ACTIVATE;

}



추가하고..


MyView.h에


afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);


를 추가했더니..!! 해결이 되었습니다.. ^^

출처 : 데브피아
6시간 동안 헤메서 겨우 해결책을 찾았음.
일반 다이얼로그 기반에서는 쉽게 되는데 SDI 기반에서는 함수를 추가해줘야 정상 작동

Posted by system
l