ATL ActiveX control loses focus when VB form displayed - Again.... 
Author Message
 ATL ActiveX control loses focus when VB form displayed - Again....

I posted this message (as a follow up) in the original thread ("ATL
ActiveX control loses focus when VB form displayed"). There have been
no responses as yet, so I am re-posting in the hope that someone can
offer some insight. I am quite keen to get this issue resolved....

The basic problem is on a VB form focus jumps from one ATL control to
the next control in the tab order (second control doesn't have to be
ATL) when another form is displayed from within an event posted by the
first control.

Using a simple ATL-wizard button-based control the problem of VB focus
jumping occurring on display of a second form (done on the button's
exposed click event) ONLY occurs if the control is on a form that is
an MDI child and the second form is displayed modelessly. If neither
of these criteria occurs focus remains on the ATL control as the
second form is displayed, and when that form is closed and the
original form regains focus.

I hope someone can offer some insight.

Further implementation details follow:

The control is windowed and based on a WTL CButton object in a
contained window:

    CContainedWindowT<WTL::CButton> m_ctlButton;

All it does is handle the BN_CLICKED message and fires a click event
(code generated by the wizard and located in SimpleButtonCP.h as per
usual) :

        // Replace this with message map entries for
        // superclassed Button

In the OnCreate handler the control is created as follows:

    HWND hWnd = m_ctlButton.Create(
                   this, 1, m_hWnd, &rc, NULL,
                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON);

The OnSetFocus handler was wizard-generated and unchanged by me:

    LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
        LRESULT lRes = CComControl<CSmplButton>::OnSetFocus(
                           uMsg, wParam, lParam, bHandled);
        if (m_bInPlaceActive)
            DoVerbUIActivate(&m_rcPos,  NULL);
        return lRes;

I have added the following routine to handle default highlighting of
the button:

    STDMETHOD(OnAmbientPropertyChange)(DISPID dispid)
            BOOL DisplayAsDefault;
            UINT Style = m_ctlButton.GetButtonStyle();

            if (DisplayAsDefault)
                Style |= BS_DEFPUSHBUTTON;
                Style &= ~BS_DEFPUSHBUTTON;

            m_ctlButton.SetButtonStyle(Style, true);

        } // if

        return S_OK;

Sun, 06 Mar 2005 07:39:22 GMT  
 [ 1 post ] 

 Relevant Pages 

1. ATL ActiveX control loses focus when VB form displayed

2. ATL ActiveX control loses focus when VB form displayed - Once more....

3. Help (Again): MDI ActiveX Document (Excel) does not hide its toolbars when it loses focus

4. Help (Again): MDI ActiveX Document (Excel) does not hide its toolbars when it loses focus

5. ATL Control Doesn't Lose Focus?

6. ActiveX control losing focus

7. ActiveX Control Stops Reponding When Loses Focus

8. Default button in a VB Form with an ActiveX edit control

9. ATL Control and VB Form.FormPrint method

10. Problem painting icon for ActiveX control in VB form

11. CListCtrl: The List Control de-highlights when the control loses focus

12. Rich-Error info lost on Attributed ATL project in remote debug config (again)


Powered by phpBB® Forum Software