FIX: Combo Box in Toolbar Leaves Drop-Down Portion Behind

Last reviewed: September 18, 1997
Article ID: Q113587
1.00 WINDOWS kbprg kbfixlist kbbuglist

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC) included with: Microsoft Visual C++ for Windows, version 1.0

SYMPTOMS

In an MDI application, with a toolbar that contains a combo box, if the mainframe is moved while the drop-down portion of the combo box is showing, the frame moves but the drop-down box remains in its original position on the screen. The combo box must have either the CBS_DROPDOWN or CBS_DROPDOWNLIST style in order for this to occur.

RESOLUTION

The problem occurs because the CMDIFrameWnd::PreTranslateMessage member function does not call its base class version of PreTranslateMessage. CFrameWnd is the base class of CMDIFrameWnd. CFrameWnd::PreTranslateMessage calls the _AfxCancelModes function, which determines whether the drop-down portion of a combo box is showing and closes it if it is. CMDIFrameWnd::PreTranslateMessage does not call _AfxCancelModes, and therefore the drop-down portion is never closed.

To workaround this problem, the application should override PreTranslateMessage in the mainframe class. The override should check for either the WM_LBUTTONDOWN or WM_NCLBUTTONDOWN message and call _AfxCancelModes. The override should then call the base class version of PreTranslateMessage, CMDIFrameWnd::PreTranslateMessage.

Perform the following five steps to accomplish this:

  1. Copy the AUXDATA.H file, located in the MSVC\MFC\SRC directory, to the directory of the project so it can be included in the MAINFRAME.CPP file.

  2. Add the following code after the existing #includes in the MAINFRAME.CPP file. AUXDATA.H contains the prototype of _AfxCancelModes and must be included before the actual call to the function:

          #include "auxdata.h"
    

  3. Add the following function to MAINFRAME.CPP:

          BOOL CMainFrame::PreTranslateMessage( MSG* pMsg )
          {
    
              if( pMsg->message == WM_LBUTTONDOWN ||
                  pMsg->message == WM_NCLBUTTONDOWN )
                  _AfxCancelModes( pMsg->hwnd );
    
              return CMDIFrameWnd::PreTranslateMessage( pMsg );
          }
    
    

  4. Add the following prototype to the public section of the mainframe class in the MAINFRAME.H file:

        virtual BOOL PreTranslateMessage(MSG* pMsg);
    

  5. Build the project.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft Foundation classes (MFC) version 2.0. This problem was corrected in the Microsoft Foundation classes version 2.5.


Additional reference words: 1.00 2.00 combobox painting dropdown
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: MfcUI
Keywords : kb16bitonly MfcUI kbbuglist kbfixlist kbprg
Technology : kbMfc
Version : 1.00
Platform : 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 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.