PRB: Owner-Drawn ListView Control in 68K Application Crashes Macintosh (200099)



The information in this article applies to:

  • Microsoft Visual C++, Macintosh Cross-Development Addon 4.0b

This article was previously published under Q200099

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 that this is 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.


Modification Type:MajorLast Reviewed:8/27/2002
Keywords:kbDSupport kbprb KB200099