700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 【C语言也能干大事】第五讲 组合框控件 下拉列表

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

时间:2023-06-20 17:46:55

相关推荐

【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;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。