📄 button.c
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#define IDC_CTRL1 100#define IDC_CTRL2 110#define IDC_CTRL3 128#define IDC_CTRL4 130static HWND hMainWnd = HWND_INVALID;static int ControlTestWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ static HWND hChildWnd1, hChildWnd2, hChildWnd3, hChildWnd4, hChildWnd5, hChildWnd6, hChildWnd7, hChildWnd8; switch (message) { case MSG_CREATE: hChildWnd1 = CreateWindow ("button", "确定", WS_CHILD | BS_DEFPUSHBUTTON | WS_VISIBLE, IDC_CTRL1, 10, 20, 80, 30, hWnd, 0); hChildWnd4 = CreateWindow ("button", "取消", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, IDC_CTRL4, 100, 20, 80, 30, hWnd, 0); hChildWnd2 = CreateWindow ("button", "复选框", WS_CHILD | BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_RIGHT | WS_VISIBLE, IDC_CTRL2, 100, 60, 100, 30, hWnd, 0); hChildWnd3 = CreateWindow ("button", "单选钮", WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_GROUP, IDC_CTRL3, 10, 60, 100, 30, hWnd, 0); hChildWnd5 = CreateWindow ("button", "单选钮", WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE, IDC_CTRL3 + 1, 10, 100, 100, 30, hWnd, 0); hChildWnd6 = CreateWindow ("button", "单选钮", WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE, IDC_CTRL3 + 2, 10, 140, 100, 30, hWnd, 0); EnableWindow (hChildWnd6, FALSE); /* hChildWnd7 = CreateWindow ("button", "按钮1", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, IDC_CTRL4 + 10, 10, 160, 60, 30, hWnd, 0); hChildWnd8 = CreateWindow ("button", "按纽2", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, IDC_CTRL4 + 20, 100, 160, 60, 30, hWnd, 0); */ break; case MSG_COMMAND: { int id = LOWORD(wParam); int code = HIWORD(wParam); char buffer [256]; HDC hdc; sprintf (buffer, "ID: %d, Code: %x", id, code); hdc = GetClientDC (hWnd); TextOut (hdc, 0, 0, buffer); switch (id) { case IDC_CTRL4: PostMessage (hWnd, MSG_CLOSE, 0, 0); break; default: break; } ReleaseDC (hdc); } break; case MSG_CLOSE: DestroyWindow (hChildWnd1); DestroyWindow (hChildWnd2); DestroyWindow (hChildWnd3); DestroyWindow (hChildWnd4); DestroyWindow (hChildWnd5); DestroyWindow (hChildWnd6); DestroyWindow (hChildWnd7); DestroyWindow (hChildWnd8); DestroyMainWindow (hWnd); MainWindowCleanup (hWnd); hMainWnd = HWND_INVALID; return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}static void InitCreateInfo(PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE; pCreateInfo->dwExStyle = WS_EX_NONE; pCreateInfo->spCaption = "Button control"; pCreateInfo->hMenu = 0; pCreateInfo->hCursor = GetSystemCursor(1); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = ControlTestWinProc; pCreateInfo->lx = 0; pCreateInfo->ty = 0; pCreateInfo->rx = 400; pCreateInfo->by = 300; pCreateInfo->iBkColor = GetWindowElementColor (BKC_CONTROL_DEF); pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = HWND_DESKTOP;}void button_demo (HWND hwnd){ MAINWINCREATE CreateInfo; if (hMainWnd != HWND_INVALID) { ShowWindow (hMainWnd, SW_SHOWNORMAL); return; } InitCreateInfo (&CreateInfo); CreateInfo.hHosting = hwnd; hMainWnd = CreateMainWindow (&CreateInfo);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -