14win32_14_button按钮
Posted 养老保险年审
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了14win32_14_button按钮相关的知识,希望对你有一定的参考价值。
14win32_14_button按钮
#include <windows.h>
#include <iostream>
CHAR szText[256] = { 0 };
#define PrintLog(x) WriteConsole(g_hStdout, x, strlen(x), NULL, NULL)
HINSTANCE g_hInst = NULL; //窗口句柄
HANDLE g_hStdout = NULL; //控制台句柄
//OnCreate
void OnCreate(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
//下压式Button
CreateWindow("BUTTON", "PUSH_BUTTON", WS_CHILD | WS_VISIBLE, 100, 100, 200, 40, hWnd, (HMENU)1001, g_hInst, NULL);
//三态按键
CreateWindow("BUTTON", "我是三态按键", WS_CHILD | WS_VISIBLE | BS_AUTO3STATE|BS_PUSHLIKE/*若不加这个风格,则像CheckBox*/, 400, 100, 200, 40, hWnd, (HMENU)2001, g_hInst, NULL);
//分组按钮
CreateWindow("BUTTON", "分组一", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 100, 200, 300, 300,
hWnd, (HMENU)3001, g_hInst, NULL);
//多选按钮,CheckBox
CreateWindow("BUTTON", "checkbox", WS_CHILD | WS_VISIBLE | BS_CHECKBOX, 120, 220, 200, 30,
hWnd, (HMENU)4001, g_hInst, NULL);
CreateWindow("BUTTON", "Auto_check_box", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, 120, 250, 200, 30,
hWnd, (HMENU)4002, g_hInst, NULL);
//单选按钮
CreateWindow("BUTTON", "A", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON|WS_GROUP/*分组,把AB分成一组*/,
120, 300, 100, 30, hWnd, (HMENU)5001, g_hInst,NULL);
CreateWindow("BUTTON", "B", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
120, 330, 100, 30, hWnd, (HMENU)5002, g_hInst,NULL);
CreateWindow("BUTTON", "C", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON|WS_GROUP/*分组,把CD分成一组*/,
120, 360, 100, 30, hWnd, (HMENU)5003, g_hInst,NULL);
CreateWindow("BUTTON", "D", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
120, 390, 100, 30, hWnd, (HMENU)5004, g_hInst,NULL);
}
//响应按钮
void OnCommand(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
int nNotifyCode = HIWORD(wParam);
int nEventID = LOWORD(wParam);
switch (nEventID)
{
case 1001:
switch (nNotifyCode)
{
//push_button消息的响应,一般只处理点击消息,其它消息很少处理
case BN_CLICKED:
MessageBox(NULL, "Hello push_button!", "button", MB_OK);
break;
}
break;
case 4002:
{
HWND hCtrl = GetDlgItem(hWnd, 4002);
LRESULT nCheck = 0;
switch (nNotifyCode)
{
//push_button消息的响应,一般只处理点击消息,其它消息很少处理
case BN_CLICKED:
{
//获取当前CheckBox的状态
nCheck = SendMessage(hCtrl, BM_GETCHECK, 0, 0);
//判断当前状态是否被选择
if (nCheck & BST_CHECKED)
{
//设置成不选择状态
SendMessage(hCtrl, BM_SETCHECK, BST_UNCHECKED, 0);
}
else
{
//设置成选择状态
SendMessage(hCtrl, BM_SETCHECK, BST_CHECKED, 0);
}
break;
}
}
break;
}
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
switch (nMsg)
{
case WM_CREATE:
OnCreate(hWnd, nMsg, wParam, lParam);
break;
case WM_COMMAND:
OnCommand(hWnd, nMsg, wParam, lParam);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, nMsg, wParam, lParam);
}
BOOL RegisterWnd(LPSTR pszClassName)
{
WNDCLASSEX wce = { 0 };
wce.cbSize = sizeof(wce);
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hbrBackground = HBRUSH(COLOR_BTNFACE + 1);
wce.hCursor = NULL;
wce.hIcon = NULL;
wce.hIconSm = NULL;
wce.hInstance = g_hInst;
wce.lpfnWndProc = WndProc;
wce.lpszClassName = pszClassName;
wce.lpszMenuName = NULL;
wce.style = CS_HREDRAW | CS_VREDRAW;
ATOM atom = RegisterClassEx(&wce);
if (atom == NULL)
{
return FALSE;
}
else
{
return TRUE;
}
}
HWND CreateWnd(LPSTR pszClassName)
{
HWND hWnd = CreateWindowEx(0, pszClassName, "灭天", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, g_hInst, 0);
return hWnd;
}
void ShowWnd(HWND hWnd)
{
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
}
void Msg()
{
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
void ConsoleWnd()
{
AllocConsole();
g_hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
CHAR szText[] = "Debug start:\n";
WriteConsole(g_hStdout, szText, strlen(szText), NULL, NULL);
}
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
{
g_hInst = hInstance;
//ConsoleWnd();
RegisterWnd("oooo");
HWND hWnd = CreateWnd("oooo");
ShowWnd(hWnd);
Msg();
return 0;
}
以上是关于14win32_14_button按钮的主要内容,如果未能解决你的问题,请参考以下文章
BricsCAD.Platinum.v14.2.12.34721.Win32_64 2CD
2016-10-10 14:23:33 scrapy crawl projectName (cannot import name '_win32stdio')