Solved

Listview bug in ownerdraw mode

Posted on 1997-04-08
2
823 Views
Last Modified: 2013-12-03
I am having an interesting problem with a ListView in report mode
where the vertical space for the text is smaller than the text so
that the text gets clipped.

Details:  I am doing an ownerdraw listview because I wanted to
select an entire row at a time (not just the first column).  I
pretty much used Microsofts sample code as it was (I made it
better).  I didn't change anything to do with RECTs because
that is a parameter that comes into the function that is
overwritten.

This worked great when I was not specifying a font in the RC file.
But when I specify a larger than default font, the listview doesn't
vertically increase the space to display the data.  It works fine
if I take away the ownerdraw, but then I can't select a whole row,
just the first column.

I think this is a bug in listview.  Has anyone seen this or does anyone
have any ideas?
0
Comment
Question by:robertsg
2 Comments
 

Accepted Solution

by:
seanmc earned 150 total points
ID: 1334491
I'm speaking from the 16-bit world where we don't have CListCtrl, but
I've just done an ownerdraw CListBox and ran across the same problem,
here is my solution.

If the ownerdraw list has variable height items, you have to process
MeasureItem in the CListBox, or OnMeasureItem in the CListBox parent.

Something like this will work.  It gets the current font of the
CListBox and bases the itemHeight on the height of the current font.

void CMyListBox::MeasureItem(LPMEASUREITEMSTRUCT lpmis)
{
 CDC *pDC = GetDC();
 CFont *pFont = GetFont();
 CFont *pOldFont = pDC->SelectObject(pFont);
 TEXTMETRIC tm;
 pDC->GetTextMetrics(&tm);
 lpmis->itemHeight = tm.tmHeight;
 pDC->SelectObject(pOldFont);
 ReleaseDC(pDC);
}

If the ownerdraw list has fixed item height, a problem occurs in that
the MeasureItem routine is never called.  As far as I know, it is
supposed to be called just once to set the itemHeight for item 0 which
is then used for all items.  Because it is not called, the itemHeight
ends up being the height of the default system font.

To get around this, I placed the following code immediately after
sub-classing the listbox, but before the OnInitialUpdate (for a View)
or OnInitDialog (for a Dialog).

This code goes in the OnInitialUpdate or OnInitDialog function of a
derived View or Dialog.

 // after subclassing the listbox

 CDC *pDC = m_cMyListBox.GetDC();
 CFont *pFont = m_cMyListBox.GetFont();
 CFont *pOldFont = pDC->SelectObject(pFont);
 TEXTMETRIC tm;
 pDC->GetTextMetrics(&tm);

 // make a call to SetItemHeight for item 0
 m_cMyListBox.SetItemHeight(0,tm.tmHeight);

 pDC->SelectObject(pOldFont);
 m_cMyListBox.ReleaseDC(pDC);

// continue with call to OnInitialUpdate or OnInitDialog of base
//  class

This solved the problem for me.  Hope it works for your CListCtrl.

0
 

Author Comment

by:robertsg
ID: 1334492
Another workaround is to use the newest listview which has a
style called LVS_EX_FULLROWSELECT.  This can be set with
the following command:
  ListView_SetExtendedListViewStyle(GetDlgItem(hwnd, IDC_LISTVIEW),LVS_EX_FULLROWSELECT);

I'm pretty sure this is only available in windows95 and windowsNT.
It is built into MSVC 4.2 but you need MSDN for documentation
about this feature.


0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now