创建一个标签
CreateWindowEx(0, "static", "姓名:",
WS_CHILD | WS_VISIBLE | SS_NOTIFY,
12, // xpos
414, // ypos
90, //width
21, //height
hwnd_frame, (HMENU)id_lbl_name, g_hInstance, NULL) ;
-
如果一个Static控件带上了SS_NOTIFY属性,则会在父窗口里响应STN_CLICKED、STN_DBLCLK、STN_DISABLE 和STN_ENABLE四种消息。
-
id_lbl_name 是一个整型数字,起到标识符的作用。
创建一个单行文本框
hwnd_t_name = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "这里可以输入初始内容",
WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL,
100, // xpos
410, // ypos
461, //width
21, //height
hwnd_frame, (HMENU)id_t_name, g_hInstance, NULL);
-
加上 ES_AUTOHSCROLL 属性,才能确保文本内容宽度超过文本框的宽度时,可以按键盘向右移动,达到显示全部内容的目地。
-
更新文本框内容
SetWindowText(hwnd_t_name, "abcdefg");
- 获取文本框内容
char name[1024];
GetWindowText(hwnd_t_name, name1024);
创建一个按钮
hwnd_b_source_folder = CreateWindowEx(0, "button", "选择...",
WS_CHILD | WS_VISIBLE, // | WS_DISABLED
571, // xpos
8, // ypos
96, //width
25, //height
hwnd_frame, (HMENU)id_b_source_folder, g_hInstance, NULL) ;
创建一个复选框
hwnd_ck_quality = CreateWindowEx(0, "button", "高",
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
21, // xpos
128, // ypos
68, //width
19, //height
hwnd_frame, (HMENU) id_ck_quality, g_hInstance, NULL);
-
其中 "button" + BS_AUTOCHECKBOX 表示为一个复选框
-
判断一个复选框是否选中
IsDlgButtonChecked(hwnd_frame, id_ck_quality)
创建一个下拉列表框
hwnd_c_image_quality = CreateWindowEx(0, "combobox", "Text",
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,
300, // xpos
69, // ypos
130, //width
300, //height
hwnd_frame, (HMENU)id_c_image_quality, g_hInstance, NULL);
- 给 combobox 添加一项
void combobox_add_item(HWND hwnd_combobox, char *text)
{
int index = (int)SendMessage(hwnd_combobox, CB_ADDSTRING, -1, (LPARAM)text);
if(index == 0)
{
SendMessage(hwnd_combobox, CB_SETCURSEL, index, 0);
}
}
- 添加一项到下拉列表框
combobox_add_item(hwnd_c_image_quality, "高");
combobox_add_item(hwnd_c_image_quality, "中");
combobox_add_item(hwnd_c_image_quality, "低");
- 设置当前选择的index
SendMessage(hwnd_c_image_quality, CB_SETCURSEL, 1, 0);
- 获取选择的index
LRESULT quanlity = SendMessage(GetDlgItem(hwnd_frame, id_c_image_quality), CB_GETCURSEL, 0, 0);
创建进度条
hwnd_progressbar = CreateWindowEx(0, "msctls_progress32", "",
WS_CHILD | WS_VISIBLE , // | WS_DISABLED
12, // xpos
451, // ypos
549, //width
21, //height
hwnd_frame, (HMENU)id_progressbar, g_hInstance, NULL) ;
- 初始化进度条的最小值和最大值
SendMessage(hwnd_progressbar, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
- 更新进度
SendMessage(hwnd_progressbar, PBM_SETPOS, 80, 0L);
- 重置进度条位置为0
SendMessage(hwnd_progressbar, PBM_SETPOS, 0, 0L);
创建一个WS_EX_TOOLWINDOW样式的窗口
hwnd_log_frame = CreateWindowEx(
WS_EX_TOOLWINDOW, /* Extended possibilites for variation */
"CodeBlocksWindowsApp", /* Classname */
"日志", /* Title Text */
WS_SYSMENU | WS_SIZEBOX, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
460, /* The programs width */
168, /* and height in pixels */
hwnd_parent, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
WS_EX_TOOLWINDOW,带有这个属性的窗口有以下特点:
- 不在任务栏显示。
- 不显示在Alt+Tab的切换列表中。
- 在任务管理器的窗口管理Tab中不显示。
- 标题栏没有图标,标题栏的高度很小,很特珠的一个窗口
创建一个无边框的窗口
hwnd_ad_window = CreateWindowEx(
0, /* Extended possibilites for variation */
"CodeBlocksWindowsApp", /* Classname */
"ad_window", /* Title Text */
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
400, /* The programs width */
16, /* and height in pixels */
hwnd_parent, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
评论区