?
Solved

Listview bug in ownerdraw mode

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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
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…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

755 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