#include "stdafx.h" #include <windows.h> #include <windowsx.h> #include "resource.h" #include "MainDlg.h" struct book { TCHAR name[256]; long phone; long qq; }; struct book pre; struct book * p; 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) { switch(id) { case IDC_OK: { HWND combox_handle_1=GetDlgItem(hwnd,IDC_COMBO1); HWND combox_handle_2=GetDlgItem(hwnd,IDC_COMBO2); HWND combox_handle_3=GetDlgItem(hwnd,IDC_COMBO3); int index_1=ComboBox_GetCurSel(combox_handle_1); int index_2=ComboBox_GetCurSel(combox_handle_2); int index_3=ComboBox_GetCurSel(combox_handle_2); p=⪯ TCHAR qq_temp[20]; TCHAR phone_temp[20]; wsprintf(qq_temp,"%i",pre.qq); wsprintf(phone_temp,"%i",pre.phone); init(); GetDlgItemText(hwnd,IDC_EDIT1,pre.name,sizeof(pre.name)); GetDlgItemText(hwnd,IDC_EDIT2,phone_temp,sizeof(phone_temp)); GetDlgItemText(hwnd,IDC_EDIT3,qq_temp,sizeof(qq_temp)); ComboBox_InsertString(combox_handle_1,-1,p->name); ComboBox_InsertString(combox_handle_2,-1,phone_temp); ComboBox_InsertString(combox_handle_3,-1,qq_temp); SetDlgItemText(hwnd,IDC_EDIT1,""); SetDlgItemText(hwnd,IDC_EDIT2,""); SetDlgItemText(hwnd,IDC_EDIT3,""); if(index_1==1) { TCHAR str[256]; ComboBox_GetLBText(combox_handle_2,index_1,str); ComboBox_GetLBText(combox_handle_2,index_1,qq_temp); } } break; case IDC_BUTTON7: { HWND combox_handle_1=GetDlgItem(hwnd,IDC_COMBO1); HWND combox_handle_2=GetDlgItem(hwnd,IDC_COMBO2); HWND combox_handle_3=GetDlgItem(hwnd,IDC_COMBO3); int index_1=ComboBox_GetCurSel(combox_handle_1); int index_2=ComboBox_GetCurSel(combox_handle_2); int index_3=ComboBox_GetCurSel(combox_handle_2); int i; int count=ComboBox_GetCount(combox_handle_1); for(i=0;i<count;i++) { if(i==ComboBox_GetCurSel(combox_handle_1)) { ComboBox_SetCurSel(combox_handle_2,i); ComboBox_SetCurSel(combox_handle_3,i); } } } break; case IDC_BUTTON2: { HWND combox_handle_1=GetDlgItem(hwnd,IDC_COMBO1); HWND combox_handle_2=GetDlgItem(hwnd,IDC_COMBO2); HWND combox_handle_3=GetDlgItem(hwnd,IDC_COMBO3); int index_1=ComboBox_GetCurSel(combox_handle_1); int index_2=ComboBox_GetCurSel(combox_handle_2); int index_3=ComboBox_GetCurSel(combox_handle_2); if(CB_ERR==index_1) { MessageBox(hwnd,TEXT("没有项了"),TEXT("错误"),MB_OK|MB_ICONWARNING); } ComboBox_DeleteString(combox_handle_1,index_1); ComboBox_DeleteString(combox_handle_2,index_2); ComboBox_DeleteString(combox_handle_3,index_3); } break; case IDC_BUTTON5: { HWND combox_handle_1=GetDlgItem(hwnd,IDC_COMBO1); HWND combox_handle_2=GetDlgItem(hwnd,IDC_COMBO2); HWND combox_handle_3=GetDlgItem(hwnd,IDC_COMBO3); int index_1=ComboBox_GetCurSel(combox_handle_1); int index_2=ComboBox_GetCurSel(combox_handle_2); int index_3=ComboBox_GetCurSel(combox_handle_2); TCHAR strserch[256]; GetDlgItemText(hwnd,IDC_EDIT4,strserch,sizeof(strserch)); SetDlgItemText(hwnd,IDC_EDIT4,""); int i; TCHAR str[256]; int count=ComboBox_GetCount(combox_handle_1); bool found=FALSE; for(i=0;i<count;i++) { ComboBox_GetLBText(combox_handle_1,i,str); if(strcmp(str,strserch)==0) { found=TRUE; ComboBox_SetCurSel(combox_handle_1,i); } } } break; default: break; } } void Main_OnClose(HWND hwnd) { EndDialog(hwnd, 0); }