DOCUMENT:Q200099 06-FEB-2000 [visualc] TITLE :PRB: Owner-Drawn List Control in 68K App Crashes Macintosh PRODUCT :Microsoft C Compiler PROD/VER:MACINTOSH:4.0b OPER/SYS: KEYWORDS:kbHWMAC kbVC kbDSupportkbbuglist ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual C++, Macintosh Cross-Development Addon, version 4.0b ------------------------------------------------------------------------------- SYMPTOMS ======== When displaying an owner-drawn ListView control in report view on a 68K Macintosh, the Macintosh system crashes displaying the following message: Sorry, a system error occurred. "application name" divide by zero If the program is executed under the debugger, Developer Studio displays the following message: Exception in xxx.exe: 0x00000004: Divide by Zero CAUSE ===== A bug with the height initialization of the ListView item for the control causes the internal call to ShowWindow to perform a divide-by-zero operation. RESOLUTION ========== Set the height of the ListView control item to an appropriate value in the parent window's WM_MEASUREITEM handler for the ListView control. This can be done through the itemHeight field of the LPMEASUREITEMSTRUCT structure pointer provided. STATUS ====== Microsoft has confirmed this to be a problem in the Microsoft products that are listed at the beginning of this article. MORE INFORMATION ================ The workaround involves setting the itemHeight data member of the LPMEASUREITEMSTRUCT structure pointer before the control is displayed. This can be done only in the parent window's WM_MEASUREITEM handler. It is not necessary to initially create the control without the WS_VISIBLE flag. The code below shows an example for an owner-drawn ListView control in a form view. The default height of a ListView control item on the Macintosh is 14 pixels. BEGIN_MESSAGE_MAP(CMyView, CFormView) ON_WM_MEASUREITEM() ... END_MESSAGE_MAP() // WM_MEASUREITEM is sent to parent of list control void CMyView::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) { if (nIDCtl == IDC_LIST1) { // Calculate appropriate font height. int newHeight = 0; CFont* pFont = (CFont*)GetFont(); if (pFont) { LOGFONT lf; pFont->GetLogFont(&lf); newHeight = (lf.lfHeight > 0) ? lf.lfHeight : -lf.lfHeight; } // Set new itemHeight, use 14 as default height. lpMeasureItemStruct->itemHeight = newHeight ? newHeight : 14; } CFormView::OnMeasureItem(nIDCtl, lpMeasureItemStruct); } IDC_LIST1 is the ID of the owner-drawn ListView control. NOTE: This problem does NOT appear on Visual C++ for the Macintosh version 4.0. REFERENCES ========== (c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Adam Kim, Microsoft Corporation. Additional query words: ownerdrawn ownerdraw CListCtrl list view WLM 4.0 4.1 4.2 owner-draw ====================================================================== Keywords : kbHWMAC kbVC kbDSupport kbbuglist Technology : kbVCsearch kbHWMAC kbOSMAC kbAudDeveloper kbVCXDev400bMac Version : MACINTOSH:4.0b Issue type : kbprb ============================================================================= 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.