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

📄 mainwndow.c

📁 minigui实现带背景图片的主窗口的例子
💻 C
字号:
/* ** $Id: taskbar.c,v 1.23 2007-08-30 02:02:03 xwyan Exp $**** The taskbar of MDE**** Copyright (c) 2001, Wei Yongming (ymwei@minigui.org)** Copyright (C) 2003 ~ 2007 Feynman Software.**** Create date: 2001/09/07*//***  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 <unistd.h>#include <time.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include <minigui/mgext.h>#include "mainwndow.h"APPINFO app_info;static void free_app_info (void){    int i;    APPITEM* item;    item = app_info.app_items;    for (i = 0; i < app_info.nr_apps; i++, item++) {        if (item->bmp.bmBits) {            UnloadBitmap (&item->bmp);            item->bmp.bmBits = NULL;        }    }    free (app_info.app_items);    app_info.app_items = NULL;}static void strsubchr (char* string, int c1, int c2){    char* tmp;    while (string && (tmp = strchr (string, c1))) {        *tmp = c2;        string = tmp;    }}static BOOL get_app_info (void){    int i;    APPITEM* item;    char section [10];    if (GetIntValueFromEtcFile (APP_INFO_FILE, "mginit", "nr", &app_info.nr_apps) != ETC_OK)        return FALSE;    if (app_info.nr_apps <= 0)        return FALSE;    GetIntValueFromEtcFile (APP_INFO_FILE, "mginit", "autostart", &app_info.autostart);        if (GetValueFromEtcFile (APP_INFO_FILE, "mginit", "logo", app_info.logo_path, PATH_MAX + NAME_MAX) != ETC_OK)        return FALSE;               if (app_info.autostart >= app_info.nr_apps || app_info.autostart < 0)        app_info.autostart = 0;    if ((app_info.app_items = (APPITEM*)calloc (app_info.nr_apps, sizeof (APPITEM))) == NULL) {        return FALSE;    }    item = app_info.app_items;    for (i = 0; i < app_info.nr_apps; i++, item++) {        sprintf (section, "app%d", i);        if (GetValueFromEtcFile (APP_INFO_FILE, section, "path", item->path, PATH_MAX) != ETC_OK)            goto error;        if (GetValueFromEtcFile (APP_INFO_FILE, section, "name", item->name, NAME_MAX) != ETC_OK)            goto error;        if (GetValueFromEtcFile (APP_INFO_FILE, section, "layer", item->layer, LEN_LAYER_NAME) != ETC_OK)            goto error;        if (GetValueFromEtcFile (APP_INFO_FILE, section, "tip", item->tip, TIP_MAX) != ETC_OK)            goto error;        strsubchr (item->tip, '&', ' ');        if (GetValueFromEtcFile (APP_INFO_FILE, section, "icon", item->bmp_path, PATH_MAX + NAME_MAX) != ETC_OK)            goto error;        if (LoadBitmap (HDC_SCREEN, &item->bmp, item->bmp_path) != ERR_BMP_OK)            goto error;        item->cdpath = TRUE;    }    return TRUE;error:    free_app_info ();    return FALSE;}pid_t exec_app (int app){    pid_t pid = 0;    char buff [PATH_MAX + NAME_MAX + 1];    if ((pid = vfork ()) > 0) {        fprintf (stderr, "new child, pid: %d.\n", pid);    }    else if (pid == 0) {        if (app_info.app_items [app].cdpath) {            chdir (app_info.app_items [app].path);        }        strcpy (buff, app_info.app_items [app].path);        strcat (buff, app_info.app_items [app].name);        if (app_info.app_items [app].layer [0]) {            execl (buff, app_info.app_items [app].name,                         "-layer", app_info.app_items [app].layer, NULL);        }        else {            execl (buff, app_info.app_items [app].name, NULL);        }        perror ("execl");        _exit (1);    }    else {        perror ("vfork");    }    return pid;}/****************************************************************************  * 名称:WinProc()  * 功能:主窗口过程函数。  *		处理MSG_PAINT消息,在窗口中显示6个图标。  *		处理MSG_CHAR消息,进行图标菜单选择操作。  * 入口参数: *		hWnd        窗口句柄  *		message     消息  *		wParam      消息附加参数1(对于不同的消息,有不同的用途)  *		lParam      消息附加参数2(对于不同的消息,有不同的用途)  * 出口参数:消息已处理则返回0。  ****************************************************************************/  static HWND hIMEWnd = 0;static BITMAP bmp_bkgnd;static int MainWindowProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){	static BITMAP  s_startbmp;  	static BITMAP  s_bmp[6];  	static PLOGFONT s_font, s_font1;  	static int s_sel = 0;  	static int s_selbak = 0;  	int  i;      switch (message) {        case MSG_CREATE:            CreateWindow (CTRL_BUTTON,                           "Close",                           WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,                           IDCANCEL,                           100, 100, 60, 30, hWnd, 0);        break;                case MSG_COMMAND:        {            int id   = LOWORD(wParam);            int code = HIWORD(wParam);            if (wParam == IDCANCEL) {                PostMessage (hWnd, MSG_CLOSE, 0, 0);            }        }        break;       	case MSG_ERASEBKGND: 		{			            HDC hdc = (HDC)wParam;            const RECT* clip = (const RECT*) lParam;            BOOL fGetDC = FALSE;            RECT rcTemp;                                if (hdc == 0) {                hdc = GetClientDC (hWnd);                fGetDC = TRUE;            }                                       if (clip) {                rcTemp = *clip;                ScreenToClient (hWnd, &rcTemp.left, &rcTemp.top);                ScreenToClient (hWnd, &rcTemp.right, &rcTemp.bottom);                IncludeClipRect (hdc, &rcTemp);            }            //FillBoxWithBitmap (hdc, 0, 0, 0, 0, &bmp_bkgnd);	//显示原始尺寸			FillBoxWithBitmap (hdc, 0, 0, rcTemp.right, rcTemp.bottom, &bmp_bkgnd);	//按比例缩放显示            if (fGetDC)                ReleaseDC (hdc);            return 0;        }          case MSG_CLOSE:            if (MessageBox (hWnd,                            "Are you sure to quit?",                             "DlgTest",                             MB_YESNOCANCEL | MB_ICONQUESTION |                            MB_BASEDONPARENT) != IDYES)                return 0;            DestroyMainWindow (hWnd);            PostQuitMessage (hWnd);        return 0;    }    return DefaultMainWinProc (hWnd, message, wParam, lParam);}/****************************************************************************  * 名称:InitMainWindow()  * 功能:建立主窗口。  * 入口参数:无 * 出口参数:返回主窗口句柄。  ****************************************************************************/HWND InitMainWindow (void){	MAINWINCREATE CreateInfo;	HWND hMainWnd;    CreateInfo.dwStyle = WS_ABSSCRPOS | WS_VISIBLE | WS_TABSTOP;    CreateInfo.dwExStyle = WS_EX_NONE;//WS_EX_TRANSPARENT;    CreateInfo.spCaption = "";    CreateInfo.hMenu = 0;    CreateInfo.hCursor = 0;    CreateInfo.hIcon = 0;    CreateInfo.MainWindowProc = MainWindowProc;    CreateInfo.lx = 0;     CreateInfo.ty = 0;    CreateInfo.rx = 640;    CreateInfo.by = 480;    CreateInfo.iBkColor = GetWindowElementColor (BKC_CONTROL_DEF);     CreateInfo.dwAddData = 0;    CreateInfo.hHosting = HWND_DESKTOP;		LoadBitmap(HDC_SCREEN, &bmp_bkgnd, "res/Nature1.jpg");	hMainWnd = CreateMainWindow (&CreateInfo);		return hMainWnd;}/*HWND create_mainwin_dlg (void){    MAINWINCREATE CreateInfo;    HWND hMainwinDlg;    InitCreateInfo (&CreateInfo);    hMainwinDlg = CreateMainWindow (&CreateInfo);	//把该函数调用移到输入法程序代码中#ifdef _IME_GB2312    hIMEWnd = GBIMEWindowEx (hMainwinDlg,                    0,                    480 - HEIGHT_IMEWIN,                    640, 					480,					FALSE);#endif    return hMainwinDlg;}*/

⌨️ 快捷键说明

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