FIX: DisplayAsDefault Ambient Property Not Updated for Control

Last reviewed: September 19, 1997
Article ID: Q148616
4.00 WINDOWS NT kbole kbprg kbbuglist kbfixlist

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC) included with: Microsoft Visual C++, 32-bit Edition, version 4.0

SYMPTOMS

When you use the arrow keys to change between controls in a Visual C++ 4.0 generated container, the DISPID_AMBIENT_DISPLAYASDEFAULT ambient property of the control site is not updated, and any control that relies on this property doesn't function correctly.

For example, a subclassed button control that is programmed to update its border according to the DISPID_AMBIENT_DISPLAYASDEFAULT ambient property will exhibit this behavior. In a Visual C++ generated container, the control won't update its border.

CAUSE

In Occdlg.cpp, the following line 542 shouldn't be called:

     bCheckDef = FALSE;

This line keeps CheckDefPushButton from being called and the ambient property from being updated.

RESOLUTION

The best solution is to upgrade to Visual C++ 4.1. If this is not a possibility, the MFC DLL can be rebuilt without bCheckDef = FALSE; however, Microsoft recommends against this because you need to rebuild the DLL with a different name (see tech note 33).

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in Microsoft Visual C++ version 4.1.

MORE INFORMATION

Sample Code

The following code can be added to the Button Control sample shipped with Visual C++ to demonstrate this problem.

///////////////////////////////////////////////////////////////////////////
/
// Display the button with a thick border if appropriate

void CButtonCtrl::OnAmbientPropertyChange(DISPID dispid)
{
    TRACE("OnAmbientPropertyChange called\n");
    BOOL bDisplayAsDefault = FALSE;
    if(DISPID_AMBIENT_DISPLAYASDEFAULT != dispid)
        return;
    // Check the control site to see if you should add or remove the border
    if (!GetAmbientProperty(DISPID_AMBIENT_DISPLAYASDEFAULT, VT_BOOL,
            &bDisplayAsDefault))
        ASSERT(FALSE);
    if(bDisplayAsDefault)
        SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, 0);
    else
        SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, 0);
    InvalidateControl();
}


Additional reference words: 4.00 focus
KBCategory: kbole kbprg kbbuglist kbfixlist
KBSubcategory: MfcOLE
Keywords : MfcOLE kbbuglist kbfixlist kbole kbprg
Technology : kbMfc
Version : 4.00
Platform : NT WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 19, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.