• <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  評(píng)論-2670  文章-0  trackbacks-0
                封裝Common Control Library 6.0的API越來越順手了。雖說要消滅BEGIN_MESSAGE_MAP之類的代碼,不過寫起來也不容易。BEGIN_MESSAGE_MAP不能動(dòng)態(tài)替換,所以我換成了類似C#的Event和Delegate那樣子的東西。如果不需要?jiǎng)討B(tài)替換的話,實(shí)際上并沒有什么大的區(qū)別,唯一的區(qū)別就在于你可以利用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"請(qǐng)?jiān)诹斜碇羞x中一項(xiàng)。");
             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"請(qǐng)?jiān)诹斜碇羞x中一項(xiàng)。");
            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"請(qǐng)?jiān)诹斜碇羞x中一項(xiàng)。");
            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"請(qǐng)?jiān)诹斜碇羞x中一項(xiàng)。");
            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"請(qǐng)?jiān)诹斜碇羞x中一項(xiàng)。");
            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) 閱讀(1977) 評(píng)論(8)  編輯 收藏 引用 所屬分類: C++

            評(píng)論:
            # re: 新增ListBox 2008-08-03 16:19 | foxtail
            有個(gè)庫叫VCL庫,不知道你知不知道  回復(fù)  更多評(píng)論
              
            # re: 新增ListBox 2008-08-03 18:47 | 陳梓瀚(vczh)
            VCL是我高中的時(shí)候連續(xù)用了三年的  回復(fù)  更多評(píng)論
              
            # re: 新增ListBox 2008-08-03 20:22 | 空明流轉(zhuǎn)
            VCL確實(shí)設(shè)計(jì)的不錯(cuò),不過那個(gè)東西要closure。。。  回復(fù)  更多評(píng)論
              
            # re: 新增ListBox 2008-08-03 21:55 | 亨德列克
            # re: 新增ListBox[未登錄] 2008-08-04 01:22 | 小老虎
            還有個(gè)庫叫VCF。你用過沒有  回復(fù)  更多評(píng)論
              
            # re: 新增ListBox 2008-08-04 05:40 | Lnn
            恭喜!  回復(fù)  更多評(píng)論
              
            # re: 新增ListBox 2008-08-04 15:11 | foxtail
            VCF新的東西,呵呵!用法有點(diǎn)像WinForm@小老虎
              回復(fù)  更多評(píng)論
              
            # re: 新增ListBox 2008-08-24 16:51 | Strive
            史上最牛B  回復(fù)  更多評(píng)論
              
            亚洲色欲久久久久综合网| 亚洲美日韩Av中文字幕无码久久久妻妇| 久久综合综合久久综合| 亚洲精品无码久久一线| 丁香五月网久久综合| 88久久精品无码一区二区毛片| 欧美午夜A∨大片久久| 亚洲精品无码久久千人斩| 国产精品久久久久影院色| 一本色道久久88综合日韩精品 | 久久91精品国产91久久小草| 伊人色综合久久| 成人午夜精品无码区久久| 亚洲成色999久久网站| 成人午夜精品无码区久久| 久久精品国产欧美日韩| 久久久久亚洲av无码专区喷水| 狠狠色综合久久久久尤物| 亚洲国产精品无码久久久蜜芽 | 国产精品久久久久乳精品爆| 日韩精品无码久久一区二区三| 粉嫩小泬无遮挡久久久久久| 亚洲精品NV久久久久久久久久| 免费精品99久久国产综合精品| 久久亚洲欧美国产精品| 99精品国产免费久久久久久下载 | 91精品无码久久久久久五月天 | 伊人伊成久久人综合网777| 91精品国产高清久久久久久国产嫩草 | 久久99精品久久久大学生| 久久国产成人午夜aⅴ影院| 99re久久精品国产首页2020| 18岁日韩内射颜射午夜久久成人| 欧美日韩成人精品久久久免费看| 精品久久久久久国产| 国内精品久久久久伊人av| 性欧美丰满熟妇XXXX性久久久| 亚洲欧洲久久av| 欧美成人免费观看久久| 一级女性全黄久久生活片免费| 亚洲伊人久久综合中文成人网|