?? listdemo.c
字號:
/*** $Id: listdemo.c,v 1.3 2003/06/13 06:50:39 weiym Exp $** ** Listing 8.1**** listbox.c: Sample program for MiniGUI Programming Guide** The usage of LISTBOX control.** ** Copyright (C) 2003 Feynman Software.**** License: GPL*/#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <sys/stat.h>#include <sys/time.h>#include <sys/types.h>#include <unistd.h>#include <pwd.h>#include <errno.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include <minigui/dti.c>#define IDL_DEMO1 100 //list box#define IDL_DEMO2 110 //check box#define IDC_PATH 120static DLGTEMPLATE DlgListDemo ={ WS_BORDER | WS_CAPTION, WS_EX_NONE, 0, 0, 320, 240, "達盛ListDemo", 0, 0, 7, NULL, 0};static CTRLDATA CtrlListDemoFiles[] ={ { CTRL_STATIC, WS_VISIBLE | SS_SIMPLE, 10, 10, 130, 15, IDC_STATIC, "ListDemo1 Notify", 0 }, { CTRL_LISTBOX, WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_NOTIFY, 10, 30, 130, 100, IDL_DEMO1, "", 0 }, { CTRL_STATIC, WS_VISIBLE | SS_SIMPLE, 150, 10, 130, 15, IDC_STATIC, "ListDemo2 CheckBox", 0 }, { CTRL_LISTBOX, WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_CHECKBOX, 150, 30, 130, 100, IDL_DEMO2, "", 0 },#if 0 { CTRL_STATIC, WS_VISIBLE | SS_SIMPLE, 10, 150, 290, 15, IDC_PATH, "路徑:", 0 },#endif { "button", WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP, 10, 170, 130, 25, IDOK, "OK", 0 }, { "button", WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 150, 170, 130, 25, IDCANCEL, "Cancel", 0 },};#if 0static void fill_boxes (HWND hDlg, const char* path){ struct dirent* dir_ent; DIR* dir; struct stat ftype; char fullpath [PATH_MAX + 1]; SendDlgItemMessage (hDlg, IDL_DEMO1, LB_RESETCONTENT, 0, (LPARAM)0); SendDlgItemMessage (hDlg, IDL_DEMO2, LB_RESETCONTENT, 0, (LPARAM)0); SetWindowText (GetDlgItem (hDlg, IDC_PATH), path); if ((dir = opendir (path)) == NULL) return; while ( (dir_ent = readdir ( dir )) != NULL ) { /* Assemble full path name. */ strncpy (fullpath, path, PATH_MAX); strcat (fullpath, "/"); strcat (fullpath, dir_ent->d_name); if (stat (fullpath, &ftype) < 0 ) { continue; } if (S_ISDIR (ftype.st_mode)) SendDlgItemMessage (hDlg, IDL_DEMO1, LB_ADDSTRING, 0, (LPARAM)dir_ent->d_name); else if (S_ISREG (ftype.st_mode)) { LISTBOXITEMINFO lbii; lbii.string = dir_ent->d_name; lbii.cmFlag = CMFLAG_BLANK; lbii.hIcon = 0; SendDlgItemMessage (hDlg, IDL_DEMO2, LB_ADDSTRING, 0, (LPARAM)&lbii); } } closedir (dir);}#endif#if 1static void prompt (HWND hDlg){ int i; char files [1024] = "你選擇要刪除的文件是:\n"; for (i = 0; i < SendDlgItemMessage (hDlg, IDL_DEMO2, LB_GETCOUNT, 0, 0L); i++) { char file [MAX_NAME + 1]; int status = SendDlgItemMessage (hDlg, IDL_DEMO2, LB_GETCHECKMARK, i, 0); if (status == CMFLAG_CHECKED) { SendDlgItemMessage (hDlg, IDL_DEMO2, LB_GETTEXT, i, (LPARAM)file); strcat (files, file); strcat (files, "\n"); } } MessageBox (hDlg, files, "確認刪除", MB_OK | MB_ICONINFORMATION);}#endifstatic int ListDemoFilesBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){ switch (message) { case MSG_INITDIALOG: { char demo1 [20]= "Hello,demo1"; SendMessage (GetDlgItem (hDlg, IDL_DEMO1), LB_ADDSTRING,0,(LPARAM)demo1); SendMessage (GetDlgItem (hDlg, IDL_DEMO1), LB_ADDSTRING,0,(LPARAM)"demo1 string1"); SendMessage (GetDlgItem (hDlg, IDL_DEMO1), LB_ADDSTRING,0,(LPARAM)"demo1 string2");#if 0 LISTBOXITEMINFO lbii; lbii.string = "Hello demo2"; lbii.cmFlag = CMFLAG_BLANK; lbii.hIcon = 0; SendDlgItemMessage (hDlg, IDL_DEMO2, LB_ADDSTRING, 0, (LPARAM)&lbii); lbii.string = "demo2 string"; lbii.cmFlag = CMFLAG_CHECKED; lbii.hIcon = 0; SendDlgItemMessage (hDlg, IDL_DEMO2, LB_ADDSTRING, 0, (LPARAM)&lbii);#endif return 1; } case MSG_COMMAND: switch (wParam) { case IDOK: prompt (hDlg); case IDCANCEL: EndDialog (hDlg, wParam); break; } break; } return DefaultDialogProc (hDlg, message, wParam, lParam);}int MiniGUIMain (int argc, const char* argv[]){ DlgListDemo.controls = CtrlListDemoFiles; DialogBoxIndirectParam (&DlgListDemo, HWND_DESKTOP, ListDemoFilesBoxProc, 0L); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -