See below, the code is unnecessarily convoluted.
joe
On Fri, 21 Sep 2007 16:39:22 +0200, mosfet <john...@anonymous.org> wrote:
>Hi,
>
>I am trying to modify the row height of a custom draw CListCtrl.
>I have tried to put the "owner draw fixed" (LVS_OWNERDRAWFIXED) style
>and to catch WM_MEASUREITEM but it doesn't seem to work, it even crashs.
>
>
>BEGIN_MESSAGE_MAP(CListCtrlCommands, CListCtrl)
> ON_WM_SIZE()
> ON_WM_GETDLGCODE()
> ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &CListCtrlCommands::OnCustomDraw)
> ON_WM_MEASUREITEM_REFLECT()
>END_MESSAGE_MAP()
>
>void CListCtrlCommands::MeasureItem( LPMEASUREITEMSTRUCT
>lpMeasureItemStruct )
>{
> TRACE(_T("CListCtrlCommands::MeasureItem()\n") );
> TEXTMETRIC tm;
****
First, replace that ridiculous parameter name with something sensible, like "mis".
CClientDC dc(this);
CFont * font = GetFont();
int save = dc.SaveDC();
dc.SelectObject(font);
dc.GetTextMetrics(&tm);
mis->itemHeight = tm.tmHeight + tm.tmExternalLeading + 1;
dc.RestoreDC(save);
So much easier! No ::GetDC or worries about doing ::ReleaseDC. No need to do clumsy
casting. No need to drop to raw APIs (and when using raw APIs, be consistent about the
use of ::, which you have not been). You stay within MFC.
I also note you used the completely meaningless word "crash" to describe a problem. What,
exactly (and I mean *exactly*) do you mean by this silly word? Did you mean it took an
access fault? If so, where? What was the stack backtrace? What line of your code was
the line that triggered it? Was it an assertion failure? If so, where did it take place?
What were the values of the variables the assertion was testing? I have no idea what a
"crash" is, and could not possibly diagnose a problem from such an empty description.
Worse still, you don't even describe what you mean when you say "doesn't seem to work".
What do you mean by "work"? What did you see that convinces you it isn't "working"?
Whatever "working" is...
joe
*****
> HDC hDC = ::GetDC(NULL);
> CFont* pFont = GetFont();
> HFONT hFontOld = (HFONT)SelectObject(hDC, pFont->GetSafeHandle());
> GetTextMetrics(hDC, &tm);
> lpMeasureItemStruct->itemHeight = tm.tmHeight +
>tm.tmExternalLeading + 1;
> SelectObject(hDC, hFontOld);
> ::ReleaseDC(NULL, hDC);
>}
>
>I don't even know if it's possible to mix customdraw and ownerdraw fixed.
>If someone could tell me how to do it ...
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm