MFC CHeaderCtrl height & VS 05 Windows XP theme  
Author Message
Farid_Z





PostPosted: Visual C++ General, MFC CHeaderCtrl height & VS 05 Windows XP theme Top

After updating my application to Visual Studio 2005, I can no longer set the height of CListCtrl header when using Windows XP theme UI. Previously I was able to set the header height by setting the header control font to a larger font but using owner-draw and drawing the the header ctrl using a regular font..

With VS 05 this no longer work. The header ctrl height does not change anymore depending on the its font. What is the appropriate mechanism of setting the height for CListCtrl header I need to display two lines of information for each header item and that's why I need to maker the header ctrl height larger.


Visual C++8  
 
 
Farid_Z





PostPosted: Visual C++ General, MFC CHeaderCtrl height & VS 05 Windows XP theme Top

Found the solution on the web.

Using the font size to set the CHeaderCtrl height of an MFC CListCtrl is a hack and does not work with common ctrl 6.0 in Windows XP style theme. Here is way to set the height directly and that works with both Windows 2000 and Windows XP.

Solution is posted by Migel on http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20705214.html

Basically, capture HDM_LAYOUT message and let Windows figure out the default layout for the header ctrl but then substitute the height you like. You still need to use owner-draw to actually draw the header ctrl but no longer need a dummy big font.

BEGIN_MESSAGE_MAP(CHeaderCtrlBase, CHeaderCtrl)
ON_MESSAGE(HDM_LAYOUT, OnLayout)
END_MESSAGE_MAP()


LRESULT CHeaderCtrlBase::OnLayout( WPARAM wParam, LPARAM lParam ) {

LRESULT lResult = CHeaderCtrl::DefWindowProc(HDM_LAYOUT, 0, lParam);

HD_LAYOUT &hdl = *( HD_LAYOUT * ) lParam;
RECT *prc = hdl.prc;
WINDOWPOS *pwpos = hdl.pwpos;

int nHeight = pwpos->cy * 2.30;

pwpos->cy = nHeight;
prc->top = nHeight;

return lResult;
}