PRB: ListView with LVS_NOSCROLL Won't Display HeaderLast reviewed: September 30, 1995Article ID: Q137520 |
The information in this article applies to:
SYMPTOMSIn report view, the header control is not displayed for a ListView control created with the LVS_NOSCROLL style.
CAUSEThe ListView control positions the header control when the scrolling is updated. When the LVS_NOSCROLL style is specified, the control is never scrolled, so the header control is not positioned.
RESOLUTIONCall following function at the appropriate time to position the header control properly. To use the function, create the ListView without the LVS_NOSCROLL style, and then call this function whenever the ListView is created, resized, the view is changed, or the parent window receives the WM_SYSPARAMETERCHANGE message. Creating the control without the LVS_NOSCROLL style will ensure that the first item in the list won't be obscured by the header control. The function will automatically detect which view is currently set and act appropriately.
/*********************************************************************** PositionHeader Call this function when the ListView is created, resized, the view is changed, or a WM_SYSPARAMETERCHANGE message is recieved***********************************************************************/
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); }}
STATUSThis behavior is by design.
|
Additional reference words: 4.00 1.30
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |