• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-341  評論-2670  文章-0  trackbacks-0
                封裝Common Control Library 6.0的API越來越順手了。雖說要消滅BEGIN_MESSAGE_MAP之類的代碼,不過寫起來也不容易。BEGIN_MESSAGE_MAP不能動態替換,所以我換成了類似C#的Event和Delegate那樣子的東西。如果不需要動態替換的話,實際上并沒有什么大的區別,唯一的區別就在于你可以利用VC++的Intellisense去查看自己想要的事件,而不是將什么WM_LBUTTONDOWN之類的消息記住了。


              1 #include "..\..\..\..\VL++\Library\Windows\VL_WinMain.h"
              2 #include "..\..\..\..\VL++\Library\Windows\Commctrl\VL_WinButton.h"
              3 #include "..\..\..\..\VL++\Library\Windows\Commctrl\VL_WinContainers.h"
              4 #include "..\..\..\..\VL++\Library\Windows\Commctrl\VL_WinText.h"
              5 
              6 using namespace vl;
              7 using namespace vl::windows;
              8 
              9 const VInt _ClientWidth=400;
             10 const VInt _ClientHeight=500;
             11 const VInt _TextHeight=20;
             12 const VInt _ButtonWidth=100;
             13 const VInt _ButtonHeight=25;
             14 const VInt _Border=10;
             15 
             16 #define MakeButtonInit VInt __ButtonCount=0
             17 
             18 #define MakeButton(Name,Text)                                                    \
             19     Name=new VL_WinButton(this);                                                \
             20     Name->SetLeft(_ClientWidth-_Border-_ButtonWidth);                            \
             21     Name->SetTop(_Border*2+_TextHeight+(_ButtonHeight+_Border)*__ButtonCount++);\
             22     Name->SetWidth(_ButtonWidth);                                                \
             23     Name->SetHeight(_ButtonHeight);                                                \
             24     Name->SetText(Text);                                                        \
             25     Name->OnClick.Bind(this,&MyForm::##Name##_Click);
             26 
             27 class MyForm : public VL_WinForm
             28 {
             29 protected:
             30     VL_WinEdit*                TextBox;
             31     VL_WinListBox*            ListBox;
             32     VL_WinButton*            BtnAdd;
             33     VL_WinButton*            BtnInsert;
             34     VL_WinButton*            BtnDelete;
             35     VL_WinButton*            BtnReplace;
             36     VL_WinButton*            BtnUnhighlight;
             37     VL_WinButton*            BtnScroll;
             38     VL_WinButton*            BtnFind;
             39     VL_WinButton*            BtnFindExact;
             40     VL_WinButton*            BtnSelect;
             41     VL_WinButton*            BtnClear;
             42     VL_WinButton*            BtnUp;
             43     VL_WinButton*            BtnDown;
             44 
             45     void ShowMessage(VUnicodeString Message)
             46     {
             47         VL_WinMsgbox(this,Message,GetText(),vmbOK);
             48     }
             49 
             50     void InitControls()
             51     {
             52         TextBox=new VL_WinEdit(this,false);
             53         TextBox->SetLeft(_Border);
             54         TextBox->SetTop(_Border);
             55         TextBox->SetWidth(_ClientWidth-2*_Border);
             56         TextBox->SetHeight(_TextHeight);
             57 
             58         ListBox=new VL_WinListBox(this);
             59         ListBox->SetLeft(_Border);
             60         ListBox->SetTop(_Border*2+_TextHeight);
             61         ListBox->SetWidth(_ClientWidth-3*_Border-_ButtonWidth);
             62         ListBox->SetHeight(_ClientHeight-_Border*3-_TextHeight);
             63 
             64         MakeButtonInit;
             65         MakeButton(BtnAdd,L"Add");
             66         MakeButton(BtnInsert,L"Insert");
             67         MakeButton(BtnDelete,L"Delete");
             68         MakeButton(BtnReplace,L"Replace");
             69         MakeButton(BtnUnhighlight,L"Unhighlight");
             70         MakeButton(BtnScroll,L"Scroll");
             71         MakeButton(BtnFind,L"Find");
             72         MakeButton(BtnFindExact,L"FindExact");
             73         MakeButton(BtnSelect,L"Select");
             74         MakeButton(BtnClear,L"Clear");
             75         MakeButton(BtnUp,L"Up");
             76         MakeButton(BtnDown,L"Down");
             77     }
             78 
             79     void BtnAdd_Click(VL_Base* Sender)
             80     {
             81         ListBox->AddString(TextBox->GetText());
             82         TextBox->SetText(L"");
             83         TextBox->SetFocused();
             84     }
             85 
             86     void BtnInsert_Click(VL_Base* Sender)
             87     {
             88         if(ListBox->GetSelectedIndex()==-1)
             89         {
             90             ShowMessage(L"請在列表中選中一項。");
             91         }
             92         else
             93         {
             94             ListBox->InsertString(ListBox->GetSelectedIndex(),TextBox->GetText());
             95             TextBox->SetText(L"");
             96             TextBox->SetFocused();
             97         }
             98     }
             99 
            100     void BtnDelete_Click(VL_Base* Sender)
            101     {
            102         if(ListBox->GetSelectedIndex()==-1)
            103         {
            104             ShowMessage(L"請在列表中選中一項。");
            105         }
            106         else
            107         {
            108             ListBox->DeleteString(ListBox->GetSelectedIndex());
            109             TextBox->SetText(L"");
            110             TextBox->SetFocused();
            111         }
            112     }
            113 
            114     void BtnReplace_Click(VL_Base* Sender)
            115     {
            116         if(ListBox->GetSelectedIndex()==-1)
            117         {
            118             ShowMessage(L"請在列表中選中一項。");
            119         }
            120         else
            121         {
            122             ListBox->SetString(ListBox->GetSelectedIndex(),TextBox->GetText());
            123             TextBox->SetText(L"");
            124             TextBox->SetFocused();
            125         }
            126     }
            127 
            128     void BtnUnhighlight_Click(VL_Base* Sender)
            129     {
            130         if(ListBox->GetSelectedIndex()==-1)
            131         {
            132             ShowMessage(L"請在列表中選中一項。");
            133         }
            134         else
            135         {
            136             ListBox->SetSelected(ListBox->GetSelectedIndex(),false);
            137             TextBox->SetText(L"");
            138             TextBox->SetFocused();
            139         }
            140     }
            141 
            142     void BtnScroll_Click(VL_Base* Sender)
            143     {
            144         if(ListBox->GetSelectedIndex()==-1)
            145         {
            146             ShowMessage(L"請在列表中選中一項。");
            147         }
            148         else
            149         {
            150             ListBox->SetFocusedIndex(ListBox->GetSelectedIndex());
            151             TextBox->SetText(L"");
            152             TextBox->SetFocused();
            153         }
            154     }
            155 
            156     void BtnFind_Click(VL_Base* Sender)
            157     {
            158         VInt Index=ListBox->FindStringPrefix(TextBox->GetText());
            159         if(Index!=-1)
            160         {
            161             ListBox->SetSelectedIndex(Index);
            162             ListBox->SetFocusedIndex(Index);
            163         }
            164         else
            165         {
            166             ShowMessage(L"找不到。");
            167         }
            168         TextBox->SetText(L"");
            169         TextBox->SetFocused();
            170     }
            171 
            172     void BtnFindExact_Click(VL_Base* Sender)
            173     {
            174         VInt Index=ListBox->FindString(TextBox->GetText());
            175         if(Index!=-1)
            176         {
            177             ListBox->SetSelectedIndex(Index);
            178             ListBox->SetFocusedIndex(Index);
            179         }
            180         else
            181         {
            182             ShowMessage(L"找不到。");
            183         }
            184         TextBox->SetText(L"");
            185         TextBox->SetFocused();
            186     }
            187 
            188     void BtnSelect_Click(VL_Base* Sender)
            189     {
            190         ListBox->SelectPrefix(TextBox->GetText());
            191         TextBox->SetText(L"");
            192         TextBox->SetFocused();
            193     }
            194 
            195     void BtnClear_Click(VL_Base* Sender)
            196     {
            197         ListBox->Clear();
            198     }
            199 
            200     void BtnUp_Click(VL_Base* Sender)
            201     {
            202         ListBox->SetSelectedIndex(ListBox->GetSelectedIndex()-1);
            203     }
            204 
            205     void BtnDown_Click(VL_Base* Sender)
            206     {
            207         ListBox->SetSelectedIndex(ListBox->GetSelectedIndex()+1);
            208     }
            209 
            210 public:
            211 
            212     MyForm():VL_WinForm(true)
            213     {
            214         SetBorder(vwfbSingle);
            215         SetMaximizeBox(false);
            216         SetClientWidth(_ClientWidth);
            217         SetClientHeight(_ClientHeight);
            218         SetText(L"Vczh ListBox Control");
            219         MoveCenter();
            220         InitControls();
            221         Show();
            222     }
            223 };
            224 
            225 void main()
            226 {
            227     new MyForm;
            228     GetApplication()->Run();
            229 }

            posted on 2008-08-03 08:48 陳梓瀚(vczh) 閱讀(1972) 評論(8)  編輯 收藏 引用 所屬分類: C++

            評論:
            # re: 新增ListBox 2008-08-03 16:19 | foxtail
            有個庫叫VCL庫,不知道你知不知道  回復  更多評論
              
            # re: 新增ListBox 2008-08-03 18:47 | 陳梓瀚(vczh)
            VCL是我高中的時候連續用了三年的  回復  更多評論
              
            # re: 新增ListBox 2008-08-03 20:22 | 空明流轉
            VCL確實設計的不錯,不過那個東西要closure。。。  回復  更多評論
              
            # re: 新增ListBox 2008-08-03 21:55 | 亨德列克
            牛!  回復  更多評論
              
            # re: 新增ListBox[未登錄] 2008-08-04 01:22 | 小老虎
            還有個庫叫VCF。你用過沒有  回復  更多評論
              
            # re: 新增ListBox 2008-08-04 05:40 | Lnn
            恭喜!  回復  更多評論
              
            # re: 新增ListBox 2008-08-04 15:11 | foxtail
            VCF新的東西,呵呵!用法有點像WinForm@小老虎
              回復  更多評論
              
            # re: 新增ListBox 2008-08-24 16:51 | Strive
            史上最牛B  回復  更多評論
              
            久久99这里只有精品国产| 国产一区二区精品久久凹凸| 国产亚洲美女精品久久久| 国产精品美女久久久久| 久久久这里有精品| 亚洲人成无码久久电影网站| 久久精品18| 天天影视色香欲综合久久| 久久影视国产亚洲| 人妻中文久久久久| 香蕉久久夜色精品国产2020| 综合久久精品色| 伊人久久大香线蕉av不卡| av色综合久久天堂av色综合在| 久久亚洲sm情趣捆绑调教| 18岁日韩内射颜射午夜久久成人 | 久久精品国产99国产精品导航 | 精品国产乱码久久久久软件| 亚洲欧洲精品成人久久奇米网| 久久久久人妻精品一区三寸蜜桃 | 国产美女久久精品香蕉69| 国产亚洲欧美精品久久久| 女人香蕉久久**毛片精品| 99热都是精品久久久久久| 欧美久久亚洲精品| 国内精品久久久久影院薰衣草 | 1000部精品久久久久久久久| 亚洲成人精品久久| 久久综合九色综合久99| 精品综合久久久久久98| 久久国产精品久久精品国产| 久久精品亚洲精品国产欧美| 久久婷婷午色综合夜啪| 久久午夜羞羞影院免费观看| 亚洲精品高清国产一久久| 亚洲欧洲中文日韩久久AV乱码| 久久国产精品成人影院| 久久精品视频91| 国产精品18久久久久久vr| 亚洲国产精品嫩草影院久久| 久久AV高清无码|