resmanager.c
来自「MINI GUI1.6X源码」· C语言 代码 · 共 959 行 · 第 1/2 页
C
959 行
/*** $Id: resmanager.c,v 1.4 2005/09/04 07:18:40 jpzhang Exp $**** main.c: The main entry of control demo program.**** 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 <unistd.h>#include <signal.h>#include <time.h>#include <sys/stat.h>#include <sys/types.h>#include <sys/wait.h>#include <math.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>#define DEFAULT_WIDTH 800#define DEFAULT_HEIGHT 600#define IDM_NEW 111#define IDM_OPEN 112#define IDM_SAVE 113#define IDM_SAVEAS 114#define IDM_CLOSE 115#define IDM_EXIT 116#define IDC_TREEVIEW 117#define IDC_LISTVIEW 118#define IDM_ABOUT 311#define IDM_ABOUT_THIS 322#define IDM_STATIC 211#define IDM_BUTTON 212#define IDM_MENUBUTTON 213#define IDM_EDIT 214#define IDM_LISTBOX 215#define IDM_PROGRESSBAR 216#define IDM_COMBOBOX 217#define IDM_TOOLBAR 218#define IDM_TRACKBAR 219#define IDM_LISTVIEW 221#define IDM_TREEVIEW 222#define IDM_MONTHCALENDAR 223#define IDM_SPINBOX 224#define IDM_COOLBAR 225#define IDM_SUBCLASS 231#define IDM_TIMEEDIT 232#define IDM_NEWTOOLBAR 233LVITEM myitem;LVSUBITEM mysubdata1;struct dirent *mydir_ent;DIR *mydir;static BITMAP foldercc;static HWND hMainWnd = HWND_INVALID;static HWND hChildWndList;static HWND hChildWnd1;static HICON hIconFold, hIconUnfold;static void ModifyListView (char *mypath);static pid_t exec_app (char *path, char *app, char *arg);static HMENUcreatepmenuabout (void){ HMENU hmnu; MENUITEMINFO mii; memset (&mii, 0, sizeof (MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 0; mii.typedata = (DWORD) "About..."; hmnu = CreatePopupMenu (&mii); memset (&mii, 0, sizeof (MENUITEMINFO)); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_ABOUT_THIS; mii.typedata = (DWORD) "About MiniGUI Controls..."; InsertMenuItem (hmnu, 0, TRUE, &mii); memset (&mii, 0, sizeof (MENUITEMINFO)); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_ABOUT; mii.typedata = (DWORD) "About MiniGUI..."; InsertMenuItem (hmnu, 1, TRUE, &mii); return hmnu;}static HMENUcreatepmenufile (void){ HMENU hmnu; MENUITEMINFO mii; memset (&mii, 0, sizeof (MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 0; mii.typedata = (DWORD) "File"; hmnu = CreatePopupMenu (&mii); memset (&mii, 0, sizeof (MENUITEMINFO)); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_NEW; mii.typedata = (DWORD) "New"; InsertMenuItem (hmnu, 0, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_OPEN; mii.typedata = (DWORD) "Open..."; InsertMenuItem (hmnu, 1, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_SAVE; mii.typedata = (DWORD) "Save"; InsertMenuItem (hmnu, 2, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_SAVEAS; mii.typedata = (DWORD) "Save As..."; InsertMenuItem (hmnu, 3, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_CLOSE; mii.typedata = (DWORD) "Close"; InsertMenuItem (hmnu, 4, TRUE, &mii); mii.type = MFT_SEPARATOR; mii.state = 0; mii.id = 0; mii.typedata = 0; InsertMenuItem (hmnu, 5, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_EXIT; mii.typedata = (DWORD) "Exit"; InsertMenuItem (hmnu, 6, TRUE, &mii); return hmnu;}static HMENUcreatepmenuobject (void){ HMENU hmnu; MENUITEMINFO mii; memset (&mii, 0, sizeof (MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 0; mii.typedata = (DWORD) "Controls"; hmnu = CreatePopupMenu (&mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_STATIC; mii.typedata = (DWORD) "Static control"; InsertMenuItem (hmnu, 0, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_BUTTON; mii.typedata = (DWORD) "Button control"; InsertMenuItem (hmnu, 1, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_MENUBUTTON; mii.typedata = (DWORD) "MenuButton control"; InsertMenuItem (hmnu, 2, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_EDIT; mii.typedata = (DWORD) "Edit control"; InsertMenuItem (hmnu, 3, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_LISTBOX; mii.typedata = (DWORD) "ListBox control"; InsertMenuItem (hmnu, 4, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_PROGRESSBAR; mii.typedata = (DWORD) "ProgressBar control"; InsertMenuItem (hmnu, 5, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_COMBOBOX; mii.typedata = (DWORD) "ComboBox control"; InsertMenuItem (hmnu, 6, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_TOOLBAR; mii.typedata = (DWORD) "NewToolBar control"; InsertMenuItem (hmnu, 7, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_TRACKBAR; mii.typedata = (DWORD) "TrackBar control"; InsertMenuItem (hmnu, 8, TRUE, &mii); mii.type = MFT_SEPARATOR; mii.state = 0; mii.id = 0; mii.typedata = 0; InsertMenuItem (hmnu, 9, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_LISTVIEW; mii.typedata = (DWORD) "ListView control"; InsertMenuItem (hmnu, 10, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_TREEVIEW; mii.typedata = (DWORD) "TreeView control"; InsertMenuItem (hmnu, 11, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_MONTHCALENDAR; mii.typedata = (DWORD) "MonthCalendar control"; InsertMenuItem (hmnu, 12, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_SPINBOX; mii.typedata = (DWORD) "SpinBox control"; InsertMenuItem (hmnu, 13, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_COOLBAR; mii.typedata = (DWORD) "CoolBar control"; InsertMenuItem (hmnu, 14, TRUE, &mii); mii.type = MFT_SEPARATOR; mii.state = 0; mii.id = 0; mii.typedata = 0; InsertMenuItem (hmnu, 15, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_SUBCLASS; mii.typedata = (DWORD) "Control Subclass"; InsertMenuItem (hmnu, 16, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_TIMEEDIT; mii.typedata = (DWORD) "Time Editor"; InsertMenuItem (hmnu, 17, TRUE, &mii); return hmnu;}static HMENUcreatemenu (void){ HMENU hmnu; MENUITEMINFO mii; hmnu = CreateMenu (); memset (&mii, 0, sizeof (MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 100; mii.typedata = (DWORD) "File"; mii.hsubmenu = createpmenufile (); InsertMenuItem (hmnu, 0, TRUE, &mii); mii.type = MFT_STRING; mii.id = 110; mii.typedata = (DWORD) "Controls"; mii.hsubmenu = createpmenuobject (); InsertMenuItem (hmnu, 2, TRUE, &mii); mii.type = MFT_STRING; mii.id = 120; mii.typedata = (DWORD) "About"; mii.hsubmenu = createpmenuabout (); InsertMenuItem (hmnu, 3, TRUE, &mii); return hmnu;}/* list view */intcompare_time (int nItem1, int nItem2, PLVSORTDATA sortData){ DWORD data1, data2; struct stat stat1, stat2; data1 = SendMessage (hChildWndList, LVM_GETITEMADDDATA, 0, nItem1); data2 = SendMessage (hChildWndList, LVM_GETITEMADDDATA, 0, nItem2); stat ((char *) data1, &stat1); stat ((char *) data2, &stat2); return (stat2.st_mtime - stat1.st_mtime);}intcompare_size (int nItem1, int nItem2, PLVSORTDATA sortData){ DWORD data1, data2; struct stat stat1, stat2; int size1, size2; data1 = SendMessage (hChildWndList, LVM_GETITEMADDDATA, 0, nItem1); data2 = SendMessage (hChildWndList, LVM_GETITEMADDDATA, 0, nItem2); stat ((char *) data1, &stat1); stat ((char *) data2, &stat2); if (S_ISREG (stat1.st_mode)) size1 = stat1.st_size; else size1 = 0; if (S_ISREG (stat2.st_mode)) size2 = stat2.st_size; else size2 = 0; return (size1 - size2);}static pid_texec_app (char *path, char *app, char *arg){ 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) { fprintf (stderr, "child process----%s\n", path); chdir (path); strcpy (buff, "./"); strcat (buff, app); execl (buff, app, arg, NULL); } else { perror ("vfork"); } return pid;}static voidlv_notify_process (HWND hwnd, int id, int code, DWORD addData){ LVSUBITEM subItem; int nItem; char pszText[50]; memset (pszText, 0x00, 50); subItem.pszText = pszText; if (code == LVN_KEYDOWN) { PLVNM_KEYDOWN down; int key; down = (PLVNM_KEYDOWN) addData; key = LOWORD (down->wParam); if (key == SCANCODE_REMOVE) { int nItem; nItem = SendMessage (hwnd, LVM_GETSELECTEDITEM, 0, 0); if (nItem > 0) { if (MessageBox (hMainWnd, "are you really want to delete this file?", "warning", MB_YESNO) == IDYES) { // not really delete yet. SendMessage (hwnd, LVM_DELITEM, nItem, 0); } } } if (key == SCANCODE_ENTER) { } } if (code == LVN_ITEMRUP) { PLVNM_ITEMRUP up; int x, y; up = (PLVNM_ITEMRUP) addData; x = LOSWORD (up->lParam); y = HISWORD (up->lParam); ClientToScreen (hChildWndList, &x, &y); // TrackPopupMenu (GetPopupSubMenu (hRightMenu), TPM_LEFTALIGN | TPM_LEFTBUTTON , // x, y, hMainWnd); } if (code == LVN_ITEMDBCLK) { nItem = SendMessage (hwnd, LVM_GETSELECTEDITEM, 0, 0); if (nItem > 0) { subItem.nItem = nItem; subItem.subItem = 3; SendMessage (hwnd, LVM_GETSUBITEMTEXT, 0, (LPARAM) & subItem); if (strcmp (subItem.pszText, "directory") == 0) { GHANDLE itemParent, found; subItem.subItem = 1; subItem.nItem = nItem; SendMessage (hwnd, LVM_GETSUBITEMTEXT, 0, (LPARAM) & subItem); itemParent = SendMessage (hChildWnd1, TVM_GETSELITEM, 0, 0); found = SendMessage (hChildWnd1, TVM_FINDCHILD, (WPARAM) itemParent, (LPARAM) subItem.pszText); SendMessage (hChildWnd1, TVM_SETSELITEM, (WPARAM) found, 0); } else { GHANDLE item; char *ptrpath = NULL; char buffer[50]; char pathnameb[PATH_MAX + 1]; subItem.subItem = 1; subItem.nItem = nItem;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?