单选钮和复选框控件的应用教案_在mfc中弹出一个窗口

单选钮和复选框控件的应用教案_在mfc中弹出一个窗口单选按钮#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);HINSTANCE hInst;int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

单选按钮

#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst;
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow
){ 

static TCHAR szClassName[] = TEXT("Win32Demo");  //窗口类名
HWND     hwnd;  //窗口句柄
MSG      msg;  //消息
WNDCLASS wndclass;  //窗口类
hInst = hInstance;
/**********第①步:注册窗口类**********/
//为窗口类的各个字段赋值
wndclass.style = CS_HREDRAW | CS_VREDRAW;  //窗口风格
wndclass.lpfnWndProc  = WndProc;  //窗口过程
wndclass.cbClsExtra   = 0;  //暂时不需要理解
wndclass.cbWndExtra   = 0;  //暂时不需要理解
wndclass.hInstance    = hInstance;  //当前窗口句柄
wndclass.hIcon        = LoadIcon (NULL, IDI_APPLICATION);  //窗口图标
wndclass.hCursor      = LoadCursor (NULL, IDC_ARROW);  //鼠标样式
wndclass.hbrBackground= (HBRUSH) GetSysColorBrush(COLOR_BTNFACE);  //窗口背景画刷(灰色)
wndclass.lpszMenuName = NULL ;  //窗口菜单
wndclass.lpszClassName= szClassName;  //窗口类名
//注册窗口
RegisterClass(&wndclass);
/*****第②步:创建窗口(并让窗口显示出来)*****/
hwnd = CreateWindow(
szClassName,  //窗口名字
TEXT("Welcome"),  //窗口标题(出现在标题栏)
WS_OVERLAPPEDWINDOW,  //窗口风格
CW_USEDEFAULT,  //初始化时x轴的位置
CW_USEDEFAULT,  //初始化时y轴的位置
500,  //窗口宽度
300,  //窗口高度
NULL,  //父窗口句柄
NULL,  //窗口菜单句柄
hInstance,  //当前窗口的句柄
NULL  //不使用该值
);
//显示窗口
ShowWindow (hwnd, iCmdShow);
//更新(绘制)窗口
UpdateWindow (hwnd);
/**********第③步:消息循环**********/
while( GetMessage(&msg, NULL, 0, 0) ){ 

TranslateMessage(&msg);  //翻译消息
DispatchMessage (&msg);  //分派消息
}
return msg.wParam;
}
//窗口过程
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ 

