【C语言也能干大事】第五讲 组合框控件,下拉列表

获得组合框控件的句柄
HWND hwndCombo1 = GetDlgItem(hwnd, IDC_COMBO1);

确定目前选项的索引
int curSel = ComboBox_GetCurSel(hwndCombo1);

删除项
ComboBox_DeleteString(hwndCombo1, 2);

取得有多少项
int getCount = ComboBox_GetCount(hwndCombo1);
TCHAR getcount[256];
itoa(getCount, getcount, 10);
MessageBox(hwnd, getcount, TEXT("总计有多少项"), MB_OK);

选定某项的值
ComboBox_SetCurSel(hwndCombo1, 2);

得到某项的值
TCHAR str[256];
ComboBox_GetLBText(hwndCombo1, 1, str);
MessageBox(hwnd, str, TEXT("得到选项的值为"), MB_OK);

添加内容:
ComboBox_AddtString(hwndComboOp, TEXT("+"));
ComboBox_InsertString(hwndComboOp, -1, TEXT("+"));


学生管理系统:

 

 
HWND hwndCombo1 = GetDlgItem(hwnd, IDC_COMBO1);
   switch(id)
  {
        case IDC_ADD:
	{
      TCHAR str1[256];
	  GetDlgItemText(hwnd, IDC_EDIT1, str1, sizeof(str1));
	  ComboBox_AddString(hwndCombo1, str1);
	  SetDlgItemText(hwnd, IDC_EDIT1, TEXT(""));
	}
        break;
	case IDC_DEL:
	{
	  int curSel = ComboBox_GetCurSel(hwndCombo1);
	  if (CB_ERR == curSel){
		MessageBox(hwnd, TEXT("没有任何项被选择"), TEXT("错误"), MB_OK | MB_ICONERROR);
	        return ;
          }
	  ComboBox_DeleteString(hwndCombo1, curSel);
	}
        break;
	case IDC_SER:
	{
	  TCHAR str2[256];
	   GetDlgItemText(hwnd, IDC_EDIT2, str2, sizeof(str2));
	   int icount = ComboBox_GetCount(hwndCombo1);
	   int i = 0;
	   BOOL bFound = FALSE;
	   for(i = 0; i < icount; i++){
		TCHAR str3[256];
		ComboBox_GetLBText(hwndCombo1, i, str3);
		if(lstrcmp(str2, str3) == 0){
			bFound = TRUE;
			ComboBox_SetCurSel(hwndCombo1, i);
		}
	  }
	  if(bFound){
		MessageBox(hwnd, TEXT("找到了"), TEXT("提示"), MB_OK);
	  }

     }
        break;

        default:
		break;
    }

转载于:https://www.cnblogs.com/wyqiang/p/3239763.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值