본문 바로가기
VisualStudio.C++.C#/코딩팁,함수활용,단편

MFC. CWnd::PreTranslateMessage . WM_KEYDOWN 핸들러로 수신못할 때.

by i.got.it 2020. 9. 30.

CWnd::PreTranslateMessage

 

- CWnd 메시지 큐에서 메시지 정보 읽어들인 시점 호출됨. 

-  CWnd 에 속한 다른 컨트롤러 들에 메시지 배포하기전에 메시지 정보 받을 수 있는것. 

- Used by class CWinApp to translate window messages before they are dispatched to the TranslateMessage and DispatchMessage Windows functions.

 

virtual BOOL PreTranslateMessage(MSG* pMsg);



typedef struct tagMSG {
  HWND   hwnd;
  UINT   message;
  WPARAM wParam;
  LPARAM lParam;
  DWORD  time;
  POINT  pt;
  DWORD  lPrivate;
} MSG, *PMSG, *NPMSG, *LPMSG;

 

 

 

 

from : MS

 

CWnd Class

 

docs.microsoft.com

 

CWnd::PreTranslateMessage 활용예.

CWnd 에 컨트롤들이 있고, CWnd 가 아닌 곳에 포커스가 있는 경우 CWnd 에서  WM_KEYDOWN 핸들러로는 키 이벤트 받지 못한다. 이런 경우  CWnd::PreTranslateMessage   오버라이딩하여 키 보드 메시지 수신가능.

 

BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)

{

  	if (pMsg->message == WM_KEYDOWN) // 키다운검출.
	{
		if (pMsg->wParam == VK_DELETE) // delete 키 검출
		{
			/// 처리할것 실행
		}
        
		if (GetKeyState(VK_CONTROL) < 0) // Ctrl 키가 눌러진 상태에서 
		{
			if (pMsg->wParam == 0x7A || pMsg->wParam == 0x5A) // z OR Z . 
			{

			}
			else if (pMsg->wParam == 0x78 || pMsg->wParam == 0x58) // x OR X
			{

			}
			else if (pMsg->wParam == 0x63 || pMsg->wParam == 0x43) // c OR C
			{

			}
			else if (pMsg->wParam == 0x76 || pMsg->wParam == 0x56) // v OR V
			{

			}
		} // ctrl 키 눌러진 상태에서, 
        
	}
 

   return CDialog::PreTranslateMessage(pMsg);

}

 

 


첫 등록 : 2020.09.30

최종 수정 : 

단축 주소 : https://igotit.tistory.com/2629

 


 

댓글



 

비트코인




암호화폐       외환/나스닥/골드       암호화폐/외환/나스닥/골드 암호화폐/외환/나스닥/골드   암호화폐/외환/나스닥/골드
     
현물 |선물 인버스 |선물 USDT       전략매니저(카피트레이딩)     롤오버 이자 없는 스왑프리계좌
( 스왑프리 암호화폐도 거래 가능 )    
MT4, MT5 , cTrader 모두 지원     FTMO 계좌 매매운용. MT4,MT5