www.pudn.com > 嵌入式linux9应用开发祥解.rar > combobox.c
#include#include #include #include #include #include #include #include #define IDC_CTRL1 100 #define IDC_CTRL2 110 #define IDC_CTRL3 120 #define IDC_CTRL4 130 #define IDC_CTRL5 140 static HWND hMainWnd = HWND_INVALID; static int ControlTestWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) { int i; static HWND hChildWnd1, hChildWnd2, hChildWnd3,hChildWnd4,hChildWnd5; char temp[20]; switch (message) { case MSG_CREATE: hChildWnd5 = CreateWindow ("BUTTON", "OK", WS_CHILD | WS_VISIBLE, IDC_CTRL5, 200, 180, 40, 25, hWnd, 0); hChildWnd1 = CreateWindow ("COMBOBOX", "combobox", WS_CHILD | CBS_DROPDOWNLIST | WS_VISIBLE, IDC_CTRL1, 30, 12, 110, 24, hWnd, (DWORD)150);//150为Listbox的高度 hChildWnd2 = CreateWindow ("COMBOBOX", "", WS_CHILD| CBS_DROPDOWNLIST | WS_VISIBLE, IDC_CTRL2, 30, 180, 110, 24, hWnd, (DWORD)90);//90为Listbox的高度 hChildWnd3 = CreateWindow ("COMBOBOX", "", WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST, IDC_CTRL3, 30, 140, 110, 24, hWnd,0); hChildWnd4 = CreateWindow ("EDIT", "ComBoBox Test", WS_CHILD | WS_BORDER | WS_VISIBLE, IDC_CTRL4, 200, 30, 80, 30, hWnd, 0); for(i=0;i<20;i++) { sprintf(temp,"%d-Welcome",i); SendMessage(hChildWnd1,CB_ADDSTRING,0,(LPARAM)temp) ; SendMessage(hChildWnd2,CB_ADDSTRING,0,(LPARAM)temp) ; SendMessage(hChildWnd3,CB_ADDSTRING,0,(LPARAM)temp) ; } break; case MSG_COMMAND: { int id = LOWORD(wParam); int code = HIWORD(wParam); char str[151]; int i; switch (id) { case IDC_CTRL1: if(code!=CBN_SELCHANGE) break; i=SendMessage(hChildWnd1,CB_GETCURSEL,0,0); if(i>=0) { SendMessage(hChildWnd1,CB_GETLBTEXT,i,(LPARAM)str); if(strlen(str)) SetWindowText(hChildWnd4,str); } break; case IDC_CTRL2: break; case IDC_CTRL3: { break; } default: break; } } break; case MSG_CLOSE: DestroyMainWindow (hWnd); MainWindowCleanup (hWnd); hMainWnd = HWND_INVALID; return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam); } static void InitCreateInfo(PMAINWINCREATE pCreateInfo) { pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE; pCreateInfo->dwExStyle = WS_EX_IMECOMPOSE; pCreateInfo->spCaption = "ComboBox control" ; pCreateInfo->hMenu = 0; pCreateInfo->hCursor = GetSystemCursor(IDC_ARROW); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = ControlTestWinProc; pCreateInfo->lx = 0; pCreateInfo->ty = 0; pCreateInfo->rx = 320; pCreateInfo->by = 240; pCreateInfo->iBkColor = GetWindowElementColor (BKC_CONTROL_DEF); pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = HWND_DESKTOP; } void combobox_demo (HWND hwnd) { MAINWINCREATE CreateInfo; if (hMainWnd != HWND_INVALID) { ShowWindow (hMainWnd, SW_SHOWNORMAL); return; } InitCreateInfo (&CreateInfo); CreateInfo.hHosting = hwnd; hMainWnd = CreateMainWindow (&CreateInfo); }