본문 바로가기
Programming/VC++

[MFC] 다이얼로그에서 단축키 써보자

by ㅇㅏㄹI 수 2007. 2. 17.

1. 다이얼로그 클래스안에 HACCEL m_hAccel 이란 멤버 변수를 만든다

2. 다이얼로그 클래스 OnInitDialog() 안에 아래 내용추가


m_hAccel = LoadAccelerators(AfxGetResourceHandle(),
 MAKEINTRESOURCE(IDR_ACCELERATOR) );
* IDR_ACCELERATOR 는 단축키 리소스 이름 

3. 다이얼로그 클래스에 PreTranslateMessage 메시지 추가


BOOL 다이얼로그클래스::PreTranslateMessage(MSG* pMsg) 
{
    // TODO: Add your specialized code here and/or call the base class
    HWND hWnd=GetSafeHwnd();    
    if (TranslateAccelerator(hWnd, m_hAccel, pMsg))
        return TRUE;    
    
    return CDialog::PreTranslateMessage(pMsg);
}

출처: 나우누리 MFC동 욜라천재(김민장 )

728x90

댓글