BUG: DDX Problem with Combo Box in Win32sLast reviewed: June 26, 1997Article ID: Q139593 |
The information in this article applies to:
SYMPTOMSThe DDX function DDX_CBString does not work correctly under Win32s for combo boxes that use the drop list style. If you try to use DDX to retrieve the string associated with the static control of a drop list style combo box under Win32s, an empty string is returned.
CAUSEThis problem is the result of an improperly sign extended return value from the Windows SDK GetWindowTextLength function. The MFC function DDX_CBString uses GetWindowTextLength to try to determine how many characters to copy from the edit control of a combo box with a drop down style or the static control of a combo box with a drop list style. The GetWindowTextLength function fails to retrieve a valid text length for a combo box with a drop list style under Win32s. When GetWindowTextLength is called for a combo box with a drop list style under Win32s, a value of 0xFFFF is returned. Because this return value isn't properly sign extended to 0xFFFFFFFF, the DDX_CBString function doesn't work correctly.
RESOLUTIONIt is possible to work around this problem by providing your own implementation of the DDX_CBString function for the class that has the DDX_CBString call in its DoDataExchange function. If you provide your own DDX_CBString member function, it will override the standard MFC DDX_CBString function. To provide your own version of DDX_CBString follow these steps:
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available. Visual C++ versions 4.2 and later do not support building Win32s applications.
MORE INFORMATION
Sample CodeThe following is a sample of an override of the DDX_CBString function for the class called CMyTryDlg:
void AFXAPI CMyTryDlg::DDX_CBString(CDataExchange* pDX, int nIDC, CString& value) { HWND hWndCtrl = pDX->PrepareCtrl(nIDC); if (pDX->m_bSaveAndValidate) { // Get current edit item text (or drop list static) int nLen = ::GetWindowTextLength(hWndCtrl); if (nLen != -1 && nLen != 0xFFFF) { // Get known length ::GetWindowText(hWndCtrl, value.GetBufferSetLength(nLen), nLen+1); } else { // GetWindowTextLength does not work for drop lists assume // max of 255 characters ::GetWindowText(hWndCtrl, value.GetBuffer(255), 255+1); } value.ReleaseBuffer(); } else { // Set current selection based on model string if (::SendMessage(hWndCtrl, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)(LPCTSTR)value) == CB_ERR) { // Set the edit text (will be ignored if DROPDOWNLIST) AfxSetWindowText(hWndCtrl, value); } } } |
Keywords : kbprg kbui MfcMisc W32s kbbuglist
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |