隐藏CListCtrl的滚动条
方法1:
void CSkinListCtrl::PreSubclassWindow()
{
ModifyStyle(WS_BORDER, LVS_OWNERDRAWFIXED|LVS_NOSCROLL , SWP_NOSIZE); //LVS_NOSCROLL的去掉,影响了表头的LayOut无法被调用
2011.8.10
CHeaderCtrl *pHeader = GetHeaderCtrl();
m_HeaderEx.SubclassWindow(pHeader->GetSafeHwnd());
// m_HeaderEx.m_bLockHead = true; //锁定列表头
CRect rcWin;
GetWindowRect(&rcWin);
WINDOWPOS wp;
wp.hwnd = m_hWnd;
wp.cx = rcWin.Width();
wp.cy = rcWin.Height();
wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
CListCtrl::PreSubclassWindow();
}
通过这种方法可以去掉,滚动条,然后自己重写滚动条。后来发现出现了问题,一个是禁用滚动条后,表头的宽度不能再修改,一个是当列表时
item数量超过108个后,就不会再向下滚动,原因还没发现。
方法2:后来这样做,还是看CodeProject鬼佬的代码来弄的。
void CSkinListCtrl::PreSubclassWindow()
{
ModifyStyle(WS_BORDER, LVS_OWNERDRAWFIXED, SWP_NOSIZE); //LVS_NOSCROLL的去掉,影响了表头的LayOut无法被调用 2011.8.10
CHeaderCtrl *pHeader = GetHeaderCtrl();
m_HeaderEx.SubclassWindow(pHeader->GetSafeHwnd());
// m_HeaderEx.m_bLockHead = true; //锁定列表头
CRect rcWin;
GetWindowRect(&rcWin);
WINDOWPOS wp;
wp.hwnd = m_hWnd;
wp.cx = rcWin.Width();
wp.cy = rcWin.Height();
wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
CListCtrl::PreSubclassWindow();
}
void CSkinListCtrl::InitList() //在外面初始化的时候来调用
{
m_iScrollHeight = 0;
InitializeFlatSB(this->m_hWnd);
FlatSB_EnableScrollBar(m_hWnd, SB_BOTH, ESB_DISABLE_BOTH);
CWnd* pParent = GetParent();
//Create scrollbars at runtime
m_SkinVerticleScrollbar.Create(NULL, WS_CHILD|SS_LEFT|SS_NOTIFY|WS_VISIBLE|WS_GROUP,CRect(0,0,0,0), pParent);
m_SkinVerticleScrollbar.pListCtrl = this;
//call this to position the scrollbars properly
PositionScrollBars();
m_SkinVerticleScrollbar.SetScrollBkColor(RGB(221, 221, 221));
}
不知道为什么,我用了 InitializeFlatSB(this->m_hWnd);和FlatSB_EnableScrollBar(m_hWnd, SB_BOTH, ESB_DISABLE_BOTH);
滚动条依然无法被隐藏,只好再响应WM_NCCALCSIZE这个消息来隐藏滚动条。
void CSkinListCtrl::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
UpdateWindow();
ShowScrollBar(SB_VERT, FALSE);
ShowScrollBar(SB_HORZ, FALSE);
CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}
需要源码的朋友,只需要下你的邮箱,我会将Codeprject的代码发给你。