2008. 12. 10. 10:39
Programming/VC++(API,MFC,WTL,ATL)
1. 원리)
CView에 있는 있는 모든 컨트롤로 메시지가 전달 되지 전에 CView에 있는 PreTranslateMessage()를 지나 간다. 따라서 원하는 컨트롤의 특정 메시지는 여기서 미리 사전 검열 및 변경 처리가 가능 하다. 물론 해당 클래스를 subclassing 하는 방법이 있지만 이 것은 무척 번거롭다고 할수 있다.
2. 예제) PreTranslateMessage에서 사전 필터링으로 CEdit 컨트롤의 엔터기 처리 하기
CEdit m_E;
BOOL CKeytestView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(WM_KEYDOWN == pMsg->message)
{
if(pMsg->hwnd == m_E.GetSafeHwnd())
{
if(VK_RETURN == pMsg->wParam)
{
//여기에 처리하고 싶은 내용을 쓰세요
}
}
}
return CFormView::PreTranslateMessage(pMsg);
}