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

📄 ctrlclass.c

📁 在ecos 下mingui 的移植开发
💻 C
字号:
// $Id: ctrlclass.c,v 1.6 2000/11/17 12:28:04 ymwei Exp $//// ctrlclass.c: the Control Class module.//// Copyright (C) 1999, Wei Yongming.//// Current maintainer: Wei Yongming./***  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Library General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This library 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**  Library General Public License for more details.****  You should have received a copy of the GNU Library 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*/// Create date: 1999/5/21//// Modify records:////  Who             When        Where       For What                Status//-----------------------------------------------------------------------------//  Wei Yongming    1999/8/23   Tsinghua    Additional Data         Done//  Wei Yongming    1999/8/29   Tsinghua    Clean up                Working//// TODO:// #include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include <pthread.h>#include <semaphore.h>#include "common.h"#include "gdi.h"#include "window.h"#include "cliprect.h"#include "gal.h"#include "internals.h"#include "ctrlclass.h"#ifdef _CTRL_STATIC#include "control/static.h"#endif#ifdef _CTRL_BUTTON#include "control/button.h"#endif#ifdef _CTRL_EDIT#include "control/edit.h"#endif#ifdef _CTRL_PROGRESSBAR#include "control/progressbar.h"#endif#ifdef _CTRL_LISTBOX#include "control/listbox.h"#endif#ifdef _CTRL_MEDIT#include "control/medit.h"#endif#ifdef _CTRL_TOOLBAR#include "control/toolbar.h"#endif#ifdef _CTRL_MENUBUTTON#include "control/menubutton.h"#endif#ifndef lintstatic char fileid[] = "$Id: ctrlclass.c,v 1.6 2000/11/17 12:28:04 ymwei Exp $";#endif#define LEN_CCITABLE    26PCTRLCLASSINFO ccitable[LEN_CCITABLE];PCONTROL Control (HWND hWnd){    PCONTROL pCtrl;    pCtrl = (PCONTROL) hWnd;    if (pCtrl && pCtrl->WinType == TYPE_CONTROL)        return pCtrl;    return NULL;}BOOL InitControlClass (){    int i;        for (i=0; i<LEN_CCITABLE; i++)        ccitable[i] = NULL;    // Register system controls here.#ifdef _CTRL_STATIC    if (!RegisterStaticControl ())        return FALSE;#endif#ifdef _CTRL_BUTTON    if (!RegisterButtonControl())        return FALSE;#endif#ifdef _CTRL_EDIT    if (!RegisterSLEditControl())        return FALSE;#endif#ifdef _CTRL_PROGRESSBAR    if (!RegisterProgressBarControl())        return FALSE;#endif#ifdef _CTRL_LISTBOX    if (!RegisterListboxControl())        return FALSE;#endif#ifdef _CTRL_MEDIT    if (!RegisterMLEditControl())        return FALSE;#endif#ifdef _CTRL_TOOLBAR    if (!RegisterToolbarControl())        return FALSE;#endif#ifdef _CTRL_MENUBUTTON    if (!RegisterMenuButtonControl())        return FALSE;#endif    return TRUE;}void TerminateControlClass (){#ifdef _CTRL_STATIC    StaticControlCleanup ();#endif#ifdef _CTRL_BUTTON    ButtonControlCleanup ();#endif#ifdef _CTRL_EDIT    SLEditControlCleanup ();#endif        #ifdef _CTRL_PROGRESSBAR    ProgressBarControlCleanup ();#endif#ifdef _CTRL_LISTBOX    ListboxControlCleanup ();#endif#ifdef _CTRL_MEDIT    MLEditControlCleanup ();#endif#ifdef _CTRL_TOOLBAR    ToolbarControlCleanup ();#endif#ifdef _CTRL_MENUBUTTON    MenuButtonControlCleanup ();#endif    EmptyControlClassInfoTable ();}PCTRLCLASSINFO GetControlClassInfo (const char* szClassName){    PCTRLCLASSINFO cci;    int i=0;    char szName [MAXLEN_CLASSNAME + 1];    if (szClassName == NULL) return NULL;    strncpy (szName, szClassName, MAXLEN_CLASSNAME);    if (!isalpha (szName[0])) return NULL;        while (szName[i]) {        szName[i] = toupper(szName[i]);        i++;    }        cci = ccitable [szName[0] - 'A'];    while (cci) {            if (strcmp (cci->name, szName) == 0)            break;        cci = cci->next;    }        return cci;}int ControlClassDataOp (int Operation, PWNDCLASS pWndClass){    PCTRLCLASSINFO cci;    cci = GetControlClassInfo (pWndClass->spClassName);    if (!cci)        return ERR_CTRLCLASS_INVNAME;    if (Operation ==  CCDOP_GETCCI) {        if (pWndClass->opMask & COP_STYLE)            pWndClass->dwStyle      = cci->dwStyle;        if (pWndClass->opMask & COP_HCURSOR)            pWndClass->hCursor      = cci->hCursor;        if (pWndClass->opMask & COP_BKCOLOR)            pWndClass->iBkColor     = cci->iBkColor;        if (pWndClass->opMask & COP_WINPROC)            pWndClass->WinProc      = cci->ControlProc;        if (pWndClass->opMask & COP_ADDDATA)            pWndClass->dwAddData    = cci->dwAddData;    }    else {        if (pWndClass->opMask & COP_STYLE)            cci->dwStyle            = pWndClass->dwStyle;        if (pWndClass->opMask & COP_HCURSOR)            cci->hCursor            = pWndClass->hCursor;        if (pWndClass->opMask & COP_BKCOLOR)            cci->iBkColor           = pWndClass->iBkColor;        if (pWndClass->opMask & COP_WINPROC)            cci->ControlProc        = pWndClass->WinProc;        if (pWndClass->opMask & COP_ADDDATA)            cci->dwAddData          = pWndClass->dwAddData;    }    return ERR_OK;}int GetCtrlClassAddData (const char* szClassName, DWORD* pAddData){    PCTRLCLASSINFO cci;    cci = GetControlClassInfo (szClassName);    if (cci) {        *pAddData = cci->dwAddData;        return ERR_OK;    }        return ERR_CTRLCLASS_INVNAME;}int SetCtrlClassAddData (const char* szClassName, DWORD dwAddData){    PCTRLCLASSINFO cci;    cci = GetControlClassInfo (szClassName);    if (cci) {        cci->dwAddData = dwAddData;        return ERR_OK;    }        return ERR_CTRLCLASS_INVNAME;}int AddNewControlClass (PWNDCLASS pWndClass){    PCTRLCLASSINFO cci, newcci;    char szClassName [MAXLEN_CLASSNAME + 2];    int i=0;    strncpy (szClassName, pWndClass->spClassName, MAXLEN_CLASSNAME + 1);    if (!isalpha (szClassName[0])) return ERR_CTRLCLASS_INVNAME;        while (szClassName[i]) {        szClassName[i] = toupper(szClassName[i]);        i++;        if (i > MAXLEN_CLASSNAME)            return ERR_CTRLCLASS_INVLEN;    }        i = szClassName[0] - 'A';    cci = ccitable [i];    if (cci) {        while (cci) {            if (strcmp (szClassName, cci->name) == 0)                return ERR_CTRLCLASS_INVNAME;            cci = cci->next;        }    }    cci = ccitable[i];    newcci = malloc (sizeof (CTRLCLASSINFO));        if (newcci == NULL) return ERR_CTRLCLASS_MEM;    newcci->next = NULL;    strcpy (newcci->name, szClassName);    newcci->dwStyle     = pWndClass->dwStyle;    newcci->hCursor     = pWndClass->hCursor;    newcci->iBkColor    = pWndClass->iBkColor;    newcci->ControlProc = pWndClass->WinProc;    newcci->dwAddData   = pWndClass->dwAddData;    newcci->nUseCount   = 0;    if (cci) {        while (cci->next)            cci = cci->next;        cci->next = newcci;    }    else        ccitable [i] = newcci;        return ERR_OK;}int DeleteControlClass (const char* szClassName){    PCTRLCLASSINFO head, cci, prev;    int i=0;    char szName [MAXLEN_CLASSNAME + 1];    if (szClassName == NULL) return ERR_CTRLCLASS_INVNAME;        strncpy (szName, szClassName, MAXLEN_CLASSNAME);    if (!isalpha (szName[0])) return ERR_CTRLCLASS_INVNAME;        while (szName[i]) {        szName[i] = toupper(szName[i]);        i++;    }        i = szName[0] - 'A';    head = ccitable [i];        cci = head;    prev = head;    while (cci) {            if (strcmp (cci->name, szName))            break;        prev = cci;        cci = cci->next;    }    if (!cci)        return ERR_CTRLCLASS_INVNAME;    if (cci->nUseCount != 0)        return ERR_CTRLCLASS_INVNAME;    if (cci == head) {        ccitable [i] = cci->next;        free (cci);    }    else {        prev->next = cci->next;        free (cci);    }    return ERR_OK;}void EmptyControlClassInfoTable (){    PCTRLCLASSINFO cci, temp;    int i;    for (i = 0; i<LEN_CCITABLE; i++) {        cci = ccitable [i];        while (cci) {            temp = cci->next;            free (cci);            cci = temp;        }    }}BOOL SetWindowExStyle (HWND hWnd, DWORD dwExStyle){    PMAINWIN pWin;    PCONTROL pCtrl;    pWin = (PMAINWIN)hWnd;    if (pWin->WinType == TYPE_MAINWIN)         pWin->dwExStyle=dwExStyle;    else if (pWin->WinType == TYPE_CONTROL) {        pCtrl = (PCONTROL)hWnd;        pCtrl->dwExStyle=dwExStyle;    }    else        return FALSE;    return TRUE;}#ifdef _DEBUGvoid mnuDumpCtrlClassInfo (PCTRLCLASSINFO cci){    printf ("\tClass Name:             %s\n", cci->name);    printf ("\tClass Cursor:           %x\n", cci->hCursor);    printf ("\tClass Background color: %d\n", cci->iBkColor);    printf ("\tClass Control Proc:     %p\n", cci->ControlProc);    printf ("\tClass Use Count:        %d\n", cci->nUseCount);}void DumpCtrlClassInfoTable(){    PCTRLCLASSINFO cci;    int i;    for (i = 0; i<LEN_CCITABLE; i++) {        cci = ccitable [i];        printf ("CCI Table Element: %d\n", i);        while (cci) {                   mnuDumpCtrlClassInfo (cci);            cci = cci->next;        }    }}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -