DOCUMENT:Q201116 11-MAR-2000 [visualc] TITLE :BUG: CB_SETTOPINDEX and CB_GETTOPINDEX Always Return 0 on Mac PRODUCT :Microsoft C Compiler PROD/VER:MACINTOSH:4.0,4.0b OPER/SYS: KEYWORDS:kbHWMAC kbMFC kbVC kbVC400bug kbDSupport kbGrpDSMFCATLkbbuglist ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual C++, Macintosh Cross-Development Addon, versions 4.0, 4.0b ------------------------------------------------------------------------------- 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 this to be a bug in the Microsoft products 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: Q65881 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; #ifdef _MAC CListBox m_comboList; #endif ... }; void CCtrlsView::OnInitialUpdate() { CFormView::OnInitialUpdate(); #ifdef _MAC // Obtain pointer to combo's list box. HWND hComboList = m_comboindex.GetWindow(GW_CHILD)->m_hWnd; ASSERT(hComboList); // Verify class name. char className[50]; GetClassName(hComboList, className, 50); ASSERT(lstrcmp(className, "ComboLBox") == 0); // Subclass to use CListBox. m_comboList.SubclassWindow(hComboList); #endif ... } // A simple combo box with "set" and "get" buttons using // the values from an edit control. void CCtrlsView::OnSetindex() { UpdateData(TRUE); #ifndef _MAC m_comboindex.SetTopIndex(m_currentIndex); #else m_comboList.SetTopIndex(m_currentIndex); #endif } void CCtrlsView::OnGetindex() { #ifndef _MAC m_currentIndex = m_comboindex.GetTopIndex(); #else m_currentIndex = m_comboList.GetTopIndex(); #endif UpdateData(FALSE); } REFERENCES ========== (c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Adam Kim, Microsoft Corporation. Additional query words: Macintosh CB_GETTOPINDEX CB_SETTOPINDEX combobox listbox ====================================================================== Keywords : kbHWMAC kbMFC kbVC kbVC400bug kbDSupport kbGrpDSMFCATL kbbuglist Technology : kbVCsearch kbHWMAC kbOSMAC kbAudDeveloper kbVCXDev400Mac kbVCXDev400bMac Version : MACINTOSH:4.0,4.0b Issue type : kbbug ============================================================================= 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. Copyright Microsoft Corporation 2000.