1.요약 

ATL 컴포넌트가 특정 키보드 메세지를 받을 수 있는 방법에 대해서 알아봅니다. 


2.본문 

ATL 컴포넌트를 만들게 되면, 웹브라우저가 키보드 메세지를 (Accelerator Key.. 예를 들어 Tab, Delete 같은 키) 컴포넌트로 보내주지 않습니다. 하지만, 웹브라우저가 노출하는 IOleInPlaceActiveObject 인터페이스의 TtranslateAccelerator 함수를 호출하면 됩니다. 물론 WM_KEYDOWN 메세지 핸들러에서 처리해 주시면 됩니다. 하지만, 간혹 WM_KEYDOWN 메세지가 정상적으로 들어오지 않는 경우가 있는데, 이를 위해서 아래와 같이 메세지 펌프를 조작하면 됩니다. 

3.예제

// 메세지 펌프 

while (GetMessage(&msg, NULL, 0, 0)) 

 TranslateMessage(&msg);


 // Send all keyboard messages to the window of your 

 // application. hwndApp is the window handle of 

 // your application. 

 // 

 if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) 

  ::SendMessage(hwndApp, msg.message, msg.wParam, msg.lParam);


 DispatchMessage(&msg); 

}


// WM_KEYDOWN 메세지 핸들러에서.. 

LRESULT OnKeydown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 

 // m_spWebBrowser is a data member of type IWebBrowser2. 

 // Using CComQIPtr in this way queries m_spWebBrowser 

 // for the IOleInPlaceActiveObject interface which is 

 // then stored in the pIOIPAO variable. 

 // 

 CComQIPtr pIOIPAO(m_spWebBrowser); 

 HRESULT hr = S_FALSE;


 if (pIOIPAO) 

 { 

  MSG msg; msg.message = uMsg; 

  msg.wParam = wParam; 

  msg.lParam = lParam; 

  hr = pIOIPAO->TranslateAccelerator(&msg); 

 } 

 

 return hr; 

}

Posted by 모과이IT
,