FIX: DrawItem Not Called for an Owner Draw CListCtrl
  
PSS ID Number: Q132289
Article last modified on 01-22-1996
 
4.00    | 3.51 2.10
 
WINDOWS | WINDOWS NT
 

---------------------------------------------------------------------
The information in this article applies to:
 
 - Windows 95 M8 Beta version 4.0
 - Windows NT Beta version 3.51
 - The Microsoft Foundation Classes (MFC) included with:
   Microsoft Visual C++, 32-bit Edition, version 2.1
---------------------------------------------------------------------
 
SYMPTOMS
========
 
The DrawItem function is not called for an owner draw CListCtrl common
control.
 
CAUSE
=====
 
An owner draw control sends the WM_DRAWITEM message to its parent for each
item that needs to be painted. A pointer to the DRAWITEM structure is
passed as the LPARAM of the message. MFC's implementation of the OnDrawItem
handler determines which control sent the message by examining the hwndItem
field of the DRAWITEMSTRUCT structure. That field should contain the handle
of the control that requested painting. However, for a list view common
control, that field is not filled and contains a random value. Thus, the
originating control is not found, so the DrawItem function is not called.
 
RESOLUTION
==========
 
Override the OnDrawItem handler in the class that belongs to the parent
window of the list view control. Set the hwndItem field with a handle you
retrieve from the ID of the control.
 
Here is an example for a CDialog derived class:
 
   void CMyDialog::OnDrawItem(int nIDCtl,
                     LPDRAWITEMSTRUCT lpDrawItemStruct)
   {
     CDialog::DrawItem(nIDCtl, lpDrawItemStruct);
 
    if(lpDrawItemStruct->itemID==ID_LISTVIEW)
             lpDrawItemStruct->hwndItem=
                  ::GetDlgItem(m_hWnd,lpDrawItemStruct->itemID);
   }
 
ID_LISTVIEW is an ID associated with the list view control.
 
STATUS
======
 
Microsoft 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.
 
NOTE: This problem also exists in earlier versions of Windows 95 (including
M8, build 347), and Windows NT 3.51 (build 1002). It was corrected in build
451 of Windows 95, and build 1057 of Windows NT 3.51.
 
REFERENCES
==========
 
For more information about OnDrawItem and DrawItem, please see the Class
Library Reference in Books Online. For the default implementation of
OnDrawItem, please see the WINCORE.CPP file in MFC source code located in
the \MSVC20\MFC\SRC subdirectory.
 
Additional reference words: 2.10 3.10 DrawItem OnDrawItem owner-draw
KBCategory: kbui kbfixlist kbbuglist
KBSubcategory: MfcUI
=============================================================================
Copyright Microsoft Corporation 1996.
