Article ID: 168777
Article Last Modified on 11/21/2006
// trap keys and forward on to the control
BOOL CMyActiveXCtrl::PreTranslateMessage(MSG* pMsg)
{
switch (pMsg->message)
{
case WM_KEYDOWN:
case WM_KEYUP:
switch (pMsg->wParam)
{
case VK_UP:
case VK_DOWN:
case VK_LEFT:
case VK_RIGHT:
case VK_HOME:
case VK_END:
SendMessage (pMsg->message, pMsg->wParam, pMsg->lParam);
// Windowless controls won't be able to call SendMessage.
// Instead, just respond to the message here.
return TRUE;
}
break;
}
return COleControl::PreTranslateMessage(pMsg);
}
If you have a child control within your ActiveX control, you need to
UI-Activate the whole control whenever that child control is activated.
For example, if you have an edit control inside your ActiveX control, add
a handler as follows to your ActiveX control class:
int CMyActiveXCtrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT
message)
{
if (!m_bUIActive)
OnActivateInPlace (TRUE, NULL); // == UI-Activate the control
return COleControl::OnMouseActivate(pDesktopWnd, nHitTest, message);
}
Because Internet Explorer may not immediately UI-Activate a control, even
if that is the only control on the page, it may be desirable to
automatically request a UI-Activation when the control is created. This can
be done during the COleControl::OnCreate (WM_CREATE) handler. Windowless
controls do not get WM_CREATE or any windows messages; therefore, this code
won't work in a windowless control. Also note that this does not guarantee
that a control will remain UI-Activated. If there are other controls on a
page that request UI-Activation in a similar manner, only one will
eventually be UI-Activated and receive keystroke messages as described. And
if the user TABs away from an ActiveX Control, Internet Explorer will
automatically UI-deactivate the control.
int CMyActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
OnActivateInPlace (TRUE, NULL); // == UI-Activate the control
return 0;
}
Keywords: kbinprocsvr kbprb kbctrl KB168777