정리

'PreTranslateMessage'에 해당되는 글 1건

  1. [MFC] Esc Key 또는 Return Key에 의해 Dialog가 닫힐 때 처리 방법

[MFC] Esc Key 또는 Return Key에 의해 Dialog가 닫힐 때 처리 방법

저장소/VC++
Dialog를 만들고 아무런 처리도 안하면 Esc Key 또는 Return Key를 누를 경우 Dialog가 종료된다.
이런게 편하다면 그냥 쓰면 되겠지만 불편할 때가 오히려 더 많다.
이 문제를 처리하기 위해서는 PreTranslateMessage를 Override해야한다.
아래와 같이 처리해주면 Esc Key나 Return Key를 눌러도 Dialog가 종료되지 않는다.

BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg)
{
	// TODO: Add your specialized code here and/or call the base class

	if(NULL != pMsg)
	{
		if(WM_KEYDOWN == pMsg->message)
		{
			if( VK_RETURN == pMsg->wParam ||
			    VK_ESCAPE == pMsg->wParam )
			{
				return FALSE;
			}
		}
	}

	return CDialog::PreTranslateMessage(pMsg);
}