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

📄 resource.c

📁 在ADS环境下MiniGUI的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
** $Id: resource.c,v 1.26 2004/08/10 00:17:37 snig Exp $
**
** resource.c: This file include some functions for system resource loading. 
**           some functions are from misc.c.
**
** Copyright (C) 2003 Feynman Software.
** Copyright (C) 1999 ~ 2002 Wei Yongming.
**
** Create date: 2003/09/06
**
** Current maintainer: Wei Yongming.
*/

/*
** This program 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 program 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 program; 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 <ctype.h>

#include "common.h"
#include "minigui.h"
#include "gdi.h"
#include "window.h"
#include "cursor.h"
#include "icon.h"
#include "sysres.h"
#include "misc.h"

BITMAP SystemBitmap [SYSBMP_ITEM_NUMBER];
HICON  LargeSystemIcon [SYSICO_ITEM_NUMBER] = {0};
HICON  SmallSystemIcon [SYSICO_ITEM_NUMBER] = {0};

#ifdef _CTRL_BUTTON
#   define _NEED_STOCKBMP_BUTTON            1
#   ifdef _PHONE_WINDOW_STYLE
#       define _NEED_STOCKBMP_PUSHBUTTON    1
#   endif
#endif

#if defined(_CTRL_COMBOBOX) || defined (_CTRL_MENUBUTTON)
#   define _NEED_STOCKBMP_DOWNARROW         1
#endif

#ifdef _CTRL_COMBOBOX
#   define _NEED_STOCKBMP_DOUBLEARROW       1
#endif

#ifdef _CTRL_LISTBOX
#   define _NEED_STOCKBMP_CHECKMARK         1
#endif

#if defined(_CTRL_TRACKBAR) && defined(_PHONE_WINDOW_STYLE)
#   define _NEED_STOCKBMP_TRACKBAR          1
#endif

#ifdef _EXT_CTRL_SPINBOX
#   define _NEED_STOCKBMP_SPINBOX           1
#endif

#ifdef _IME_GB2312
#   define _NEED_STOCKBMP_IME               1
#endif

#ifdef _MISC_ABOUTDLG
#   define _NEED_STOCKBMP_LOGO              1
#endif

#ifdef _EXT_CTRL_TREEVIEW
#   define _NEED_SYSICON_FOLD               1
#endif

#ifdef _EXT_CTRL_LISTVIEW
#   define _NEED_STOCKBMP_LVFOLD            1
#   define _NEED_SYSICON_FILETYPE           1
#endif

static struct _StockBitmaps {
    const char* name;
    BITMAP bmp;
} StockBitmaps [] =
{
#ifdef _NEED_STOCKBMP_BUTTON
    {STOCKBMP_BUTTON},
#endif
#ifdef _NEED_STOCKBMP_PUSHBUTTON
    {STOCKBMP_PUSHBUTTON},
    {STOCKBMP_PUSHEDBUTTON},
#endif
#ifdef _NEED_STOCKBMP_DOWNARROW
    {STOCKBMP_DOWNARROW},
#endif
#ifdef _NEED_STOCKBMP_DOUBLEARROW
    {STOCKBMP_UPDOWNARROW},
    {STOCKBMP_LEFTRIGHTARROW},
#endif
#ifdef _NEED_STOCKBMP_CHECKMARK
    {STOCKBMP_CHECKMARK},
#endif
#ifdef _NEED_STOCKBMP_TRACKBAR
    {STOCKBMP_TRACKBAR_HBG},
    {STOCKBMP_TRACKBAR_HSLIDER},
    {STOCKBMP_TRACKBAR_VBG},
    {STOCKBMP_TRACKBAR_VSLIDER},
#endif
#ifdef _NEED_STOCKBMP_SPINBOX
    {STOCKBMP_SPINBOX_HORZ},
    {STOCKBMP_SPINBOX_VERT},
#endif
#ifdef _NEED_STOCKBMP_LVFOLD
    {STOCKBMP_LVFOLD},
    {STOCKBMP_LVUNFOLD},
#endif
#ifdef _NEED_STOCKBMP_IME
    {STOCKBMP_IMECTRLBTN},
#endif
#ifdef _NEED_STOCKBMP_LOGO
    {STOCKBMP_LOGO}
#endif
};

const BITMAP* GUIAPI GetStockBitmap (const char* name, int ckey_x, int ckey_y)
{
    int i;

    if (!name || name [0] == '\0')
        return NULL;

    for (i = 0; i < TABLESIZE(StockBitmaps); i++) {
        if (strcmp (name, StockBitmaps [i].name) == 0) {
            PBITMAP bmp = &StockBitmaps [i].bmp;

            if (bmp->bmWidth == 0 || bmp->bmHeight == 0) {
                if (!LoadSystemBitmapEx (bmp, name, ckey_x, ckey_y))
                    return NULL;
            }

            return bmp;
        }
    }

    return NULL;
}

#ifndef _INCORE_RES

/****************************** System resource support *********************/

