Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Listview bug in ownerdraw mode

Posted on 1997-04-08
2
841 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

829 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