PRB: Problems with CMDIFrameWnd Toolbar Combo Box

Last reviewed: July 22, 1997
Article ID: Q117685
1.00 1.50 WINDOWS kbprg kbprb

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC) included with:

        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

Using AppWizard, create an MDI application that contains a toolbar. Add a combo-box control to the toolbar using the same method that the CTRLBARS sample uses (see CMainFrame::CreateStyleBar() to create a combo box on the toolbar).

When you drop the list-box portion of the combo box down and move the parent-frame window, the list box detaches from the edit-box portion of the combo box. With the CTRLBARS sample, the list box closes as soon as you click the frame window.

CAUSE

This behavior is ultimately caused by a problem in the combo-box control in Windows. For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q76365
   TITLE     : PRB: Moving or Resizing the Parent of an Open Combo Box

In an SDI application, CFrameWnd::PreTranslateMessage() has code to detect when a CComboBox is the last active window. When this is true, the function sends a message to the CComboBox to close the drop-down list box. In an MDI application, CMDIFrameWnd::PreTranslateMessage() does not have any code to detect this special case; therefore, the combo box behaves as it normally does under Windows.

RESOLUTION

To work around this problem, you should handle WM_PAINT messages in your MDI application for the parent-frame window of the combo box and send the combo box a message directly. For example, if your frame window is class CMainFrame, if your toolbar is called MyToolBar, and if MyToolBar has a combo box named MyCombo, your OnPaint() would look like this:

   CMainFrame::OnPaint()
   {
   ...
      MyToolBar.MyCombo.SendMessage(CB_SHOWDROPDOWN, FALSE);
   ...
   }


Additional reference words: 1.00 1.50 2.00 2.50
KBCategory: kbprg kbprb
KBSubcategory: MfcUI
Keywords : kb16bitonly
Technology : kbMfc


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: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.