#include
#include
#include
#include
#include
#include
#include
#define IDC_BOX1 100
#define IDC_BOX2 200
#define IDC_BOX3 300
#define IDC_BOX4 400
#define IDC_BOX5 500
#define IDC_SELECTED 600
static HWND hMainWnd = HWND_INVALID;
static void create_combobox (HWND parent)
{
int i;
HWND hwnd1, hwnd2, hwnd3, hwnd4;
char temp[20];
DIR* dir;
struct dirent* dir_ent;
hwnd1 = CreateWindow (CTRL_COMBOBOX,
"combobox",
WS_VISIBLE | CBS_DROPDOWNLIST | CBS_NOTIFY | CBS_READONLY,
IDC_BOX1,
10, 10, 180, 24,
parent, 100);
hwnd2 = CreateWindow (CTRL_COMBOBOX,
"combobox",
WS_VISIBLE | CBS_SPINLIST | WS_TABSTOP | CBS_SORT,
IDC_BOX2,
10, 40, 180, 24,
parent, 0);
hwnd3 = CreateWindow (CTRL_COMBOBOX,
"0",
WS_VISIBLE | CBS_AUTOSPIN | WS_TABSTOP,
IDC_BOX3,
10, 70, 180, 24,
parent, 0);
hwnd4 = CreateWindow (CTRL_COMBOBOX,
"0",
WS_VISIBLE | CBS_SIMPLE | CBS_SORT | WS_TABSTOP,
IDC_BOX4,
10, 100, 180, 24,
parent, 100);
dir = opendir ("./");
while ( (dir_ent = readdir ( dir )) != NULL ) {
SendMessage (hwnd1, CB_ADDSTRING, 0, (LPARAM)dir_ent->d_name);
SendMessage (hwnd4, CB_ADDSTRING, 0, (LPARAM)dir_ent->d_name);
}
closedir (dir);
for (i = 0; i < 1000; i++) {
sprintf (temp, "Welcome: %03d", i);
SendMessage (hwnd2, CB_ADDSTRING, 0, (LPARAM)temp);
}
}
static int ControlTestWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case MSG_CREATE:
create_combobox (hWnd);
CreateWindow (CTRL_STATIC,
"selected",
WS_CHILD | WS_VISIBLE | SS_SIMPLE,
IDC_SELECTED,
210, 10, 200, 25, hWnd, 0);
CreateWindow (CTRL_BUTTON,
"Close",
WS_CHILD | WS_VISIBLE,
IDCANCEL,
280, 200, 60, 25, hWnd, 0);
break;
case MSG_COMMAND:
{
int id = LOWORD(wParam);
int code = HIWORD(wParam);
char str [NAME_MAX + 20], file [NAME_MAX + 1];
int selected;
if (wParam == IDCANCEL) {
PostMessage (hWnd, MSG_CLOSE, 0, 0);
break;
}
switch (id) {
case IDC_BOX1:
if (code != CBN_SELCHANGE)
break;
selected = SendDlgItemMessage (hWnd, IDC_BOX1, CB_GETCURSEL,0,0);
if (selected >= 0) {
SendDlgItemMessage (hWnd, IDC_BOX1, CB_GETLBTEXT, selected, (LPARAM)file);
if (strlen (file)) {
sprintf (str, "Selected: %s", file);
SetDlgItemText (hWnd, IDC_SELECTED, str);
}
}
break;
}
}
break;
case MSG_DESTROY:
DestroyAllControls (hWnd);
hMainWnd = HWND_INVALID;
return 0;
case MSG_CLOSE:
DestroyMainWindow (hWnd);
MainWindowThreadCleanup (hWnd);
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_NONE;
pCreateInfo->spCaption = "ComboBox controls";
pCreateInfo->hMenu = 0;
pCreateInfo->hCursor = GetSystemCursor(IDC_ARROW);
pCreateInfo->hIcon = 0;
pCreateInfo->MainWindowProc = ControlTestWinProc;
pCreateInfo->lx = 0;
pCreateInfo->ty = 0;
pCreateInfo->rx = 400;
pCreateInfo->by = 280;
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);
}