- //学生管理系统:
- #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)
- {
- HWND hwndcombo1=GetDlgItem(hwnd,IDC_COMBO1);
- ComboBox_InsertString(hwndcombo1,-1,"张三");
- ComboBox_InsertString(hwndcombo1,-1,"李四");
- ComboBox_InsertString(hwndcombo1,-1,"王五");
- return TRUE;
- }
- void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
- {
- switch(id)
- {
- case IDC_OK:
- {
- HWND hwndcombo1=GetDlgItem(hwnd,IDC_COMBO1);
- ComboBox_SetCurSel(hwndcombo1,0);
- }
- break;
- case IDC_BUTTON1zj:
- {
- HWND hwndcombo1=GetDlgItem(hwnd,IDC_COMBO1);
- TCHAR str1[256];
- GetDlgItemText(hwnd,IDC_EDIT2,str1,sizeof(str1));
- int s=strlen(str1);
- if(0==s)
- {
- MessageBox(hwnd,TEXT("输入不合法!"),TEXT("警告"),MB_OK|MB_ICONERROR);
- return;
- }
- ComboBox_InsertString(hwndcombo1,-1,str1);
- SetDlgItemText(hwnd,IDC_EDIT2,NULL);
- }
- break;
- case IDC_BUTTON2shch:
- {
- HWND hwndcombo1=GetDlgItem(hwnd,IDC_COMBO1);
- int i2=ComboBox_GetCurSel(hwndcombo1);
- if(CB_ERR==i2)
- {
- MessageBox(hwnd,TEXT("输入不合法!"),TEXT("警告"),MB_OK|MB_ICONERROR);
- return;
- }
- ComboBox_DeleteString(hwndcombo1,i2);
- }
- break;
- case IDC_BUTTON3chzh:
- {
- HWND hwndcombo1=GetDlgItem(hwnd,IDC_COMBO1);
- TCHAR str2[256];
- GetDlgItemText(hwnd,IDC_EDIT2,str2,sizeof(str2));
- int i3=ComboBox_GetCount(hwndcombo1);
- int i=0;
- BOOL Found=FALSE;
- for(i=0;i<=i3;i++)
- {
- TCHAR str3[256];
- ComboBox_GetLBText(hwndcombo1,i,str3);
- if(lstrcmp(str2,str3)==0)
- {
- Found=TRUE;
- ComboBox_SetCurSel(hwndcombo1,i);
- }
- }
- if(Found)
- {
- MessageBox(hwnd,TEXT("找到了"),TEXT("哈哈"),MB_OK);
- }
- if(Found==0)
- {
- MessageBox(hwnd,TEXT("找不到该项"),TEXT("呜呜"),MB_OK);
- }
- }
- break;
- default:
- break;
- }
- }
- void Main_OnClose(HWND hwnd)
- {
- EndDialog(hwnd, 0);
- }