How to set focus on ActiveX control in CMDIChildWnd ?
-
It looks like a very simple question, but I stuck with it ! I have the selfwritten ATL ActiveX. Then I wanted to place it inside the MFC window such as CMDIChildWnd to fill the entire client area. The only thing I want is that my ActiveX can get focus when the hosting window is activated. So I put the following code: void CMyFrame::OnSetFocus(CWnd* pOldWnd) { if (m_pView!=NULL) m_pView->SetFocus(); else CMDIChildWnd::OnSetFocus(pOldWnd); } where the CMyFrame is frame derived from CMDIChildWnd, m_pView - my ActiveX pointer. It has a type of pointer to the ActiveX CWnd_wrapper created by the VC7 wizard "MFC Class from ActiveX control". The problem is that my control gets focus only once - the first time the hosting window is activated. I've tested my ActiveX in the simple dialog window - all is ok... The ActiveX is created as: int CMyFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { m_pView = new CMyControl; if (m_pView!=NULL) { CRect rect(0,0,0,0); m_pView->Create(NULL,WS_CHILD | WS_VISIBLE | WS_TABSTOP,rect,this,1); // "this" - is a parent CMDIChildWnd ... Does anybody has an idea ? Thank you very much P.S. Actually I know the reason of that :) I separated my message in two parts: If I do something completly wrong, then you will see it from the first part - please tell me if its so :) Now the details: m_pView->SetFocus() actually does the DoVerb(OLEIVERB_UIACTIVATE) i.e. activates my ActiveX UI. This is done internally by the COleControlSite::SetFocus. The problem is that default implementation of COleControlSite ignores OnFocus(FALSE) event that comes from my ActiveX when it loses the focus. COleControlSite does not call UIDeactivate upon this event. Since my control was once OLEIVERB_UIACTIVATEed and was not UIDeactivated it ignored the next DoVerb(OLEIVERB_UIACTIVATE) though it losts the focus (the ATL implementation). I cannot modify this code since its in the ATL & MFC...