Solved

Listview bug in ownerdraw mode

Posted on 1997-04-08
2
843 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
[X]
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
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
link access with Quickbooks 9 64
Microsoft Query from QuickBooks 9 75
C# LINQ ForEach() question 6 77
Need a simple RegEx to search for two words 27 78
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 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