View Code
#include "stdafx.h" #include <windows.h> #include <windowsx.h> #include "resource.h" #include "MainDlg.h" BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog); HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand); HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose); } return FALSE; } BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { return TRUE; } void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) { HWND hwnd1 = GetDlgItem(hwnd,IDC_COMBO1); switch(id) { case IDC_ADD://添加按钮 { TCHAR str[256]; GetDlgItemText(hwnd,IDC_EDIT1,str,sizeof(str)); ComboBox_InsertString(hwnd1,-1,str); } break; case IDC_DELETE: //删除按钮 { //TCHAR str[256]; int ret = ComboBox_GetCurSel(hwnd1); ComboBox_DeleteString(hwnd1,ret); } break; case IDC_FIND://查找按钮,用一个循环查找是否匹配 { TCHAR str[256]; TCHAR strtemp[256]; BOOL select = false; GetDlgItemText(hwnd,IDC_EDIT2,str,sizeof(str)); for(int i = 0;i < ComboBox_GetCount(hwnd1);i++) { ComboBox_GetLBText(hwnd1,i,strtemp); if(strcmp(str,strtemp) == 0) { select = true; break; } else { continue; // } } if(select == true) { MessageBox(hwnd,TEXT("您选择的名字是在数据库中"),TEXT("正确"),MB_OK); } else { MessageBox(hwnd,TEXT("没有您要查找的名字"),TEXT("错误"),MB_OK); } } break; default: break; } } void Main_OnClose(HWND hwnd) { EndDialog(hwnd, 0); }
运行结果: