📄 mginit.c
字号:
/*** $Id: mginit.c,v 1.34 2004/07/19 04:56:35 clear Exp $**** The mginit program of MiniGUI Demostration Envirionment.**** Copyright (C) 2001, 2002 Wei Yongming.** Copyright (C) 2003 Feynman Software.**** Create date: 2001/09/05*//*** 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 <signal.h>#include <time.h>#include <sys/types.h>#include <sys/wait.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 <minigui/fixedmath.h>#ifndef _LITE_VERSION #error "*************************************************************************" #error "**** Your MiniGUI configured as MiniGUI-Threads. ****" #error "**** This program is a server of MiniGUI-Lite, can only run on ****" #error "**** MiniGUI-Lite, not MiniGUI-Threads. ****" #error "**** If you want to configure MiniGUI as MiniGUI-Lite, ****" #error "**** please run `./configure --enable-lite' when configure MiniGUI, ****" #error "**** and build and reinstall MiniGUI. ****" #error "**** Note that this is not a fatal error. ****" #error "*************************************************************************"#else#include "taskbar.h"static HWND hTaskBar;static void AboutMiniGUI (void){ char buff [1024]; sprintf (buff, "MiniGUI version %d.%d.%d.\n" "Copyright (C) 1999 ~ 2003 Feynman Software and others.\n\n" "MiniGUI is free software, covered by the GNU General Public License, " "and you are welcome to change it and/or distribute copies of it under certain conditions. " "Please visit\n\n" "http://www.minigui.com\n\n" "for more information.\n\n" "There is absolutely no warranty for MiniGUI.", MINIGUI_MAJOR_VERSION, MINIGUI_MINOR_VERSION, MINIGUI_MICRO_VERSION); MessageBox (HWND_DESKTOP, buff, "About MiniGUI!", MB_OK | MB_ICONINFORMATION);}static void AboutMDE (void){ char buff [1024]; sprintf (buff, "MDE version %d.%d.%d.\n" "Copyright (C) 2001-2002 Feynman Software.\n\n" "MDE (MiniGUI Demostration Envirionment) is a comprehensive demo system " "for MiniGUI Ver %d.%d.%d. \n\n" "It creates a task bar for you, and you can launch applications from " "the bar, and switch among different layers by click " "the layer-box on the bar.\n\n" "MDE is free software, covered by the GNU General Public License, " "and you are welcome to change it and/or distribute copies of it under certain conditions. " "Please see the file COPYING to know the details.\n\n" "There is absolutely no warranty for MDE.", MINIGUI_MAJOR_VERSION, MINIGUI_MINOR_VERSION, MINIGUI_MICRO_VERSION, MINIGUI_MAJOR_VERSION, MINIGUI_MINOR_VERSION, MINIGUI_MICRO_VERSION); MessageBox (HWND_DESKTOP, buff, "About MDE!", MB_OK | MB_ICONINFORMATION);}static void Usage (void){ MessageBox (HWND_DESKTOP, "Please start 'mginit' from the directory in which it located! " "Do not change to other directory to run it.\n\n" "Thanks a lot.", "Usage of MDE!", MB_OK | MB_ICONEXCLAMATION);}static const char* new_del_client_info [] ={ NULL, "New comming in client: %s\n", "Disconnecting client: %s\n"};static void on_child_exit(int signal){ wait(NULL);}static void on_new_del_client (int op, int cli){ static int nr_clients = 0; MG_Client* client = mgClients + cli; if (op > 0 && op <= LCO_DEL_CLIENT) printf (new_del_client_info [op], client?client->name:"NULL"); if (op == LCO_NEW_CLIENT) { nr_clients ++; } else if (op == LCO_DEL_CLIENT) { nr_clients --; if (nr_clients == 0) {#if 0 SendMessage (hTaskBar, MSG_CLOSE, 0, 0);#else printf ("There is no any client.\n");#endif } else if (nr_clients < 0) { printf ("Serious error: nr_clients less than zero.\n"); } } else printf ("Serious error: incorrect operations.\n");}static const char* change_layer_info [] ={ NULL, "New layer created: %s; client: %s\n", "Layer deleted: %s; client: %s\n", "New client joined layer: (%s, %s)\n", "Remove client from layer: (%s, %s)\n", "Change topmost layer to %s; client: %s\n", "Change active client: (%s, %s)\n",};static void adjust_boxes (int width, MG_Layer* layer){ int left = _LEFT_BOXES; MG_Layer* cur_layer = mgLayers; while (cur_layer) { if (cur_layer != layer) { MoveWindow ((HWND)cur_layer->dwAddData, left, _MARGIN, width, _HEIGHT_CTRL, TRUE); left += width; } cur_layer = cur_layer->next; }}static void on_change_topmost (MG_Layer* layer){ MG_Layer* cur_layer = mgLayers; if (layer) SendMessage ((HWND)layer->dwAddData, BM_SETCHECK, BST_CHECKED, 0); while (cur_layer) { if (cur_layer != layer) { SendMessage ((HWND)cur_layer->dwAddData, BM_SETCHECK, 0, 0); } cur_layer = cur_layer->next; }}static void on_change_layer (int op, MG_Layer* layer, MG_Client* client){ static int nr_boxes = 0; static int box_width = _MAX_WIDTH_LAYER_BOX; int new_width; if (op > 0 && op <= LCO_ACTIVE_CHANGED) printf (change_layer_info [op], layer?layer->name:"NULL", client?client->name:"NULL"); switch (op) { case LCO_NEW_LAYER: nr_boxes ++; if (box_width * nr_boxes > _WIDTH_BOXES) { new_width = _WIDTH_BOXES / nr_boxes; if (new_width < _MIN_WIDTH_LAYER_BOX) { new_width = _MIN_WIDTH_LAYER_BOX; } if (new_width != box_width) { adjust_boxes (new_width, layer); box_width = new_width; } } layer->dwAddData = (DWORD)CreateWindow (CTRL_BUTTON, layer->name, WS_CHILD | WS_VISIBLE | BS_CHECKBOX | BS_PUSHLIKE | BS_CENTER, _ID_LAYER_BOX, _LEFT_BOXES + box_width * (nr_boxes - 1), _MARGIN, box_width, _HEIGHT_CTRL, hTaskBar, (DWORD)layer); break; case LCO_DEL_LAYER: DestroyWindow ((HWND)(layer->dwAddData)); layer->dwAddData = 0; nr_boxes --; if (box_width * nr_boxes < _WIDTH_BOXES) { if (nr_boxes != 0) new_width = _WIDTH_BOXES / nr_boxes; else new_width = _MAX_WIDTH_LAYER_BOX; if (new_width > _MAX_WIDTH_LAYER_BOX) new_width = _MAX_WIDTH_LAYER_BOX; adjust_boxes (new_width, layer); box_width = new_width; } break; case LCO_JOIN_CLIENT: break; case LCO_REMOVE_CLIENT: break; case LCO_TOPMOST_CHANGED: on_change_topmost (layer); break; case LCO_ACTIVE_CHANGED: break; default: printf ("Serious error: incorrect operations.\n"); }}static void child_wait (int sig){ int pid; int status; while ((pid = waitpid (-1, &status, WNOHANG)) > 0) { if (WIFEXITED (status)) printf ("--pid=%d--status=%x--rc=%d---\n", pid, status, WEXITSTATUS(status)); else if (WIFSIGNALED(status)) printf ("--pid=%d--signal=%d--\n", pid, WTERMSIG (status)); }}int MiniGUIMain (int args, const char* arg[]){ pid_t pid_desktop; struct sigaction siga; int status; MSG msg; siga.sa_handler = child_wait; siga.sa_flags = 0; memset (&siga.sa_mask, 0, sizeof(sigset_t)); signal(SIGCHLD, on_child_exit); OnNewDelClient = on_new_del_client; OnChangeLayer = on_change_layer;#if _MINIGUI_VERSION_CODE < _VERSION_CODE (1, 3, 0) if (!ServerStartup ()) { fprintf (stderr, "Can not start the server of MiniGUI-Lite: mginit.\n"); return 1; }#endif if (SetDesktopRect (0, g_rcScr.bottom - HEIGHT_TASKBAR - HEIGHT_IMEWIN, g_rcScr.right, g_rcScr.bottom) == 0) { fprintf (stderr, "Empty desktop rect.\n"); return 1; } if (!InitMiniGUIExt ()) { fprintf (stderr, "Can not init mgext library.\n"); return 1; } AboutMiniGUI (); AboutMDE (); if ((hTaskBar = create_task_bar ()) == HWND_INVALID) { fprintf (stderr, "Can not create task bar.\n"); return 2; } pid_desktop = exec_app (app_info.autostart); if (pid_desktop == 0 || waitpid (pid_desktop, &status, WNOHANG) > 0) { fprintf (stderr, "Desktop already have terminated.\n"); Usage (); return 1; } sigaction (SIGCHLD, &siga, NULL); while (GetMessage (&msg, hTaskBar)) { DispatchMessage (&msg); } MiniGUIExtCleanUp (); return 0;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -