Article ID: 137520
Article Last Modified on 7/11/2005
/********************************************************************
PositionHeader
Call this function when the ListView is created, resized, the
view is changed, or a WM_SYSPARAMETERCHANGE message is received.
********************************************************************/
void PositionHeader(HWND hwndListView)
{
HWND hwndHeader = GetWindow(hwndListView, GW_CHILD);
DWORD dwStyle = GetWindowLong(hwndListView, GWL_STYLE);
/*
To ensure that the first item will be visible, create the control
without the LVS_NOSCROLL style and then add it here.
*/
dwStyle |= LVS_NOSCROLL;
SetWindowLong(hwndListView, GWL_STYLE, dwStyle);
/*
Only do this if the ListView is in report view and you were able to
get the header hWnd.
*/
if(((dwStyle & LVS_TYPEMASK) == LVS_REPORT) && hwndHeader)
{
RECT rc;
HD_LAYOUT hdLayout;
WINDOWPOS wpos;
GetClientRect(hwndListView, &rc);
hdLayout.prc = &rc;
hdLayout.pwpos = &wpos;
Header_Layout(hwndHeader, &hdLayout);
SetWindowPos( hwndHeader,
wpos.hwndInsertAfter,
wpos.x,
wpos.y,
wpos.cx,
wpos.cy,
wpos.flags | SWP_SHOWWINDOW);
ListView_EnsureVisible(hwndListView, 0, FALSE);
}
}
Keywords: kblistview kbprb kbctrl KB137520