首页 > 代码库 > Combo Box的简单使用(Win32)
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);//设置默认值
Combo Box的简单使用(Win32)