class ATL_NO_VTABLE CAtlFocusTest :
...
{
public:
...
STDMETHOD(UIDeactivate)(void)
{
ATLTRACE("CAtlFocusTest::UIDeactivate() - handle kill focus event\n");
return IOleInPlaceObjectWindowlessImpl<CAtlFocusTest>::UIDeactivate();
}
STDMETHOD(DoVerb)(LONG iVerb, LPMSG pMsg, IOleClientSite* pActiveSite, LONG lindex,
HWND hwndParent, LPCRECT lprcPosRect)
{
if (iVerb == OLEIVERB_UIACTIVATE)
{
ATLTRACE("CAtlFocusTest::DoVerb(iVerb=%d) - handle set focus event\n", iVerb);
// Do not call IOleInPlaceSiteWindowless::SetFocus(TRUE) here because
// it will call DoVerb again!
}
else
ATLTRACE("CAtlFocusTest::DoVerb(iVerb=%d) - handle some other event\n", iVerb);
return IOleObjectImpl<CAtlFocusTest>::DoVerb(iVerb, pMsg, pActiveSite, lindex, hwndParent, lprcPosRect);
}
STDMETHOD(OnFrameWindowActivate)(BOOL fActivate)
{
if (fActivate)
{
ATLTRACE("CAtlFocusTest::OnFrameWindowActivate(fActivate=%d) - handle set focus event (switching app)\n", fActivate);
if (m_spInPlaceSite)
m_spInPlaceSite->SetFocus(TRUE);
}
else
{
ATLTRACE("CAtlFocusTest::OnFrameWindowActivate(fActivate=%d) - handle kill focus event (switching app)\n", fActivate);
if (m_spInPlaceSite)
m_spInPlaceSite->SetFocus(FALSE);
}
return IOleInPlaceActiveObjectImpl<CAtlFocusTest>::OnFrameWindowActivate(fActivate);
}
LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
ATLTRACE("CAtlFocusTest::OnKeyDown(%d, %d, %d, %d)\n",
uMsg, wParam, lParam, bHandled);
return 0;
}
LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (m_spInPlaceSite)
m_spInPlaceSite->SetFocus(TRUE);
return 0;
}
...
};