Combo Box的简单使用(Win32)

1 SendMessage函数向窗口发送消息

LRESULT SendMessage(

HWND hWnd,     // handle to destination window

UINT Msg,      // message

WPARAM wParam, // first message parameter

LPARAM lParam   // second message parameter

);

2 向Combo Box添加数据

HWND hWndComboBox = GetDlgItem(hWnd, IDC_COMBO1);

TCHAR szMessage[20] = "Hello";

SendMessage(hWndComboBox , CB_ADDRSTRING, 0, (LPARAM)szMessage);

3 向Combo Box插入数据

HWND hWndComboBox = GetDlgItem(hWnd, IDC_COMBO1);

TCHAR szMessage[20] = "World";

SendMessage(hWndComboBox , CB_INSERTRSTRING, 0, (LPARAM)szMessage);

4 向Combo Box删除数据

SendMessage(hWndComboBox, CB_DELETESTRING, 1, 0);    //删除第二项数据

5 清除Combo Box所有数据

SendMessage(hWndComboBox, CB_RESETCONTENT, 0, 0);

6 获取Combo Box数据项目的数量

UINT uCount;

uCount = SendMessage(hWndComboBox, CB_GETCOUNT, 0, 0):

7 获取Combo Box某项的值

TCHAR szMessage[200];

ZeroMessage(szMessage, sizeof(szMessage)):

SendMessage(hWndComboBox, CB_GETLBTEXT, 1, (LPARAM)szMessage);    //获取第二项的数据

MessageBox(NULL, szMessage, " ", MB_OK);

-----------------

SendMessage(hWndcombo,CB_ADDSTRING,0,(LPARAM)"网通一区");//先用这个添加一条,然后再用下面的指定位置插入
SendMessage(hWndcombo,CB_INSERTSTRING,1,(LPARAM)"电信一区");
SendMessage(hWndcombo,CB_INSERTSTRING,2,(LPARAM)"电信二区");
SendMessage(hWndcombo,CB_SETCURSEL, 0, 0);//设置默认值

时间: 2024-08-24 17:01:38

Combo Box的简单使用(Win32)的相关文章

Win32程序中使用 Combo box控件

  SendMessage函数向窗口发送消息 LRESULT SendMessage( HWND hWnd,     // handle to destination window UINT Msg,      // message WPARAM wParam, // first message parameter LPARAM lParam   // second message parameter ); 1 向Combo Box添加数据 HWND hWndComboBox = GetDlgI

【转】VS2010/MFC编程入门之二十五(常用控件:组合框控件Combo Box)

原文网址:http://www.jizhuomi.com/software/189.html 上一节鸡啄米讲了列表框控件ListBox的使用,本节主要讲解组合框控件Combo Box.组合框同样相当常见,例如,在Windows系统的控制面板上设置语言或位置时,有很多选项,用来进行选择的控件就是组合框控件.它为我们的日常操作提供了很多方便. 组合框控件简介 组合框其实就是把一个编辑框和一个列表框组合到了一起,分为三种:简易(Simple)组合框.下拉式(Dropdown)组合框和下拉列表式(Dro

How to make a combo box with fulltext search autocomplete support?

I would like a user to be able to type in the second or third word from a TComboBoxitem and for that item to appear in the AutoSuggest dropdown options For example, a combo box contains the items: Mr John Brown Mrs Amanda Brown Mr Brian Jones Mrs Sam

Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layou

android无法静态显示ui效果. Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references. Failed to find style 'textViewStyle' in current theme 採用的解决方法例如以

下拉列表框Combo Box

Combo Box/Combo Box Ex 组合窗口是由一个输入框和一个列表框组成.创建一个组合窗口可以使用成员函数: BOOL CListBox::Create( LPCTSTR lpszText, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID = 0xffff ); 其中dwStyle将指明该窗口的风格,除了子窗口常用的风格WS_CHILD,WS_VISIBLE外,你可以针对列表控件指明专门的风格. · CBS_DR

WPF Combo box 获取选择的Tag

string str1 = ((ComboBoxItem)this.cboBoxRate1553B.Items[this.cboBoxRate1553B.SelectedIndex]).Tag.ToString(); string str2 = (this.cboBoxRate1553B.SelectedItem as ComboBoxItem).Tag.ToString(); 不知道为什么只能先转换为var 或者string类型,再转化为其他类型. I have a combo box lik

Check Box、Radio Button、Combo Box控件使用

Check Box.Radio Button.Combo Box控件使用 使用控件的方法 1.拖动控件到对话框 2. 定义控件对应的变量(值变量或者控件变量) 3.响应控件各种消息 Check Box(复选框) 设定几个复选框,绑定变量分别是:m_bProgram(编程).m_bFriend(交友).m_bRead(阅读).m_bSwim(游泳) 默认选择 m_bProgram=TRUE; m_bFriend=TRUE; 选择判断项是否被选中 Cstring result; if(m_bFrie

MFC 获取Combo Box控件 当前选定项的序号和文本内容

代码如下: CString text; // 选定项的文本内容 Combobox m_combobox; // 控件变量 int cindex= m_combobox.GetCurSel(); // 获取选定项的序号 m_combobox.GetLBText(cindex,text); // 获取选定项的文本内容 其中,m_combobox为Combo Box控件变量,可由右键控件添加变量.序号cindex是从0开始的,也就是获取Combox Box控件的第一个项的序号为0. 原文地址:http

VC++ COMBO BOX控件的使用

1.你在编辑状态下点那个控件的向下的三角形,就出冒出来一个可以调高度的东东.将高度调高,否则在执行时会不能显示下拉选项. 2.为combo box添加选项,在编辑状态下选combo box控件的属性,选Data标签,在编辑框中添加选项,按Ctrl-Enter来添加下一个选项. 3.为combo box添加变量 combo box有两个变量,CComboBox类变量和CString变量. CComboBox变量用来设置combo box的属性,一般在cdialog类中的oninitdialog()