加载一个对话框
int Dlg_rtn_id = DialogBox(h1, MAKEINTRESOURCE(DLG_ID), NULL, DlgProc);
编辑框 Edit Control
获取编辑框文本
GetDlgItemText(hwnd, EDIT_ID, str_buf, buf_len);
获取编辑框整形数字
int num = GetDlgItemInt(hwnd, EDIT_ID, NULL, TRUE);
设置编辑框文本
SetDlgItemText(hwnd, EDIT_ID, "string");
设置编辑框数字
SetDlgItemInt(hwnd, EDIT_ID, num, TRUE);
复选框控件 Check Box
获取复选框状态 (这里返回值只需要选中与未选中)
BOOL b = IsDlgButtonChecked(hwnd, CHECK_ID);
设置复选框状态
CheckDlgButton(hwnd, CHENK_ID, TRUE);
下拉式单选框 Combo Control
设置选项
SendMessage(COMBO_HWND, CB_ADDSTRING, 0, (LPARAM)"00001");
获取选中:同编辑框
滑动调节控件 slider control
设置范围
SendMessage(SLIDER_HWND, WM_USER + 6,(WPARAM)1, (LPARAM)MAKELONG(0, 100));
设置初始值
SendMessage(SLIDER_HWND, WM_USER + 5, (WPARAM)1, (LPARAM)20);
获取滑块位置
int num = (unsigned char)SendMessage(SLIDER_HWND, TBM_GETPOS, 0, 0);
持续更新拖动条并设置到进度条
主对话框函数:case WM_HSCROLL:
switch (LOWORD(wparam))
case SB_THUMBTRACK
SendMessage(GetDlgItem(hwnd, IDC_PROGRESS1), PBM_SETPOS, SendMessage(h, TBM_GETPOS, 0, 0), 0);
6.进度条 progress
设置范围
SendMessage(PROGRESS_HWND, WM_USER+1, 0, MAKELPARAM(0, 100));
更新进度
SendMessage(PROGRESS_HWND, PBM_SETPOS, 80, 0L);
设置进度块颜色
SendMessage(GetDlgItem(hwnd, IDC_PROGRESS1), PBM_SETBARCOLOR, 0, RGB(0,222,222));
设置进度块背景颜色
SendMessage(GetDlgItem(hwnd, IDC_PROGRESS1), PBM_SETBKCOLOR, 0, RGB(222, 111, 222));
7.列表框 list
添加新项目会(重新排序)
SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM)"string");
插入新项目(wparam为位置,-1表示添加到末尾)
SendMessage(h, LB_INSERTSTRING, -1, (LPARAM)buf);
删除所有项目
SendMessage(h, LB_RESETCONTENT, 0, 0);
列表listctrl
//添加新列标题
LV_COLUMN ls;
ls.fmt = LVCFMT_LEFT;//文本对齐方式 LVCFMT_RIGHT(右对齐)LVCFMT_CENTER(居中)
ls.cx = GetCX(HLIST)/6;//初始宽度范围
ls.mask = 1 | 2 | 4 ;//有效字段
ls.pszText = "第一列";//显示文本
ListView_InsertColumn(HLIST, 0, &ls);
ls.pszText = "第二例";
ListView_InsertColumn(HLIST, 1, &ls);
添加数据(首列)
LVITEM lv;
lv.iSubItem = 0;
lv.mask = LVIF_TEXT;
lv.iItem = 0;//列索引
lv.pszText = "第一行";
ListView_InsertItem(HLIST, &lv);
lv.iItem = 1;
lv.pszText = "第二行";
ListView_InsertItem(HLIST, &lv);
设置数据
LVITEM lv2;
lv2.mask = LVIF_TEXT;
lv2.iItem = 0;//行
lv2.iSubItem = 1;//列
lv2.pszText = "00";
ListView_SetItem(HLIST, &lv2);
lv2.iItem = 1;
lv2.iSubItem = 1;
lv2.pszText = "01";
ListView_SetItem(HLIST, &lv2);