PAINTSTRUCT ps;
HDC hdc;
static HFONT hFont;  //逻辑字体
//一组单选按钮
static HWND labSex;  //静态文本框--性别
static HWND radioMale;  //单选按钮--男
static HWND radioFemale;  //单选按钮--女
//一组单选按钮
static HWND labMarriage;  //静态文本框--婚姻状况
static HWND radioMarried;  //单选按钮--已婚
static HWND radioSingle;  //单选按钮--未婚
static HWND radioSecrecy;  //单选按钮--保密
//一组复选框
static HWND labPet;  //静态文本框--你的宠物
static HWND checkboxDog;  //复选框--狗
static HWND checkboxCat;  //复选框--猫
static HWND checkboxFish;  //复选框--鱼
static HWND checkboxOther;  //复选框--其他
switch (message){ 

case  WM_CREATE:
hFont = CreateFont(
-14, -7, 0, 0, 400,
FALSE, FALSE, FALSE,DEFAULT_CHARSET,
OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY,
FF_DONTCARE, TEXT("微软雅黑")
);
//选择性别
labSex = CreateWindow(
TEXT("static"), TEXT("你的性别:"),
WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE | SS_RIGHT/*文字居右*/,
10, 10, 80, 26,
hWnd, (HMENU)1, hInst, NULL
);
radioMale = CreateWindow(
TEXT("button"), TEXT("男"),
WS_CHILD | WS_VISIBLE | BS_LEFT/*文字居左*/ | BS_AUTORADIOBUTTON /*单选按钮*/ | WS_GROUP,
95, 10, 50, 26,
hWnd, (HMENU)2, hInst, NULL
);
radioFemale = CreateWindow(
TEXT("button"), TEXT("女"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON,
150, 10, 50, 26,
hWnd, (HMENU)2, hInst, NULL
);
//选择婚姻状况
labMarriage = CreateWindow(
TEXT("static"), TEXT("婚姻状况:"),
WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE | SS_RIGHT,
10, 40, 80, 26,
hWnd, (HMENU)4, hInst, NULL
);
radioMarried = CreateWindow(
TEXT("button"), TEXT("已婚"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON | WS_GROUP,
95, 40, 65, 26,
hWnd, (HMENU)5, hInst, NULL
);
radioSingle = CreateWindow(
TEXT("button"), TEXT("未婚"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON,
165, 40, 65, 26,
hWnd, (HMENU)6, hInst, NULL
);
radioSecrecy = CreateWindow(
TEXT("button"), TEXT("保密"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON,
235, 40, 100, 26,
hWnd, (HMENU)7, hInst, NULL
);
//你的宠物
labPet = CreateWindow(
TEXT("static"), TEXT("你的宠物:"),
WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE | SS_RIGHT,
10, 70, 80, 26,
hWnd, (HMENU)8, hInst, NULL
);
checkboxDog = CreateWindow(
TEXT("button"), TEXT("狗"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX/*复选框*/,
95, 70, 50, 26,
hWnd, (HMENU)9, hInst, NULL
);
checkboxCat = CreateWindow(
TEXT("button"), TEXT("猫"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX,
150, 70, 50, 26,
hWnd, (HMENU)10, hInst, NULL
);
checkboxFish = CreateWindow(
TEXT("button"), TEXT("鱼"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX,
205, 70, 50, 26,
hWnd, (HMENU)11, hInst, NULL
);
checkboxOther = CreateWindow(
TEXT("button"), TEXT("其他"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX,
260, 70, 65, 26,
hWnd, (HMENU)11, hInst, NULL
);
SendMessage(labSex, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(radioMale, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(radioFemale, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(labMarriage, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(radioMarried, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(radioSingle, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(radioSecrecy, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(labPet, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(checkboxDog, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(checkboxCat, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(checkboxFish, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(checkboxOther, WM_SETFONT, (WPARAM)hFont, NULL);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

分组框控件

#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst;
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow
){ 

static TCHAR szClassName[] = TEXT("Win32Demo");  //窗口类名
HWND     hwnd;  //窗口句柄
MSG      msg;  //消息
WNDCLASS wndclass;  //窗口类
hInst = hInstance;
/**********第①步:注册窗口类**********/
//为窗口类的各个字段赋值
wndclass.style = CS_HREDRAW | CS_VREDRAW;  //窗口风格
wndclass.lpfnWndProc  = WndProc;  //窗口过程
wndclass.cbClsExtra   = 0;  //暂时不需要理解
wndclass.cbWndExtra   = 0;  //暂时不需要理解
wndclass.hInstance    = hInstance;  //当前窗口句柄
wndclass.hIcon        = LoadIcon (NULL, IDI_APPLICATION);  //窗口图标
wndclass.hCursor      = LoadCursor (NULL, IDC_ARROW);  //鼠标样式
wndclass.hbrBackground= (HBRUSH) GetSysColorBrush(COLOR_BTNFACE);  //窗口背景画刷(灰色)
wndclass.lpszMenuName = NULL ;  //窗口菜单
wndclass.lpszClassName= szClassName;  //窗口类名
//注册窗口
RegisterClass(&wndclass);
/*****第②步:创建窗口(并让窗口显示出来)*****/
hwnd = CreateWindow(
szClassName,  //窗口名字
TEXT("Welcome"),  //窗口标题(出现在标题栏)
WS_OVERLAPPEDWINDOW,  //窗口风格
CW_USEDEFAULT,  //初始化时x轴的位置
CW_USEDEFAULT,  //初始化时y轴的位置
800,  //窗口宽度
500,  //窗口高度
NULL,  //父窗口句柄
NULL,  //窗口菜单句柄
hInstance,  //当前窗口的句柄
NULL  //不使用该值
);
//显示窗口
ShowWindow (hwnd, iCmdShow);
//更新(绘制)窗口
UpdateWindow (hwnd);
/**********第③步:消息循环**********/
while( GetMessage(&msg, NULL, 0, 0) ){ 

TranslateMessage(&msg);  //翻译消息
DispatchMessage (&msg);  //分派消息
}
return msg.wParam;
}
//窗口过程
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ 

PAINTSTRUCT ps;
HDC hdc;
static HFONT hFont;  //逻辑字体
//一组单选按钮--性别
static HWND hGroupSex;  //GroupBox 控件
static HWND hRadioMale;  //单选按钮--男
static HWND hRadioFemale;  //单选按钮--女
//一组单选按钮--婚姻状况
static HWND hGroupMarriage;
static HWND hRadioMarried;  //单选按钮--已婚
static HWND hRadioSingle;  //单选按钮--未婚
static HWND hRadioSecrecy;  //单选按钮--保密
//一组复选框--宠物
static HWND hGroupPet;
static HWND hCheckboxDog;  //复选框--狗
static HWND hCheckboxCat;  //复选框--猫
static HWND hCheckboxFish;  //复选框--鱼
static HWND hCheckboxOther;  //复选框--其他
switch (message){ 

case  WM_CREATE:
//创建字体
hFont = CreateFont(
-14, -7, 0, 0, 400,
FALSE, FALSE, FALSE,DEFAULT_CHARSET,
OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY,
FF_DONTCARE, TEXT("微软雅黑")
);
//一组单选按钮--性别
hGroupSex = CreateWindow(
TEXT("button"), TEXT("你的性别"),
WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
20, 20, 300, 70,
hWnd, (HMENU)1, hInst, NULL
);
hRadioMale = CreateWindow(
TEXT("button"), TEXT("男"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON /*单选按钮*/,
15, 30, 50, 26,
hGroupSex /*父窗口为 GroupBox 控件*/, (HMENU)2, hInst, NULL
);
hRadioFemale = CreateWindow(
TEXT("button"), TEXT("女"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON,
80, 30, 50, 26,
hGroupSex, (HMENU)3, hInst, NULL
);
//一组单选按钮--婚姻状况
hGroupMarriage = CreateWindow(
TEXT("button"), TEXT("婚姻状况"),
WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
20, 120, 300, 70,
hWnd, (HMENU)4, hInst, NULL
);
hRadioMarried = CreateWindow(
TEXT("button"), TEXT("已婚"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON,
15, 30, 50, 26,
hGroupMarriage, (HMENU)5, hInst, NULL
);
hRadioSingle = CreateWindow(
TEXT("button"), TEXT("未婚"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON,
80, 30, 50, 26,
hGroupMarriage, (HMENU)6, hInst, NULL
);
hRadioSecrecy = CreateWindow(
TEXT("button"), TEXT("保密"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON,
145, 30, 50, 26,
hGroupMarriage, (HMENU)7, hInst, NULL
);
//一组复选框--宠物
hGroupPet = CreateWindow(
TEXT("button"), TEXT("你的宠物"),
WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
20, 220, 300, 70,
hWnd, (HMENU)8, hInst, NULL
);
hCheckboxDog = CreateWindow(
TEXT("button"), TEXT("狗"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX /*复选框*/,
15, 30, 50, 26,
hGroupPet, (HMENU)9, hInst, NULL
);
hCheckboxCat = CreateWindow(
TEXT("button"), TEXT("猫"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX,
80, 30, 50, 26,
hGroupPet, (HMENU)10, hInst, NULL
);
hCheckboxFish = CreateWindow(
TEXT("button"), TEXT("鱼"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX,
145, 30, 50, 26,
hGroupPet, (HMENU)11, hInst, NULL
);
hCheckboxOther = CreateWindow(
TEXT("button"), TEXT("其他"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX,
210, 30, 65, 26,
hGroupPet, (HMENU)12, hInst, NULL
);
//依次设置控件字体
SendMessage(hGroupSex, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hRadioMale, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hRadioFemale, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hGroupMarriage, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hRadioMarried, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hRadioSingle, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hRadioSecrecy, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hGroupPet, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hCheckboxDog, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hCheckboxCat, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hCheckboxFish, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(hCheckboxOther, WM_SETFONT, (WPARAM)hFont, NULL);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

复选框

/* tab 选项卡 SysTabControl32 listbox 列表框 ListBox progress 进度条 msctls_progress32 ScrollBar 滚动条 ScrollBar listview 列表视图 SysListView32 treeview 树状图 SysTreeView32 updown 滚动选框 msctls_updown32 */
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst;
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow
){ 

static TCHAR szClassName[] = TEXT("Win32Demo");  //窗口类名
HWND     hwnd;  //窗口句柄
MSG      msg;  //消息
WNDCLASS wndclass;  //窗口类
hInst = hInstance;
/**********第①步:注册窗口类**********/
//为窗口类的各个字段赋值
wndclass.style = CS_HREDRAW | CS_VREDRAW;  //窗口风格
wndclass.lpfnWndProc  = WndProc;  //窗口过程
wndclass.cbClsExtra   = 0;  //暂时不需要理解
wndclass.cbWndExtra   = 0;  //暂时不需要理解
wndclass.hInstance    = hInstance;  //当前窗口句柄
wndclass.hIcon        = LoadIcon (NULL, IDI_APPLICATION);  //窗口图标
wndclass.hCursor      = LoadCursor (NULL, IDC_ARROW);  //鼠标样式
wndclass.hbrBackground= (HBRUSH) GetSysColorBrush(COLOR_BTNFACE);  //窗口背景画刷(灰色)
wndclass.lpszMenuName = NULL ;  //窗口菜单
wndclass.lpszClassName= szClassName;  //窗口类名
//注册窗口
RegisterClass(&wndclass);
/*****第②步:创建窗口(并让窗口显示出来)*****/
hwnd = CreateWindow(
szClassName,  //窗口名字
TEXT("Welcome"),  //窗口标题(出现在标题栏)
WS_OVERLAPPEDWINDOW,  //窗口风格
CW_USEDEFAULT,  //初始化时x轴的位置
CW_USEDEFAULT,  //初始化时y轴的位置
800,  //窗口宽度
500,  //窗口高度
NULL,  //父窗口句柄
NULL,  //窗口菜单句柄
hInstance,  //当前窗口的句柄
NULL  //不使用该值
);
//显示窗口
ShowWindow (hwnd, iCmdShow);
//更新(绘制)窗口
UpdateWindow (hwnd);
/**********第③步:消息循环**********/
while( GetMessage(&msg, NULL, 0, 0) ){ 

TranslateMessage(&msg);  //翻译消息
DispatchMessage (&msg);  //分派消息
}
return msg.wParam;
}
//窗口过程
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ 

int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
//设置缓冲区
static TCHAR szBufSex[10];
static TCHAR szBufMarriage[10];
static TCHAR szBufPet[20];
static TCHAR szBufSubmit[100];
static TCHAR szBufTmp[10];
static HFONT hFont;  //逻辑字体
//一组单选按钮
static HWND labSex;  //静态文本框--性别
static HWND radioMale;  //单选按钮--男
static HWND radioFemale;  //单选按钮--女
//一组单选按钮
static HWND labMarriage;  //静态文本框--婚姻状况
static HWND radioMarried;  //单选按钮--已婚
static HWND radioSingle;  //单选按钮--未婚
static HWND radioSecrecy;  //单选按钮--保密
//一组复选框
static HWND labPet;  //静态文本框--你的宠物
static HWND checkboxDog;  //复选框--狗
static HWND checkboxCat;  //复选框--猫
static HWND checkboxFish;  //复选框--鱼
static HWND checkboxOther;  //复选框--其他
static HWND btnSubmit;  //按钮控件
switch (message){ 

case  WM_CREATE:
hFont = CreateFont(
-14, -7, 0, 0, 400,
FALSE, FALSE, FALSE,DEFAULT_CHARSET,
OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY,
FF_DONTCARE, TEXT("微软雅黑")
);
//选择性别
labSex = CreateWindow(
TEXT("static"), TEXT("你的性别:"),
WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE | SS_RIGHT/*文字居右*/,
10, 10, 80, 26,
hWnd, (HMENU)1, hInst, NULL
);
radioMale = CreateWindow(
TEXT("button"), TEXT("男"),
WS_CHILD | WS_VISIBLE | BS_LEFT/*文字居左*/ | BS_AUTORADIOBUTTON /*单选按钮*/ | WS_GROUP,
95, 10, 50, 26,
hWnd, (HMENU)2, hInst, NULL
);
radioFemale = CreateWindow(
TEXT("button"), TEXT("女"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON,
150, 10, 50, 26,
hWnd, (HMENU)2, hInst, NULL
);
//选择婚姻状况
labMarriage = CreateWindow(
TEXT("static"), TEXT("婚姻状况:"),
WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE | SS_RIGHT,
10, 40, 80, 26,
hWnd, (HMENU)4, hInst, NULL
);
radioMarried = CreateWindow(
TEXT("button"), TEXT("已婚"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON | WS_GROUP,
95, 40, 65, 26,
hWnd, (HMENU)5, hInst, NULL
);
radioSingle = CreateWindow(
TEXT("button"), TEXT("未婚"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON,
165, 40, 65, 26,
hWnd, (HMENU)6, hInst, NULL
);
radioSecrecy = CreateWindow(
TEXT("button"), TEXT("保密"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTORADIOBUTTON,
235, 40, 100, 26,
hWnd, (HMENU)7, hInst, NULL
);
//你的宠物
labPet = CreateWindow(
TEXT("static"), TEXT("你的宠物:"),
WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE | SS_RIGHT,
10, 70, 80, 26,
hWnd, (HMENU)8, hInst, NULL
);
checkboxDog = CreateWindow(
TEXT("button"), TEXT("狗"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX/*复选框*/,
95, 70, 50, 26,
hWnd, (HMENU)9, hInst, NULL
);
checkboxCat = CreateWindow(
TEXT("button"), TEXT("猫"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX,
150, 70, 50, 26,
hWnd, (HMENU)10, hInst, NULL
);
checkboxFish = CreateWindow(
TEXT("button"), TEXT("鱼"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX,
205, 70, 50, 26,
hWnd, (HMENU)11, hInst, NULL
);
checkboxOther = CreateWindow(
TEXT("button"), TEXT("其他"),
WS_CHILD | WS_VISIBLE | BS_LEFT | BS_AUTOCHECKBOX,
260, 70, 65, 26,
hWnd, (HMENU)12, hInst, NULL
);
//创建按钮控件
btnSubmit = CreateWindow(TEXT("button"), TEXT("提 交"),
WS_CHILD | WS_VISIBLE | WS_BORDER | BS_FLAT,
95, 110, 200, 36,
hWnd, (HMENU)13, hInst, NULL
);
SendMessage(labSex, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(radioMale, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(radioFemale, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(labMarriage, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(radioMarried, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(radioSingle, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(radioSecrecy, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(labPet, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(checkboxDog, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(checkboxCat, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(checkboxFish, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(checkboxOther, WM_SETFONT, (WPARAM)hFont, NULL);
SendMessage(btnSubmit, WM_SETFONT, (WPARAM)hFont, NULL);
break;
case WM_COMMAND:
wmId    = LOWORD(wParam);
wmEvent = HIWORD(wParam);
if( wmEvent==  BN_CLICKED){ 

switch (wmId){ 

//获取性别
case 2:
case 3:
GetWindowText((HWND)lParam, szBufSex, 10);
break;
//获取婚姻状况
case 5:
case 6:
case 7:
GetWindowText((HWND)lParam, szBufMarriage, 10);
break;
//获取宠物
case 9:
case 10:
case 11:
case 12:
memset(szBufPet, 0, sizeof(szBufPet));
//是否选中狗
if( SendMessage(checkboxDog, BM_GETCHECK, 0, 0) == BST_CHECKED ){ 

GetWindowText(checkboxDog, szBufTmp,  10);
wsprintf(szBufPet, TEXT("%s %s"), szBufPet, szBufTmp);
}
//是否选中猫
if( SendMessage(checkboxCat, BM_GETCHECK, 0, 0) == BST_CHECKED ){ 

GetWindowText(checkboxCat, szBufTmp, 10);
wsprintf(szBufPet, TEXT("%s %s"), szBufPet, szBufTmp);
}
//是否选中鱼
if( SendMessage(checkboxFish, BM_GETCHECK, 0, 0) == BST_CHECKED ){ 

GetWindowText(checkboxFish, szBufTmp, 10);
wsprintf(szBufPet, TEXT("%s %s"), szBufPet, szBufTmp);
}
//是否选中其他
if( SendMessage(checkboxOther, BM_GETCHECK, 0, 0) == BST_CHECKED ){ 

GetWindowText(checkboxOther, szBufTmp, 10);
wsprintf(szBufPet, TEXT("%s %s"), szBufPet, szBufTmp);
}
break;
case 13:
wsprintf(szBufSubmit, TEXT("你的性别:%s\n婚姻状况:%s\r\n你的宠物:%s"), szBufSex, szBufMarriage, szBufPet);
MessageBox(hWnd, szBufSubmit, TEXT("信息提示"), MB_ICONINFORMATION);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_DESTROY:
DeleteObject(hFont);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/170968.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • c语言debug和release什么区别_电源模式有何差别

    c语言debug和release什么区别_电源模式有何差别.NET中Debug模式与Release模式差别

  • StretchDIBits用法

    StretchDIBits用法转自:http://blog.csdn.net/giantchen547792075/article/details/6996011StretchDIBits函数把DIB、JPEG、PNG图像中一矩形区域内的像素颜色数据复制到指定的目标矩形里。如果目标矩形大于源矩形,此函数将拉伸的行和列以适合目标矩形的颜色数据。如果目标矩形小于源矩形,则此函数使用指定的光栅操作压缩的行和列。(Note:整幅图像…

  • 复杂json转MAP对象

    复杂json转MAP对象普通json对象或者字符串转换map或者实体就不说了,这里主要提供复杂json转map的方法,直接上java代码了:publicclassJsonUtils{ /** *类描述:复杂json字符串转换为Map,包含数组时value为List。 */ publicstaticMapjson2Map(Stringjson){ LinkedMap

  • 约瑟夫环——公式法(递推公式)

    约瑟夫环——公式法(递推公式)约瑟夫问题约瑟夫问题是个有名的问题:N个人围成一圈,第一个从1开始报数,报M的将被杀掉,下一个人接着从1开始报。如此反复,最后剩下一个,求最后的胜利者。例如只有三个个人,把他们叫做A、B、C围成一圈,从A开始报数,报2的人被杀掉。A开始报数,他报1。侥幸逃过一劫。然后轮到B报数,他报2。非常惨,他被杀了C接着从1开始报数然后轮到A报数,他报2。也被杀死了。最终胜利者是C解决方案普通解

  • 面试问题spring cloud和dubbo的区别[通俗易懂]

    面试问题spring cloud和dubbo的区别[通俗易懂]最近一段时间不论互联网还是传统行业,凡是涉及信息技术范畴的圈子几乎都在讨论微服务架构 。近期也看到各大技术社区开始组织一些沙龙和论坛来分享spring Cloud的相关实施经验,这对于最近正在整理SpringCloud相关套件内容与实例应用的我而言,还是有不少激励的。目前,SpringCloud在国内的知名度并不高,在前阵子的求职过程中,与一些互联网公司的架构师、技术VP或者CT

  • android 从相册选择图片_android调用相册并显示图片

    android 从相册选择图片_android调用相册并显示图片publicclassMainActivityextendsAppCompatActivity{intREQUEST_CODE=0;privateNineGridImageViewngiv;privateArrayListphotos;privateDialogdialog;privatecn.com.jwtimes.www.jwtimes.mAdaptermAdapter1…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号