#ifdef _CURSOR_SUPPORT
PCURSOR LoadSystemCursor (int i)
{
    PCURSOR tempcsr;

    char szValue[MAX_NAME + 1];
    char szPathName[MAX_PATH + 1];
    char szKey[10];

    if (GetMgEtcValue (CURSORSECTION, "cursorpath", szPathName, MAX_PATH) < 0)
                 goto error;

    sprintf (szKey, "cursor%d", i);
    if (GetMgEtcValue (CURSORSECTION, szKey, szValue, MAX_NAME) < 0)
                goto error;

    strcat (szPathName, szValue);

    if (!(tempcsr = (PCURSOR)LoadCursorFromFile (szPathName)))
                     goto error;

    return tempcsr;

error:
    return 0;
}
#endif

BOOL GUIAPI LoadSystemBitmapEx (PBITMAP pBitmap, const char* szItemName, int ckey_x, int ckey_y)
{
    char szPathName[MAX_PATH + 1];
    char szValue[MAX_NAME + 1];
    
    if (GetMgEtcValue ("bitmapinfo", szItemName,
            szValue, MAX_NAME) < 0 ) {
        fprintf (stderr, "LoadSystemBitmapEx: Get bitmap file name error!\n");
        return FALSE;
    }
    
    if (GetMgEtcValue ("bitmapinfo", "bitmappath",
            szPathName, MAX_PATH) < 0 ) {
        fprintf (stderr, "LoadSystemBitmapEx: Get bitmap path error!\n");
        return FALSE;
    }

    if (strcmp (szValue, "none") == 0) {
        memset (pBitmap, 0, sizeof (BITMAP));
        return TRUE;
    }

    strcat(szPathName, szValue);
    
    if (LoadBitmap (HDC_SCREEN, pBitmap, szPathName) < 0) {
        fprintf (stderr, "LoadSystemBitmapEx: Load bitmap error: %s!\n", szPathName);
        return FALSE;
    }
    
    if (ckey_x >= 0 && ckey_x < pBitmap->bmWidth
            && ckey_y >= 0 && ckey_y < pBitmap->bmHeight) {
        pBitmap->bmType = BMP_TYPE_COLORKEY;
        pBitmap->bmColorKey = GetPixelInBitmap (pBitmap, 0, 0);
    }

    return TRUE;
}

HICON GUIAPI LoadSystemIcon (const char* szItemName, int which)
{
    char szPathName[MAX_PATH + 1];
    char szValue[MAX_NAME + 1];
    HICON hIcon;
    
    if (GetMgEtcValue ("iconinfo", szItemName,
            szValue, MAX_NAME) < 0 ) {
        fprintf (stderr, "LoadSystemIcon: Get icon file name error!\n");
        return 0;
    }
    
    if (GetMgEtcValue ("iconinfo", "iconpath",
            szPathName, MAX_PATH) < 0 ) {
        fprintf (stderr, "LoadSystemIcon: Get icon path error!\n");
        return 0;
    }

    strcat (szPathName, szValue);
    
    if ((hIcon = LoadIconFromFile (HDC_SCREEN, szPathName, which)) == 0) {
        fprintf (stderr, "LoadSystemIcon: Load icon error: %s!\n", szPathName);
        return 0;
    }
    
    return hIcon;
}

BOOL InitSystemRes (void)
{
    int i;
    int nBmpNr, nIconNr;
    char szValue [12];
    
    /*
     * Load system bitmaps here.
     */
    if (GetMgEtcValue ("bitmapinfo", "bitmapnumber", 
                            szValue, 10) < 0)
        return FALSE;
    nBmpNr = atoi (szValue);
    if (nBmpNr <= 0) return FALSE;
    nBmpNr = nBmpNr < SYSBMP_ITEM_NUMBER ? nBmpNr : SYSBMP_ITEM_NUMBER;

    for (i = 0; i < nBmpNr; i++) {
        sprintf (szValue, "bitmap%d", i);

        if (!LoadSystemBitmap (SystemBitmap + i, szValue))
            return FALSE;
    }

    /*
     * Load system icons here.
     */
    if (GetMgEtcValue ("iconinfo", "iconnumber", 
                            szValue, 10) < 0 )
        return FALSE;
    nIconNr = atoi(szValue);
    if (nIconNr <= 0) return FALSE;
    nIconNr = nIconNr < SYSICO_ITEM_NUMBER ? nIconNr : SYSICO_ITEM_NUMBER;

    for (i = 0; i < nIconNr; i++) {
        sprintf(szValue, "icon%d", i);
        
        SmallSystemIcon [i] = LoadSystemIcon (szValue, 1);
        LargeSystemIcon [i] = LoadSystemIcon (szValue, 0);

        if (SmallSystemIcon [i] == 0 || LargeSystemIcon [i] == 0)
            return FALSE;
    }

    return TRUE;
}

#else /* _INCORE_RES */

#ifdef _CURSOR_SUPPORT
#   include "cursors.c"
#endif

#ifdef _FLAT_WINDOW_STYLE

⌨️ 快捷键说明

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