• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            MFC ComboBox 使用方法(轉載)

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

            MFC ComboBox 使用方法(轉載)


            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 使用方法(轉載)  回復  更多評論   

            2007-05-30 13:32 by
            @魔
            国产一区二区精品久久岳| 久久久精品午夜免费不卡| 99久久人人爽亚洲精品美女| 无码日韩人妻精品久久蜜桃| 国产成人综合久久精品红| 日本久久久久亚洲中字幕| 开心久久婷婷综合中文字幕| 成人午夜精品久久久久久久小说 | 狠狠色丁香久久婷婷综| 久久久久人妻一区二区三区vr| 亚洲国产精品综合久久一线| 久久综合偷偷噜噜噜色| 亚洲级αV无码毛片久久精品 | 久久er国产精品免费观看2| 久久久久久久久久久久中文字幕| 国产精品99久久99久久久| 久久久久中文字幕| Xx性欧美肥妇精品久久久久久| 久久99精品久久久久久秒播| 思思久久99热免费精品6| 97精品国产97久久久久久免费 | 中文国产成人精品久久不卡| 国产高潮久久免费观看| 国内精品久久久久久久coent| 久久香蕉国产线看观看猫咪?v| 一级a性色生活片久久无少妇一级婬片免费放 | 久久精品99久久香蕉国产色戒| 99久久精品九九亚洲精品| 久久午夜福利电影| 久久精品夜夜夜夜夜久久| 久久成人精品| 久久精品国产亚洲精品2020 | 区久久AAA片69亚洲| 国产精品久久亚洲不卡动漫| 久久经典免费视频| a级毛片无码兔费真人久久| 丁香色欲久久久久久综合网| 精品无码久久久久久久动漫| 久久天天躁狠狠躁夜夜网站| 久久精品国产亚洲av瑜伽| 久久综合九色综合久99|