Listview header height

Started by Pat Dooley, June 18, 2009, 12:02:41 PM

Previous topic - Next topic

Pat Dooley

How does one go about increasing the header row height in a listview to accomodate a larger font. The listview is set to LVS_REPORT and FullRowSelect.  The data rows turn out fine, but the header text is cut off. I would like to go as high as perhaps 30 points.

Pat
 

Jean-Pierre LEROY

Hi Pat,

I made also some tests and I have the same behavior as you.

I'm pretty sure Paul will be able to fix this issue quickly.

Jean-Pierrre

TechSupport

I thought that setting the font of the control would also set the height of the rows and header??? It seems to in my very brief test. Granted, when you change the font inside the FireFly environment you may see the ListView look funny but when the program is compiled and run it should be fine.

Pat Dooley

I've just barely started on this, but here is a screenshot.  The font is the default Tahoma at 30 points.  The header is meant to read DATE, TIME and MESSAGE.

TechSupport

Very strange because here is my screenshot.....

(I tried it on XP and Vista).


TechSupport

Can you email me your sample program so I can test it on my equipment?


Jean-Pierre LEROY

Hi Paul,

I think I found the issue.

If "Enable WinXP theme support" is ticked then it doesn't work.

Otherwise without WinXP theme support it works !

Seems stange ...

Jean-Pierre

Pat Dooley

Good catch and yes, it does make a difference. The problem appears to be solved, since I'm not too concerned with XP Themes at the moment.
In the process, I did figure out how to calculate the height if the header (20 pixels before the fix, 52 after), so it was a learning experience.
Thanks,
Pat

TechSupport

Thanks for figuring it out guys!

Jean-Pierre LEROY

Paul,

Do you know if there is any workaround (an API ?) to force the "Header Row Height" if we need to enable the Windows XP theme ?

For Pat: how do you calculate the height of the header for a specific font ?

Thanks
Jean-Pierre

TechSupport

When I researched this yesterday, I read a post by a Microsoft MVP and he said that there wasn't an api to explicitly set the height. The list of messages can be found at: http://msdn.microsoft.com/en-us/library/cc656468(VS.85).aspx


Pat Dooley

#11
Jean-Pierrre: This is all I could come up with.  It doesn't directly address the issue of header height, but still interesting.

start a new project.
put 4 textxboxes and one button on the form
Rename text2 to pointsize
Rename text3 to margx
Rename text4 to margy
Place Text1 away from the other boxes, since it will expand and shrink
In the button click event place the code below.

When you run it, enter some text uo to 30 characters in Text1 and also enter a point size in the pointsize box and an x and y margin in their boxes.  Notice if you enter 0 for both margins things get cut of.  This is due I think to an internal preset margin in text boxes and probably listview headers too.
The msgbox gives you the height of the font in pixels. At least it seems to.
Also, I don't know if I'm calling ReleaseDC properly.
Pat

Local hdc As Dword
Local hFont As Long
Local zString As Asciiz * 31
Local tFont As sizel
Local fontsize As Long
Local strLength As Long
Local marginx As Long
Local marginy As Long

marginx=Val(FF_TextBox_GetText (HWND_FORM1_MARGX))
marginy=Val(FF_TextBox_GetText (HWND_FORM1_MARGY))

fontsize=Val(FF_TextBox_GetText (HWND_FORM1_POINTSIZE))
If fontsize<4 Or fontsize> 72 Then Exit Function
hFont=FF_MakeFontEx ("Tahoma", fontsize, %False, %False, %False, %False)
zString=FF_TextBox_GetText (HWND_FORM1_TEXT1)
strLength=Len(FF_TextBox_GetText (HWND_FORM1_TEXT1))
If strLength>30 Then strLength=30
FF_Control_SetFont (HWND_FORM1_TEXT1, hfont)
hdc=GetDC(HWND_FORM1_TEXT1)

SelectObject(hdc,hfont)
GetTextExtentPoint32(hdc,zString,strLength,tfont)

FF_Control_SetSize (HWND_FORM1_TEXT1, tfont.cx+marginx, tfont.cy+marginy)
MsgBox "Height of font:"+Str$(tfont.cy)+$CrLf+"Width of string:"+Str$(tfont.cx)
If hFont Then DeleteObject hFont
ReleaseDC(0,hdc)

Forgot to mention... set the Text property of pointsize to "30", margx to "28", and margy to 4.  This will give you a starting point.  Also margx and margy are just fudge factors and as such, they should be pecentages which would require some code modification.
You'll notice that for any particular margx or margy values the text will get cut off for larger fonts.

TechSupport

ReleaseDC HWND_FORM1_TEXT1, hDC


Roger Garstang

XP's version of the Listview has been buggy for a while.  AutoSize doesn't work correct either when providing your own data for the control instead of loading the data to it.  Only choice is no themes, or I know I saw some code somewhere that allowed you to specify a filter for themes as to what controls/class of controls to apply or not apply to.