Microsoft KB Archive/201116

= BUG: CB_SETTOPINDEX and CB_GETTOPINDEX Always Return Zero on Macintosh =

Article ID: 201116

Article Last Modified on 10/2/2003

-

APPLIES TO


 * Microsoft Visual C++ 4.0 Cross Development Edition for Macintosh
 * Microsoft Visual C++ 4.0 Cross Development Edition for Macintosh

-



This article was previously published under Q201116



SYMPTOMS
On the Macintosh, the combo box messages CB_GETTOPINDEX and CB_SETTOPINDEX fail and always return zero (0).



CAUSE
There are no message handlers for these messages in the combo-box window procedure in the Windows Portability Library.



RESOLUTION
Obtain a pointer to the list box portion of the combo box, and use LB_GETTOPINDEX and LB_SETTOPINDEX instead.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
The combo-box control is composed of an edit control and a list-box control. For additional information about combo boxes, please see the following article in the Microsoft Knowledge Base:

65881 INFO: The Parts of a Windows Combo Box and How They Relate

On the Intel side, the edit control is the first child of the combo box. For a simple combo box, the Macintosh has the list-box control as the first control.

The window handle to the list box can be obtained using GetWindow. Once a valid handle is obtained, using the LB_GETTOPINDEX and LB_SETTOPINDEX messages provides the same functionality as CB_GETTOPINDEX and CB_SETTOPINDEX.

The sample code below shows the MFC implementation:

Sample Code
class CCtrlsView : public CFormView { public: CComboBox  m_comboindex; int     m_currentIndex; CListBox m_comboList; ... };
 * 1) ifdef _MAC
 * 1) endif

void CCtrlsView::OnInitialUpdate {  CFormView::OnInitialUpdate;

// Obtain pointer to combo's list box. HWND hComboList = m_comboindex.GetWindow(GW_CHILD)->m_hWnd; ASSERT(hComboList);
 * 1) ifdef _MAC

// Verify class name. char className[50]; GetClassName(hComboList, className, 50); ASSERT(lstrcmp(className, "ComboLBox") == 0);

// Subclass to use CListBox. m_comboList.SubclassWindow(hComboList); ... }
 * 1) endif

// A simple combo box with "set" and "get" buttons using // the values from an edit control. void CCtrlsView::OnSetindex {  UpdateData(TRUE); m_comboindex.SetTopIndex(m_currentIndex); m_comboList.SetTopIndex(m_currentIndex); }
 * 1) ifndef _MAC
 * 1) else
 * 1) endif

void CCtrlsView::OnGetindex {  m_currentIndex = m_comboindex.GetTopIndex; m_currentIndex = m_comboList.GetTopIndex; UpdateData(FALSE); }
 * 1) ifndef _MAC
 * 1) else
 * 1) endif

