<menu id="w8yyk"><menu id="w8yyk"></menu></menu>
  • <dd id="w8yyk"><nav id="w8yyk"></nav></dd>
    <menu id="w8yyk"></menu>
    <menu id="w8yyk"><code id="w8yyk"></code></menu>
    <menu id="w8yyk"></menu>
    <xmp id="w8yyk">
    <xmp id="w8yyk"><nav id="w8yyk"></nav>
  • 網站首頁 > 物聯資訊 > 技術分享

    積累的VC編程小技巧之滾動條

    2016-09-28 00:00:00 廣州睿豐德信息科技有限公司 閱讀
    睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接

    1.設置滾動條的滾動大小

    創建一個基于CScrollview的SDI Project(在第6步中選CScrollview) 
    若你已創建了,這步可以省略。 
    然后: 
    改為如 
    void CTestView::OnInitialUpdate() 

    CScrollView::OnInitialUpdate(); 

    CSize sizeTotal; 
    // TODO: calculate the total size of this view 
    sizeTotal.cx = 1024;  //改這兩個 
    sizeTotal.cy = 768;   // 
    SetScrollSizes(MM_TEXT, sizeTotal); 
    }

     

    2.滾動條的控制

    BOOL CDiagramShowView::PreTranslateMessage(MSG* pMsg)

    {

           CFileTreeDoc* pDoc = (CFileTreeDoc*)GetDocument();

           CPoint point = GetScrollPosition();

          

           if(pMsg->message == WM_KEYDOWN)

           {

                  switch(pMsg->wParam)

                  {

                  case VK_LEFT:

                         if( point.x > 10)

                         {

                               EndPoint.x = EndPoint.x - 10;

                               EndPoint.y = EndPoint.y;

                         }

                         else

                         {

                               EndPoint.x = 0;

                               EndPoint.y = EndPoint.y;

                         }

                         ScrollToPosition(EndPoint);

                         InvalidateRect(NULL,TRUE);

                         break;

                  case VK_RIGHT:

                         if( point.x < pDoc->intDiagramColumnCount * pDoc->intColumnWidth - 10 )

                         {

                               EndPoint.x = EndPoint.x + 10;

                               EndPoint.y = EndPoint.y;

                         }

                         else

                         {

                               EndPoint.y = pDoc->intDiagramColumnCount * pDoc->intColumnWidth;

                               EndPoint.x = EndPoint.x;

                         }

                         ScrollToPosition(EndPoint);

                         InvalidateRect(NULL,TRUE);

                         break;

                  case VK_UP:

                         if( point.y > 10)

                         {

                               EndPoint.y = EndPoint.y - 10;

                               EndPoint.x = EndPoint.x;

                         }

                         else

                         {

                               EndPoint.y = 0;

                               EndPoint.x = EndPoint.x;

                         }

                         ScrollToPosition(EndPoint);

                         InvalidateRect(NULL,TRUE);

                         break;

                  case VK_DOWN:

                         if( point.y < pDoc->intDiagramRowCount * pDoc->intRowHeight - 10 )

                         {

                               EndPoint.y = EndPoint.y + 10;

                               EndPoint.x = EndPoint.x;

                         }

                         else

                         {

                               EndPoint.y = pDoc->intDiagramRowCount * pDoc->intRowHeight;

                               EndPoint.x = EndPoint.x;

                         }

                         ScrollToPosition(EndPoint);

                         InvalidateRect(NULL,TRUE);

                         break;

                  default:

                         break;

                  }

           }

           return FALSE;

    }

     

     

    // 通過正負號判斷是向上還是向下滾動

    if(zDelta==120) 

    向上滾動
    if(zDelta==-120)
    向下滾動

     

    BOOL CDiagramShowView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)

    {

           CFileTreeDoc* pDoc = (CFileTreeDoc*)GetDocument();

           CPoint point = GetScrollPosition();

          

           if(zDelta==120)

           {

                  if( point.y >= 20 )

                  {

                         EndPoint.x = point.x;

                         EndPoint.y = point.y;

                        

                         EndPoint.x = EndPoint.x;

                         EndPoint.y = EndPoint.y - 20;

                  }

                  else

                  {

                         EndPoint.x = EndPoint.x;

                         EndPoint.y = 0;

                  }

           }

          

           if(zDelta==-120)

           {

                  if( point.y <= pDoc->intDiagramRowCount * pDoc->intRowHeight - 20 )

                  {

                         EndPoint.x = point.x;

                         EndPoint.y = point.y;

                        

                         EndPoint.x = EndPoint.x;

                         EndPoint.y = EndPoint.y + 20;

                  }

                  else

                  {

                         EndPoint.x = EndPoint.x;

                         EndPoint.y = EndPoint.y;

                  }

           }

          

           ScrollToPosition(EndPoint);

           InvalidateRect(NULL,TRUE);

           return CScrollView::OnMouseWheel(nFlags, zDelta, pt);

    }

     

    3.給從CWnd派生的窗口添加滾動條

    ModifyStyle(0,WS_VSCROLL);

     

    4.如何用鍵盤滾動分割的視口

    我的問題是當我用鼠標滾動分割窗口時,視口滾動都很正常,但用鍵盤時,卻什么也沒有發生.

    在你的視圖繼承類中加入如下兩個函數,假定該類為CScrollerView:

    void CScrollerView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
            BOOL processed;
            for (unsigned int i=0;i< nRepCnt&&processed;i++)
                    processed=KeyScroll(nChar);
            if (!processed)
               CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
    }

    BOOL CScrollerView::KeyScroll(UINT nChar)
    {
            switch (nChar)
                    {
                    case VK_UP:
                            OnVScroll(SB_LINEUP,0,NULL);
                            break;
                    case VK_DOWN:
                            OnVScroll(SB_LINEDOWN,0,NULL);
                            break;
                    case VK_LEFT:
                            OnHScroll(SB_LINELEFT,0,NULL);
                            break;
                    case VK_RIGHT:
                            OnHScroll(SB_LINERIGHT,0,NULL);
                            break;
                    case VK_HOME:
                            OnHScroll(SB_LEFT,0,NULL);
                            break;
                    case VK_END:
                            OnHScroll(SB_RIGHT,0,NULL);
                            break;
                    case VK_PRIOR:
                            OnVScroll(SB_PAGEUP,0,NULL);
                            break;
                    case VK_NEXT:
                            OnVScroll(SB_PAGEDOWN,0,NULL);
                            break;
                    default:
                            return FALSE; // not for us
                                 // and let the default class
                                 // process it.
                    }
       return TRUE;
    }

     

    RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成
    最近免费观看高清韩国日本大全