📄 button.c
字号:
/*** $Id: button.c,v 1.12 2004/04/19 07:30:21 weiym Exp $**** button.c: The Button control demo program.**** Copyright (C) 2001 ~ 2002 Wei Yongming.** Copyright (C) 2003 Feynman Software.**** Create date: 2001/11/01*//*** This source is free software; you can redistribute it and/or** modify it under the terms of the GNU General Public** License as published by the Free Software Foundation; either** version 2 of the License, or (at your option) any later version.**** This software is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU** General Public License for more details.**** You should have received a copy of the GNU General Public** License along with this library; if not, write to the Free** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,** MA 02111-1307, USA*/#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_BUTTON 100#define IDC_CHECKBOX 200#define IDC_RADIOBUTTON 300static HWND hMainWnd = HWND_INVALID;#if _MINIGUI_VERSION_CODE >= _VERSION_CODE (1, 2, 6)static void my_notif_proc (HWND hwnd, int id, int nc, DWORD add_data){ printf ("From my_notif_proc: ID: %d, Code %d\n", id, nc);}#endifstatic int ControlTestWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ HWND hwnd; switch (message) { case MSG_CREATE: CreateWindow (CTRL_BUTTON, "Push Button", WS_CHILD | BS_PUSHBUTTON | BS_CHECKED | WS_VISIBLE, IDC_BUTTON, 10, 10, 80, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Multiple Lines Push Button", WS_CHILD | BS_PUSHBUTTON | BS_MULTLINE | WS_VISIBLE, IDC_BUTTON + 1, 100, 10, 80, 40, hWnd, 0); CreateWindow (CTRL_BUTTON, "Normal check box", WS_CHILD | BS_CHECKBOX | BS_CHECKED | WS_VISIBLE, IDC_BUTTON + 2, 190, 10, 150, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Normal radio button", WS_CHILD | BS_RADIOBUTTON | WS_VISIBLE, IDC_BUTTON + 3, 350, 10, 150, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Auto 3-state check box", WS_CHILD | BS_AUTO3STATE | WS_VISIBLE, IDC_CHECKBOX, 10, 60, 150, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Auto check box on left", WS_CHILD | BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_RIGHT | WS_VISIBLE, IDC_CHECKBOX + 1, 170, 60, 150, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Push-like check box", WS_CHILD | BS_AUTOCHECKBOX | BS_PUSHLIKE | WS_VISIBLE, IDC_CHECKBOX + 2, 330, 60, 100, 20, hWnd, 0); CreateWindow (CTRL_STATIC, "A Group Box", WS_CHILD | SS_GROUPBOX | WS_VISIBLE, IDC_STATIC, 10, 100, 150, 140, hWnd, 0); CreateWindow (CTRL_BUTTON, "Auto Radio Button 1", WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE | WS_GROUP, IDC_RADIOBUTTON, 20, 120, 130, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Auto Radio Button 2", WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE, IDC_RADIOBUTTON + 1, 20, 160, 130, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Auto Radio Button 3", WS_CHILD | BS_AUTORADIOBUTTON | WS_VISIBLE, IDC_RADIOBUTTON + 2, 20, 200, 130, 30, hWnd, 0); CreateWindow (CTRL_STATIC, "A Group Box", WS_CHILD | SS_GROUPBOX | WS_VISIBLE, IDC_STATIC, 170, 100, 170, 140, hWnd, 0); CreateWindow (CTRL_BUTTON, "Auto Radio Button 1", WS_CHILD | BS_AUTORADIOBUTTON | BS_LEFTTEXT | BS_RIGHT | WS_VISIBLE | WS_GROUP, IDC_RADIOBUTTON + 3, 180, 120, 140, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Auto Radio Button 2", WS_CHILD | BS_AUTORADIOBUTTON | BS_LEFTTEXT | BS_RIGHT | WS_VISIBLE, IDC_RADIOBUTTON + 4, 180, 160, 140, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Auto Radio Button 3", WS_CHILD | BS_AUTORADIOBUTTON | BS_LEFTTEXT | BS_RIGHT | WS_VISIBLE, IDC_RADIOBUTTON + 5, 180, 200, 140, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Push-like Radio 1", WS_CHILD | BS_AUTORADIOBUTTON | BS_PUSHLIKE | WS_VISIBLE | WS_GROUP, IDC_RADIOBUTTON + 3, 10, 260, 100, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Push-like Radio 2", WS_CHILD | BS_AUTORADIOBUTTON | BS_PUSHLIKE | WS_VISIBLE, IDC_RADIOBUTTON + 4, 120, 260, 100, 30, hWnd, 0); CreateWindow (CTRL_BUTTON, "Push-like Radio 3", WS_CHILD | BS_AUTORADIOBUTTON | BS_PUSHLIKE | WS_VISIBLE, IDC_RADIOBUTTON + 5, 230, 260, 100, 30, hWnd, 0); hwnd = CreateWindow (CTRL_BUTTON, "Close", WS_CHILD | BS_PUSHBUTTON | BS_ICON |BS_REALSIZEIMAGE | BS_NOTIFY | WS_VISIBLE, IDC_BUTTON + 4, 10, 300, 60, 30, hWnd, (DWORD) GetLargeSystemIcon (IDI_APPLICATION)); CreateWindow (CTRL_BUTTON, "Close", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, IDCANCEL, 410, 300, 60, 30, hWnd, 0);#if _MINIGUI_VERSION_CODE >= _VERSION_CODE (1, 2, 6) SetNotificationCallback (hwnd, my_notif_proc);#endif break; case MSG_COMMAND: { int id = LOWORD(wParam); int code = HIWORD(wParam); printf ("Notification from buttons: ID: %d, Code: %x\n", id, code); if (wParam == IDCANCEL) { PostMessage (hWnd, MSG_CLOSE, 0, 0); } } break; case MSG_DESTROY: DestroyAllControls (hWnd); hMainWnd = HWND_INVALID; return 0; case MSG_CLOSE: DestroyMainWindow (hWnd); MainWindowCleanup (hWnd); return 0; } return DefaultMainWinProc (hWnd, message, wParam, lParam);}static void InitCreateInfo(PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE; pCreateInfo->dwExStyle = WS_EX_NONE; pCreateInfo->spCaption = "Button controls"; pCreateInfo->hMenu = 0; pCreateInfo->hCursor = GetSystemCursor(1); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = ControlTestWinProc; pCreateInfo->lx = 0; pCreateInfo->ty = 0; pCreateInfo->rx = 480; pCreateInfo->by = 380; 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 + -