随笔-341  评论-2670  文章-0  trackbacks-0
    Win32 API为了让控件更为有用真是煞费苦心,不仅Tab没有提供控件可见控制,连Scroll Bar点击的时候竟然是不修改Position的,要我在每一个消息里用SBM_SETSCROLLINFO来设置当前的位置。而且当前的位置的获得还不是一致的,根据消息的不同而不同。真是故意为难人啊。

    文本框里面的东西是为了检查各个消息中GetPosition函数的正确性而打出来的。输出消息的代码如下:
  1 #include "..\..\..\..\VL++\Library\Windows\VL_WinGUI.h"
  2 
  3 using namespace vl;
  4 using namespace vl::windows;
  5 
  6 class MyForm : public VL_WinForm
  7 {
  8 protected:
  9     VL_WinScroll*            FHScroll;
 10     VL_WinScroll*            FVScroll;
 11     VL_WinEdit*                FEdit;
 12 
 13     void InitControls()
 14     {
 15         FHScroll=new VL_WinScroll(this,true);
 16         FHScroll->Move(0,380,380,20);
 17         FVScroll=new VL_WinScroll(this,false);
 18         FVScroll->Move(380,0,20,380);
 19         FEdit=new VL_WinEdit(this,true);
 20         FEdit->Move(0,0,380,380);
 21         FEdit->SetReadonly(true);
 22 
 23         FHScroll->OnScrollMin.Bind(this,&MyForm::Scroll_ScrollMin);
 24         FHScroll->OnScrollMax.Bind(this,&MyForm::Scroll_ScrollMax);
 25         FHScroll->OnArrowDec.Bind(this,&MyForm::Scroll_ArrowDec);
 26         FHScroll->OnArrowInc.Bind(this,&MyForm::Scroll_ArrowInc);
 27         FHScroll->OnPageDec.Bind(this,&MyForm::Scroll_PageDec);
 28         FHScroll->OnPageInc.Bind(this,&MyForm::Scroll_PageInc);
 29         FHScroll->OnTracking.Bind(this,&MyForm::Scroll_Tracking);
 30         FHScroll->OnThumbUp.Bind(this,&MyForm::Scroll_ThumbUp);
 31         FHScroll->OnPositionChanged.Bind(this,&MyForm::Scroll_PositionChanged);
 32         FHScroll->OnEndScroll.Bind(this,&MyForm::Scroll_EndScroll);
 33 
 34         FVScroll->OnScrollMin.Bind(this,&MyForm::Scroll_ScrollMin);
 35         FVScroll->OnScrollMax.Bind(this,&MyForm::Scroll_ScrollMax);
 36         FVScroll->OnArrowDec.Bind(this,&MyForm::Scroll_ArrowDec);
 37         FVScroll->OnArrowInc.Bind(this,&MyForm::Scroll_ArrowInc);
 38         FVScroll->OnPageDec.Bind(this,&MyForm::Scroll_PageDec);
 39         FVScroll->OnPageInc.Bind(this,&MyForm::Scroll_PageInc);
 40         FVScroll->OnTracking.Bind(this,&MyForm::Scroll_Tracking);
 41         FVScroll->OnThumbUp.Bind(this,&MyForm::Scroll_ThumbUp);
 42         FVScroll->OnPositionChanged.Bind(this,&MyForm::Scroll_PositionChanged);
 43         FVScroll->OnEndScroll.Bind(this,&MyForm::Scroll_EndScroll);
 44     }
 45 
 46     void Print(VUnicodeString Message)
 47     {
 48         FEdit->SetText(FEdit->GetText()+Message+L"\r\n");
 49         FEdit->Select(FEdit->GetText().Length(),0);
 50         FEdit->ScrollToCaret();
 51     }
 52 
 53     void Print(VL_Base* Sender , VUnicodeString Message)
 54     {
 55         VL_WinScroll* Scroll=dynamic_cast<VL_WinScroll*>(Sender);
 56         if(Scroll)
 57         {
 58             if(Scroll==FHScroll)
 59             {
 60                 Print(L"Horizontal , "+Message+L" = "+VUnicodeString(Scroll->GetPosition()));
 61             }
 62             else
 63             {
 64                 Print(L"Vertical , "+Message+L" = "+VUnicodeString(Scroll->GetPosition()));
 65             }
 66         }
 67     }
 68 
 69     void Scroll_ScrollMin(VL_Base* Sender)
 70     {
 71         Print(Sender,L"Min");
 72     }
 73 
 74     void Scroll_ScrollMax(VL_Base* Sender)
 75     {
 76         Print(Sender,L"Max");
 77     }
 78 
 79     void Scroll_ArrowDec(VL_Base* Sender)
 80     {
 81         Print(Sender,L"Arrow-");
 82     }
 83 
 84     void Scroll_ArrowInc(VL_Base* Sender)
 85     {
 86         Print(Sender,L"Arrow+");
 87     }
 88 
 89     void Scroll_PageDec(VL_Base* Sender)
 90     {
 91         Print(Sender,L"Page-");
 92     }
 93 
 94     void Scroll_PageInc(VL_Base* Sender)
 95     {
 96         Print(Sender,L"Page+");
 97     }
 98 
 99     void Scroll_Tracking(VL_Base* Sender)
100     {
101         Print(Sender,L"Tracking");
102     }
103 
104     void Scroll_ThumbUp(VL_Base* Sender)
105     {
106         Print(Sender,L"ThumbUp");
107     }
108 
109     void Scroll_PositionChanged(VL_Base* Sender)
110     {
111         Print(Sender,L"Changed");
112     }
113 
114     void Scroll_EndScroll(VL_Base* Sender)
115     {
116         Print(Sender,L"End");
117     }
118 
119 public:
120 
121     MyForm():VL_WinForm(true)
122     {
123         SetMaximizeBox(false);
124         SetBorder(vwfbSingle);
125         SetClientWidth(400);
126         SetClientHeight(400);
127         SetText(L"Vczh Form");
128         MoveCenter();
129         InitControls();
130         Show();
131     }
132 };
133 
134 void main()
135 {
136     new MyForm;
137     GetApplication()->Run();
138 }
    至于我是怎么解决GetPosition的呢?因为每一次操作Scroll Bar的Position都不会改,所以理所当然的,我要替它改……
 1     LRESULT VL_WinScroll::ProcessMessage(UINT Message , WPARAM& wParam , LPARAM& lParam , VBool& CallDefaultProcedure)
 2     {
 3         LRESULT Result=0;
 4         switch(Message)
 5         {
 6         case WM_VSCROLL_DISPATCHED:
 7         case WM_HSCROLL_DISPATCHED:
 8             switch(LOWORD(wParam))
 9             {
10             case SB_ENDSCROLL:
11                 OnEndScroll(this);
12                 break;
13             case SB_LEFT:
14                 OnScrollMin(this);
15                 OnPositionChanged(this);
16                 break;
17             case SB_RIGHT:
18                 OnScrollMax(this);
19                 OnPositionChanged(this);
20                 break;
21             case SB_LINELEFT:
22                 SetPosition(GetPosition()-1);
23                 OnArrowDec(this);
24                 OnPositionChanged(this);
25                 break;
26             case SB_LINERIGHT:
27                 SetPosition(GetPosition()+1);
28                 OnArrowInc(this);
29                 OnPositionChanged(this);
30                 break;
31             case SB_PAGELEFT:
32                 SetPosition(GetPosition()-GetPage());
33                 OnPageDec(this);
34                 OnPositionChanged(this);
35                 break;
36             case SB_PAGERIGHT:
37                 OnPageInc(this);
38                 SetPosition(GetPosition()+GetPage());
39                 OnPositionChanged(this);
40                 break;
41             case SB_THUMBPOSITION:
42                 {
43                     SCROLLINFO Info;
44                     GetInfo(Info);
45                     SetPosition(Info.nTrackPos);
46                     OnThumbUp(this);
47                     OnPositionChanged(this);
48                 }
49                 break;
50             case SB_THUMBTRACK:
51                 {
52                     SCROLLINFO Info;
53                     GetInfo(Info);
54                     SetPosition(Info.nTrackPos);
55                     OnTracking(this);
56                     OnPositionChanged(this);
57                 }
58                 break;
59             }
60             Result=VL_WinControl::ProcessMessage(Message,wParam,lParam,CallDefaultProcedure);
61             break;
62         default:
63             Result=VL_WinControl::ProcessMessage(Message,wParam,lParam,CallDefaultProcedure);
64         }
65         return Result;
66     }

posted on 2008-08-15 06:26 陈梓瀚(vczh) 阅读(1371) 评论(1)  编辑 收藏 引用 所属分类: C++

评论:
# re: Scroll Bar完成 2008-08-15 07:27 | 沈臻豪(foxtail)
滚动条终于出来啦 等了好久  回复  更多评论
  

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理