CRect rect;
GetClientRect(rect);
m_ListCtrl.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,rect, this, IDC_LIST);
DWORD dwSystl = ::GetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE);
SetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE,dwSystl|LVS_REPORT|WS_CHILD|WS_VISIBLE|WS_BORDER);
DWORD Exsystl =m_ListCtrl.GetExtendedStyle();
m_ListCtrl.SetExtendedStyle(Exsystl|LVS_EX_HEADERDRAGDROP|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES);
for (int j = 0; j < g_Column_Count; j++)
{
m_ListCtrl.InsertColumn(j, g_Column_Data[j].title);
m_ListCtrl.SetColumnWidth(j, g_Column_Data[j].nWidth);
g_Column_Width += g_Column_Data[j].nWidth; // 总宽度
}

解决方案 »

  1.   


    给你一个MSDN上的例子,处理OnHScroll函数,这个例子的各个分支都有,你想干什么,就在分支下做就行.void CMyView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
    {
       // Get the minimum and maximum scroll-bar positions.
       int minpos;
       int maxpos;
       pScrollBar->GetScrollRange(&minpos, &maxpos); 
       maxpos = pScrollBar->GetScrollLimit();   // Get the current position of scroll box.
       int curpos = pScrollBar->GetScrollPos();   // Determine the new position of scroll box.
       switch (nSBCode)
       {
       case SB_LEFT:      // Scroll to far left.
          curpos = minpos;
          break;   case SB_RIGHT:      // Scroll to far right.
          curpos = maxpos;
          break;   case SB_ENDSCROLL:   // End scroll.
          break;   case SB_LINELEFT:      // Scroll left.
          if (curpos > minpos)
             curpos--;
          break;   case SB_LINERIGHT:   // Scroll right.
          if (curpos < maxpos)
             curpos++;
          break;   case SB_PAGELEFT:    // Scroll one page left.
       {
          // Get the page size. 
          SCROLLINFO   info;
          pScrollBar->GetScrollInfo(&info, SIF_ALL);
       
          if (curpos > minpos)
          curpos = max(minpos, curpos - (int) info.nPage);
       }
          break;   case SB_PAGERIGHT:      // Scroll one page right.
       {
          // Get the page size. 
          SCROLLINFO   info;
          pScrollBar->GetScrollInfo(&info, SIF_ALL);      if (curpos < maxpos)
             curpos = min(maxpos, curpos + (int) info.nPage);
       }
          break;   case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
          curpos = nPos;      // of the scroll box at the end of the drag operation.
          break;   case SB_THUMBTRACK:   // Drag scroll box to specified position. nPos is the
          curpos = nPos;     // position that the scroll box has been dragged to.
          break;
       }   // Set the new position of the thumb (scroll box).
       pScrollBar->SetScrollPos(curpos);   CView::OnHScroll(nSBCode, nPos, pScrollBar);
    }