快捷搜索:   服务器  安全  linux 安全  MYSQL  dedecms

symbian 5th系统滚动条使用

貌似好久没有更新自己的博客了。很怀恋这些一直拥护我的博友们。工作的迁移,环境的变化一切都来的是不是有点太突然,但是还好有大伙的陪伴,使我的目标更明确。。。 再次谢谢各位博友了。 过来分享下可可哥的经验。 还是直接上代码吧。  
  1. class CMyControl: public CCoeControl, public MEikScrollBarObserver  {  
  2.      public:// Constructors and destructor          ~CMyControl();  
  3.         static CMyControl* NewL(TRect aRect);          static CMyControl* NewLC(TRect aRect);  
  4.         private:  
  5.          CMyControl();           void ConstructL(TRect aRect);  
  6.          void Draw( const TRect& aRect ) const;           virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);  
  7.          TInt CountComponentControls() const;           CCoeControl* ComponentControl( TInt aIndex ) const;  
  8.          void CreateScrollBar();     
  9.      private:///MEikScrollBarObserver           void HandleScrollEventL(CEikScrollBar*  aScrollBar,TEikScrollEvent aEventType );  
  10.         protected:  
  11.          void SizeChanged();     
  12.         private:  
  13.         CEikScrollBarFrame* iSBFrame;          TInt                iScrollSpan;  
  14.         TInt                iScrollPos;          TBool iIsScrollDown;  
  15.    };  
  16.     
  17.  // Implementation of scroll bar in custom control along with number of movement by scrollbar in one Drag.  
  18. // ScrollBar in symbian c++ ("Symbian c++").     
  19. void CMyControl::CreateScrollBar()  {  
  20.          iScrollPos=-1;// initial scroll pos is -1 as 0 specify the first span/drag.           iScrollSpan=1;// scrollbar moves by one item at a time  
  21.          iSBFrame=new ( ELeave ) CEikScrollBarFrame( this,this);              iSBFrame->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOn);   
  22.          iSBFrame->CreateDoubleSpanScrollBarsL(ETrue, EFalse);// create scrollbar           iSBFrame->SetTypeOfVScrollBar(CEikScrollBarFrame::EDoubleSpan);//type of scrollbar  
  23. }     
  24. void CMyControl::SizeChanged()  {   
  25.          // Here you are required to define the size of your scrollbar//            TInt listStatusPaneHeight=60;  
  26.           TEikScrollBarFrameLayout layout;            TEikScrollBarModel       myModel;  
  27.           TEikScrollBarModel       myModel2;            myModel.iThumbSpan=1;  
  28.           myModel.iScrollSpan =iScrollSpan;               layout.iTilingMode=TEikScrollBarFrameLayout::EInclusiveRectConstant;             
  29.           TRect fullRect =TRect(TPoint(Rect().iTl.iX,Rect().iTl.iY+listStatusPaneHeight),TSize(Rect().Size().iWidth,Rect ().Size().iHeight-listStatusPaneHeight));            TRect inclRect = fullRect;  
  30.           if(iSBFrame)        {  
  31.             TBool stat = iSBFrame->TileL(&myModel2, &myModel, fullRect, inclRect, layout);          iSBFrame->DrawScrollBarsNow();  
  32.           }      }  
  33.       
  34.    void CMyControl::HandleScrollEventL(CEikScrollBar*  aScrollBar,TEikScrollEvent aEventType )  
  35.         {          switch(aEventType)  
  36.            {               case EEikScrollThumbDragVert:  
  37.                  {                     CEikScrollBar* sb=  iSBFrame->VerticalScrollBar();// get an object of your scroll bar  
  38.                    TInt pos=sb->ThumbPosition();/// it will provide new position of scrollbar                    if(iScrollPos<pos)  
  39.                    {                       iScrollPos=pos;/// moving down number of scroll span  
  40.                      iIsScrollDown=ETrue;                     }  
  41.                   else                    {  
  42.                      iScrollPos=pos;/// moving down number of scroll span                       iIsScrollDown=EFalse;  
  43.                    }                    DrawNow();  
  44.                   break;                  }  
  45.              case EEikScrollThumbReleaseVert:                    break;  
  46.              default:                    break;  
  47.             }          }  
让大家见笑了。争取抽点时间写写我自己的东西。
顶(1)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论