[MFC] User_MSG 사용법

2011. 7. 27. 13:28MFC


1. #define WM_USER_MSG (WM_USER+10000)

 

2. 사용자 메세지를 해당 class h, cpp에 등록한다.

//xxx.h 정의입니다.

afx_msg LRESULT OnTestMessage( WPARAM wParam, LPARAM lParam );
//xxx.cpp 구현입니다.

LRESULT CTestView::OnTestMessage( WPARAM wParam, LPARAM lParam )
{

     ...

}

 

3. 이제 메세지를 맵핑하여 만들어둔 함수를 동작하게 할 준비를 합니다.

 BEGIN_MESSAGE_MAP(CTestView Cwnd)

        ON_MESSAGE(WM_USER_MSG, OnTestMessage)

    END_MESSAGE_MAP()

 

4. 사용법

CWnd* pWnd = AfxGetMainWnd();

ASSERT(pWnd);

// m_DayCellData(struct or class) 주소값을 WParam에 넣는다.

pWnd->SendMessage(WM_USER_MSG, (WPARAM)(&this->m_DayCellData ), (LPARAM)0 )

//

//연결된 OnTestMessage로 메세지가 전달된다.

 

// p.s 두가지 방법으로 메세지를 보내요.

// PostMessage( MSG );  // 메시지큐를 이용. 
// SendMessage( MSG );  //  함수 마칠때까지 대기한다. 

'MFC' 카테고리의 다른 글

[MFC] ODBC  (0) 2012.06.11
[MFC] 디버깅용 DLL파일들  (0) 2012.06.04
[MFC]MFC에서 오류나는거  (0) 2011.05.27