0

I have an owner drawn header of a ListView control. If the header is not owner drawn we have a nice hover effect when mouse is on one of the header's columns. After I made header columns owner drawn I have to take care of the hover effect myself.

In order to catch it I monitor WM_MOUSEMOVE message within header window and when I get this message I redraw the column of a header with changed background first and on top of that I draw text and other necessary graphics. There is just one but... The font of a text becomes bold.

You can see it below. First header is mine, and second header is from Windows explorer with hover effect on Date modified column.

enter image description here

Why does the font suddenly becomes bold? Is this the right way to implement hover effect? Maybe I missed some Header specific notification?

Community
  • 1
  • 1
Robertas
  • 1,164
  • 3
  • 11
  • 26

2 Answers2

1

In owner draw mode you have to take care of everything including fonts. Don't assume you know what the current DC font is. If you want a specific font you need to select one into the DC before drawing text.

beater
  • 555
  • 4
  • 6
0

Well, I solved this mystery :) Even though I still don't know why the font used in DrawThemeText function suddenly changed in WM_MOUSEMOVE notification. My approach still relies on catching WM_MOUSEMOVE event and redrawing the column underneath the mouse pointer. In order not to change the default header font (like in illustration in my question) I used the following code to get and set it:

HFONT displayFont = (HFONT)SendMessage( header, WM_GETFONT, 0, 0 ); // gets default header font
SelectObject(hdc, displayFont); // sets device context to use newly found font

This solution has at least one drawback: I redraw the Header too frequently (each time mouse moves within header column).

Robertas
  • 1,164
  • 3
  • 11
  • 26