• <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>

            Tauruser

            Enjoy Every Day
            posts - 34, comments - 95, trackbacks - 0, articles - 5
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            MFC ComboBox 使用方法(轉(zhuǎn)載)

            Posted on 2007-02-28 10:29 Tauruser 閱讀(18748) 評(píng)論(1)  編輯 收藏 引用 所屬分類: MFC

            MFC ComboBox 使用方法(轉(zhuǎn)載)


            Combo box controls are space savers. Wherever there is no need for a multi-select from a list of items, combo box is a good choice in such places. This article " CComboBox Example" explains how to use the MFC CComboBox class for manipulation of a list of strings.

            CComboBox Example - Initializing a Combo Box:

            ?? It is assumed that the readers of the sample have already created a dialog box (either in a dialog based application or SDI/MDI application) and placed a combo box control from the controls toolbox on the Resource Editor.

            ?? After placing the combo box control on the dialog box, open the class wizard by pressing Ctrl + W keys or Menu --> View --> ClassWizard. In the Member Variables tab, Add a Variable for the CComboBox class. This CComboBox example assumes that the variable name is,

            ????? CComboBox? m_cbExample;

            ?? This m_cbExample will be used further in our CComboBox example MFC code.

            CComboBox Example - Adding Items to a Combo Box:

            ?? The function AddString is used for adding items to a combo box. If there is a constant set of data, these values can also be added in the Resource Editor itself. The Combo Box control properties dialog has a tab for adding data. Otherwise the data can be added as follows.

            ??? m_cbExample.AddString("StringData1");
            ??? m_cbExample.AddString("StringData2");
            ??? m_cbExample.AddString("StringData3");

            CComboBox Example - Retrieving Items from a Combo Box:

            ?? Usually
            a requirement for retrieving items from the combo box will arise from selecting the data. This article also assumes the same. Now the data selected in a combo box needs to be retrieved.

            ?? To do this, the first step is to find out the index of the selected item inside the combo box control.
            Then the item at the corresponding position needs to be pulled out as follows.


            ??? int nIndex = m_cbExample.GetCurSel();
            ??? CString strCBText;

            ??? m_cbExample.GetLBText(
            nIndex, strCBText);


            ?? In the above CComboBox example code, the value will be retrieved and stored in strCBText variable. There is another overloaded version for GetLBText. But the version which uses CString is the easiest one.


            CComboBox Example - Finding Items inside a Combo Box:


            ?? This kind of Find operations on a Combo box will most probably be useful in programs that dynamically modify the values in a combo box. The function FindStringExact is used to find the exact string match inside a combo box.


            ??? int nIndex = m_cbExample.FindStringExact(0, "Value to be found");

            ?? The string position inside the combo box control is the return value. It returns CB_ERR if it was unsuccessful in finding the string.


            CComboBox Example - Deleting Items from a Combo Box:


            ??? This operation can be done by using the CCombobox member function DeleteString. This function needs the index of the item inside the combo box.


            ???? m_cbExample
            .DeleteString(nIndex);

            Feedback

            # re: MFC ComboBox 使用方法(轉(zhuǎn)載)  回復(fù)  更多評(píng)論   

            2007-05-30 13:32 by
            @魔
            2020最新久久久视精品爱| 久久福利青草精品资源站免费| 久久久久亚洲爆乳少妇无| 久久WWW免费人成—看片| 天天综合久久一二三区| 漂亮人妻被黑人久久精品| 久久不射电影网| 免费无码国产欧美久久18| 国产精品18久久久久久vr| 久久se精品一区精品二区国产| 99久久精品免费看国产一区二区三区 | 久久久久亚洲AV无码网站| 精品久久久久一区二区三区| 久久无码专区国产精品发布| 久久综合九色综合精品| 亚洲伊人久久精品影院| 久久精品国产一区二区三区不卡| 日产精品久久久久久久性色| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 久久成人国产精品| 久久福利资源国产精品999| 好属妞这里只有精品久久| 久久人人爽人人爽人人片AV东京热 | 久久丫精品国产亚洲av| 亚洲七七久久精品中文国产| 国产精品久久久久久久久鸭| 久久人人爽人人爽人人片AV不| 伊人热热久久原色播放www| 国产福利电影一区二区三区久久久久成人精品综合 | 亚洲av伊人久久综合密臀性色| 免费一级欧美大片久久网| 久久噜噜电影你懂的| 日韩乱码人妻无码中文字幕久久| 久久精品国产精品亚洲下载| 国产精品日韩欧美久久综合| 久久中文娱乐网| 91精品国产色综久久| 一本久久久久久久| 久久精品国产秦先生| 9191精品国产免费久久| 国产精品狼人久久久久影院|