⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subclass.c

📁 MINI GUI1.6X源码
💻 C
字号:
/*** $Id: subclass.c,v 1.5 2003/06/06 10:10:47 weiym Exp $**** subclass.c:**  This program demostrates the technology of sub-class in MiniGUI**** 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_CTRL1     100#define IDC_CTRL2     110#define IDC_CTRL3     120#define IDC_CTRL4     130#define MY_ES_DIGIT_ONLY    0x0001#define MY_ES_ALPHA_ONLY    0x0002static HWND hMainWnd = HWND_INVALID;static WNDPROC old_edit_proc;static int RestrictedEditBox (HWND hwnd, int message, WPARAM wParam, LPARAM lParam){    if (message == MSG_CHAR) {        DWORD my_style = GetWindowAdditionalData (hwnd);        if ((my_style & MY_ES_DIGIT_ONLY) && (wParam < '0' || wParam > '9'))            return 0;        else if (my_style & MY_ES_ALPHA_ONLY)            if (!((wParam >= 'A' && wParam <= 'Z') || (wParam >= 'a' && wParam <= 'z')))                return 0;    }    return (*old_edit_proc) (hwnd, message, wParam, lParam);}static int ControlTestWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    switch (message) {    case MSG_CREATE:    {        HWND hWnd1, hWnd2, hWnd3;        CreateWindow (CTRL_STATIC, "Digit-only box:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 0,                     10, 10, 180, 24, hWnd, 0);        hWnd1 = CreateWindow (CTRL_EDIT, "", WS_CHILD | WS_VISIBLE | WS_BORDER, IDC_CTRL1,                     200, 10, 180, 24, hWnd, MY_ES_DIGIT_ONLY);        CreateWindow (CTRL_STATIC, "Alpha-only box:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 0,                     10, 40, 180, 24, hWnd, 0);        hWnd2 = CreateWindow (CTRL_EDIT, "", WS_CHILD | WS_BORDER | WS_VISIBLE, IDC_CTRL2,                     200, 40, 180, 24, hWnd, MY_ES_ALPHA_ONLY);        CreateWindow (CTRL_STATIC, "Normal edit box:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 0,                     10, 70, 180, 24, hWnd, 0);        hWnd3 = CreateWindow (CTRL_EDIT, "", WS_CHILD | WS_BORDER | WS_VISIBLE, IDC_CTRL2,                     200, 70, 180, 24, hWnd, MY_ES_ALPHA_ONLY);        CreateWindow ("button", "Close", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, IDC_CTRL4,                     100, 100, 60, 24, hWnd, 0);        old_edit_proc = SetWindowCallbackProc (hWnd1, RestrictedEditBox);        SetWindowCallbackProc (hWnd2, RestrictedEditBox);        break;    }    case MSG_COMMAND:    {        int id   = LOWORD(wParam);        switch (id) {        case IDC_CTRL4:            PostMessage (hWnd, MSG_CLOSE, 0, 0);            break;        }    }    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_IMECOMPOSE;    pCreateInfo->spCaption = "Subclass of Control";    pCreateInfo->hMenu = 0;    pCreateInfo->hCursor = GetSystemCursor(0);    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 subclass_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 + -