Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Listview bug in ownerdraw mode

Posted on 1997-04-08
2
Medium Priority
?
885 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 300 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

618 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