📄 resmanager.c
字号:
/*** $Id: resmanager.c,v 1.7 2005/11/02 09:18:55 qzlong 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);/* 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);}#if 0static 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;}#endifstatic 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; SendMessage (hwnd, LVM_GETSUBITEMTEXT, 0, (LPARAM) & subItem); memset (pathnameb, 0x00, PATH_MAX + 1); ptrpath = pathnameb + PATH_MAX; item = SendMessage (hChildWnd1, TVM_GETSELITEM, 0, 0); *ptrpath = '/'; ptrpath++; *ptrpath = 0; while (item != 0) { SendMessage (hChildWnd1, TVM_GETITEMTEXT, (WPARAM) item, (LPARAM) buffer); ptrpath = ptrpath - 1 - strlen (buffer) - 1; *ptrpath++ = '/'; strncpy (ptrpath, buffer, strlen (buffer)); item = SendMessage (hChildWnd1, TVM_GETRELATEDITEM, TVIR_PARENT, (LPARAM) item); }#if 0 fprintf (stderr, "---------%s\n", ptrpath); exec_app (ptrpath, subItem.pszText, 0);#endif } } }}/* end list view *//* tree view */static voidtv_notify_process (HWND hWnd, int id, int code, DWORD addData){ DIR *dir; struct dirent *dir_ent; struct stat my_stat; TVITEMINFO itemInfo; GHANDLE itemtree; GHANDLE curItem; GHANDLE item; char pathname[PATH_MAX + 1]; char *ptr = NULL; char buffer[50]; char pathnameb[PATH_MAX + 1]; char proname[50]; switch (code) { case TVN_CLICKED: break; case TVN_DBLCLK: break; case TVN_SELCHANGE: case TVN_UNFOLDED: itemtree = 0; curItem = 0; item = 0; memset (pathname, 0x00, PATH_MAX + 1); memset (pathnameb, 0x00, PATH_MAX + 1); curItem = SendMessage (hWnd, TVM_GETSELITEM, 0, 0); curItem = SendMessage (hWnd, TVM_GETRELATEDITEM, TVIR_FIRSTCHILD, (LPARAM) curItem); item = SendMessage (hWnd, TVM_GETRELATEDITEM, TVIR_NEXTSIBLING, (LPARAM) curItem); while (item != 0) { SendMessage (hWnd, TVM_DELTREE, (WPARAM) item, 0); item = SendMessage (hWnd, TVM_GETRELATEDITEM, TVIR_NEXTSIBLING, (LPARAM) curItem); } curItem = SendMessage (hWnd, TVM_GETSELITEM, 0, 0); item = curItem; SendMessage (hWnd, TVM_GETITEMTEXT, (WPARAM) curItem, (LPARAM) buffer); strcpy (proname, buffer); ptr = pathnameb + PATH_MAX - strlen (buffer) - 1; *ptr = '/'; ptr++; strcat(ptr, buffer); while (item != 0) { item = SendMessage (hWnd, TVM_GETRELATEDITEM, TVIR_PARENT, (LPARAM) item); SendMessage (hWnd, TVM_GETITEMTEXT, (WPARAM) item, (LPARAM) buffer); ptr = ptr -1 -strlen(buffer) -1; *ptr++='/'; strncpy(ptr,buffer,strlen(buffer)); } if (stat (ptr, &my_stat) < 0) return; if (S_ISREG (my_stat.st_mode)) return; dir = opendir (ptr); if (dir == NULL) { MessageBox (hChildWnd1, "Cann't Open it!", "Error", MB_OK | MB_ICONSTOP); return; } else { ModifyListView (ptr); } strcpy (pathname, ptr); ptr = pathname + strlen (pathname);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -