Bringing the window and/or view containing an SDI ActiveX Control to the top
-
Hello everyone: I have a question about bringing a window containing an ActiveX control to the top if it is partially obscured by another window. It's kind of long but please bear with me. For instance, say MyControl is my ActiveX Control I created that is inside a client consisting of a single window (we'll call it MyClient) - note that the client area of MyControl fills up the entire window of MyClient. Suppose another application's window obscures partially the MyClient window with MyControl in it (therefore, MyClient does not have focus). If I click on the non-obscured area of MyClient (which is actually clicking on the non-obscured client area of MyControl), how can I bring MyClient and coincidentally MyControl to the forefront and setfocus on MyClient? Now, here comes the twist. MyControl follows the Single Document-View (SDI) architecture. That is, the client area of MyControl is actually a CScrollView, with a CDocument, as part of CSingleDocTemplate object created in the InitInstance of the MyControl's COleControlModule. The CMainFrame is derived from CFrameWnd, but it has no caption bar or border, thereby allowing for a more visually pleasing embedded appearance in the client. So, what I did was handle the WM_LBUTTONUP handler of my derived CScrollView. I then propagated the the WM_LBUTTONUP msg up to my MyControl's derived COleControl class. There, I managed to get the IOleContainer interface pointer as illustrated below (CMyCtrl is derived from COleControl): void CMyCtrl::OnLButtonUp(UINT nFlags, CPoint point) { IOleContainer* pContainer = NULL; BOOL rc = FALSE; if(SUCCEEDED(GetClientSite()->GetContainer(&pContainer))) { CWnd* pParent = GetParent(); if(pParent) { CRect parentrect, rect; pParent->GetWindowRect(&parentrect); GetWindowRect(&rect); //pParent->SetWindowPos(&wndTop, parentrect.left, parentrect.top, parentrect.Width(), parentrect.Height(), SWP_NOMOVE | SWP_NOSIZE ); pParent->SetFocus(); } } if(pContainer) pContainer->Release(); COleControl::OnLButtonUp(nFlags, point); } The "pParent->SetFocus()" works with the control inside a CWnd of a container application, but how can I make it work if MyControl is embedded in the _view of an SDI client application_? Is there anything that I can do with IOleContainer pointer pContainer to bring the container (be it a dialog, a window, or a CView) to the forefront when it is clicked on? And here's the other thing - say that MyControl does not