Microsoft KB Archive/113587

{|
 * width="100%"|

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

 * }

Q113587

-

The information in this article applies to:


 * The Microsoft Foundation Classes (MFC), included with:
 * Microsoft Visual C++, version 1.5

-

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:

 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.  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"   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 ); }   Add the following prototype to the public section of the mainframe class in the MAINFRAME.H file:     virtual BOOL PreTranslateMessage(MSG* pMsg);  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 query words: 1.00 2.00 combobox painting dropdown

Keywords : kb16bitonly kbMFC KbUIDesign kbVC

Issue type :

Technology : kbAudDeveloper kbMFC