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

📄 listbox.c

📁 44b0处理器+UCOS操作系统+miniGUI源代码
💻 C
字号:
/*** $Id: listbox.c,v 1.4 2003/11/22 06:53:19 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 <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>#define IDL_DIR    100#define IDL_FILE   110#define IDC_PATH   120static DLGTEMPLATE DlgDelFiles ={    WS_BORDER | WS_CAPTION,    WS_EX_NONE,    100, 100, 304, 225,    "删除文件",    0, 0,    7, NULL,    0};static CTRLDATA CtrlDelFiles[] ={     {        CTRL_STATIC,        WS_VISIBLE | SS_SIMPLE,         10, 10, 130, 15,        IDC_STATIC,        "目录列表框",        0    },    {        CTRL_LISTBOX,        WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_NOTIFY,        10, 30, 130, 100,        IDL_DIR,        "",        0    },    {        CTRL_STATIC,        WS_VISIBLE | SS_SIMPLE,         150, 10, 130, 15,         IDC_STATIC,        "文件列表框",        0    },    {        CTRL_LISTBOX,        WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_AUTOCHECKBOX,        150, 30, 130, 100,        IDL_FILE,        "",        0    },    {        CTRL_STATIC,        WS_VISIBLE | SS_SIMPLE,         10, 150, 290, 15,         IDC_PATH,        "路径:",        0    },    {        "button",        WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP,        10, 170, 130, 25,        IDOK,         "删除",        0    },    {        "button",        WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,        150, 170, 130, 25,        IDCANCEL,        "取消",        0    },};static void fill_boxes (HWND hDlg, const char* path){#ifdef __ECOS    LISTBOXITEMINFO lbii;    lbii.string = "file.1";    lbii.cmFlag = CMFLAG_BLANK;    lbii.hIcon = 0;    SendDlgItemMessage (hDlg, IDL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii);    lbii.string = "file.2";    SendDlgItemMessage (hDlg, IDL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii);    lbii.string = "file.3";    SendDlgItemMessage (hDlg, IDL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii);#else    struct dirent* dir_ent;    DIR*   dir;    struct stat ftype;    char   fullpath [PATH_MAX + 1];    SendDlgItemMessage (hDlg, IDL_DIR, LB_RESETCONTENT, 0, (LPARAM)0);    SendDlgItemMessage (hDlg, IDL_FILE, 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_DIR, 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_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii);        }    }    closedir (dir);#endif}static void dir_notif_proc (HWND hwnd, int id, int nc, DWORD add_data){    if (nc == LBN_DBLCLK || nc == LBN_ENTER) {        int cur_sel = SendMessage (hwnd, LB_GETCURSEL, 0, 0L);        if (cur_sel >= 0) {            char cwd [MAX_PATH + 1];            char dir [MAX_NAME + 1];            GetWindowText (GetDlgItem (GetParent (hwnd), IDC_PATH), cwd, MAX_PATH);            SendMessage (hwnd, LB_GETTEXT, cur_sel, (LPARAM)dir);            if (strcmp (dir, ".") == 0)                return;            strcat (cwd, "/");	    strcat (cwd, dir);            fill_boxes (GetParent (hwnd), cwd);        }    }}static void file_notif_proc (HWND hwnd, int id, int nc, DWORD add_data){    /* Do nothing */}static void prompt (HWND hDlg){    int i;    char files [1024] = "你选择要删除的文件是:\n";    for (i = 0; i < SendDlgItemMessage (hDlg, IDL_FILE, LB_GETCOUNT, 0, 0L); i++) {	char file [MAX_NAME + 1];        int status = SendDlgItemMessage (hDlg, IDL_FILE, LB_GETCHECKMARK, i, 0);        if (status == CMFLAG_CHECKED) {            SendDlgItemMessage (hDlg, IDL_FILE, LB_GETTEXT, i, (LPARAM)file);	    strcat (files, file);	    strcat (files, "\n");	}    }    MessageBox (hDlg, files, "确认删除", MB_OK | MB_ICONINFORMATION);}static int DelFilesBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){    switch (message) {    case MSG_INITDIALOG:    {        char cwd [MAX_PATH + 1];        SetNotificationCallback (GetDlgItem (hDlg, IDL_DIR), dir_notif_proc);        SetNotificationCallback (GetDlgItem (hDlg, IDL_FILE), file_notif_proc);        fill_boxes (hDlg, getcwd (cwd, MAX_PATH));        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[]){#ifdef _LITE_VERSION    SetDesktopRect(0, 0, 1024, 768);#endif        DlgDelFiles.controls = CtrlDelFiles;        DialogBoxIndirectParam (&DlgDelFiles, HWND_DESKTOP, DelFilesBoxProc, 0L);    return 0;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif

⌨️ 快捷键说明

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