Help and Support
 

powered byLive Search

FIX: DisplayAsDefault Ambient Property Not Updated for Control

Retired KB ArticleThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Article ID:148616
Last Review:November 18, 2003
Revision:2.0
This article was previously published under Q148616
On This Page

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.

Back to the top

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.

Back to the top

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).

Back to the top

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.

Back to the top

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();
}
				

Back to the top


APPLIES TO
Microsoft Foundation Class Library 4.2, when used with:
  Microsoft Visual C++ 4.0 Professional Edition
  Microsoft Visual C++ 5.0 Learning Edition

Back to the top

Keywords: 
kbbug kbcontainer kbctrl kbfix kblocalsvr kbnoupdate kbvc410fix KB148616

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.