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

📄 filedlg.c

📁 这是一个介绍 linux 编程知识的文章。
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Written by You Huayun.
//   2000/2/26
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
#include <pthread.h>
#include <semaphore.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>

#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>

#include "../include/vacs.h"
#include "filedlg.h"
#include "filemanage.h"

#define IDC_DIRLST1         100
#define IDC_FILELST1        110
#define IDC_FILENAME        120
#define IDC_CLFILE1         130
#define IDC_NCFILE1         140


#define IDC_DIRLST2         200
#define IDC_FILELST2        210
#define IDC_FILETODEL       220
#define IDC_CLFILE2         230
#define IDC_NCFILE2         240
#define IDC_CHKDEL          250

#define IDC_DIRLST3         300
#define IDC_FILELST3        310
#define IDC_FILESRCE        320
#define IDC_FILEDEST        330
#define IDC_CLFILE3         340
#define IDC_NCFILE3         350
#define IDC_CHKOVR          360

#define IDC_DIRLST4         400
#define IDC_FILELST4        410
#define IDC_CLFILE4         420
#define IDC_NCFILE4         430

static void ListDir ( HWND hWnd, int dirListID, int fileListID, char* path)
{
    struct dirent* pDirEnt;
    DIR* dir;
    struct stat ftype;
    char fullpath [PATH_MAX + 1];

    dir = opendir (path);
    while ( (pDirEnt = readdir ( dir )) != NULL ) {

        // Assemble full path name.
        strcpy (fullpath, path);
        strcat (fullpath, "/");
        strcat (fullpath, pDirEnt->d_name);
        
        if (lstat (fullpath, &ftype) < 0 ){
           Ping();
           continue;
        }
        if (S_ISDIR (ftype.st_mode))
            SendDlgItemMessage( hWnd, dirListID, LB_ADDSTRING,
                             0, (LPARAM)pDirEnt->d_name);
        else if (S_ISREG(ftype.st_mode))   
            SendDlgItemMessage( hWnd, fileListID, LB_ADDSTRING,
                             0, (LPARAM)pDirEnt->d_name); 
    }
    closedir(dir);
}

static void ChangeDirList (HWND hWnd, int dirListID, int fileListID, 
                int editID, char* path)
{
    char msg [PATH_MAX + 30];
    
    SendDlgItemMessage (hWnd, dirListID, LB_RESETCONTENT, 0, (LPARAM)0);
    SendDlgItemMessage (hWnd, fileListID, LB_RESETCONTENT, 0, (LPARAM)0);
    if (editID)
        SetWindowText (GetDlgItem (hWnd, editID), "");

    sprintf (msg, "对不起,未找到指定的目录:\n\n%s\n", path);
    if( access( path, F_OK ) == -1){
         MessageBox( hWnd, msg, "提示信息", MB_OK | MB_ICONSTOP);
         return;
    }

    ListDir ( hWnd, dirListID, fileListID, path);
}

DLGTEMPLATE DlgFileOpenInfo = 
{
    WS_BORDER | WS_CAPTION, WS_EX_NONE,
    180, 80, 430, 315, "打开文件", 0, 0, 11, NULL
};

CTRLDATA CtrlFileOpenInfo [] = 
{
    { "static", WS_VISIBLE | SS_SIMPLE,
        10, 10, 40, 40, IDC_STATIC, "LOGO", 0 },
    { "static", WS_VISIBLE | SS_LEFT,
        50, 10, 90, 24, IDC_STATIC, "目录", 0 },
    { "static", WS_VISIBLE | SS_LEFT,
        142, 10, 260, 24, IDC_STATIC, "文件", 0 },
    { "listbox", WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_VSCROLL | WS_BORDER,
        50, 35, 90, 195, IDC_DIRLST1, NULL, 0 },
    { "listbox", WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_VSCROLL | WS_BORDER,
        142, 35, 138, 195, IDC_FILELST1, NULL, 0 },
    { "static", WS_VISIBLE | SS_LEFT,
        50, 250, 60, 24, IDC_STATIC, "文件名:", 0 },
    { "edit", WS_VISIBLE | WS_TABSTOP | WS_BORDER,
        110, 245, 170, 24, IDC_FILENAME, NULL, 0 },
    { "button", WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
        305, 35, 100, 26, IDC_CLFILE1, "刀位文件", 0 },
    { "button", WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
        305, 70, 100, 26, IDC_NCFILE1, "数控文件", 0 },
    { "button", WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP,
        305, 210, 100, 26, IDOK, "打开", 0 },
    { "button", WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
        305, 245, 100, 26, IDCANCEL, "取消", 0 }
};

static int
DialogFileOpenProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
    case MSG_INITDIALOG:
    {
        struct FileOpenInfo* fi = (struct FileOpenInfo*) lParam;
        
        ListDir (hDlg, IDC_DIRLST1, IDC_FILELST1, fi->dir);

        SetWindowText (GetDlgItem (hDlg, IDC_FILENAME), fi->filename);
        SetWindowAdditionalData2 (hDlg, (DWORD)lParam);
        return 1;
    }
        
    case MSG_COMMAND:
    {
        struct FileOpenInfo* fi = 
            (struct FileOpenInfo*) GetWindowAdditionalData2 (hDlg);
        int nSelect;
        int id = LOWORD (wParam);
        int code = HIWORD (wParam);
 
        switch (id) {
        case IDC_DIRLST1:
        {/*
            char dir[NAME_MAX + 1];
            
            if (code == LBN_DBLCLK){
                nSelect = 
                    SendDlgItemMessage(hDlg, IDC_DIRLST1, LB_GETCURSEL, 0, 0);
                if (nSelect != -1)
                    SendDlgItemMessage(hDlg, IDC_DIRLST1, LB_GETTEXT, 
                                nSelect, (LPARAM)dir);
                if (strcmp (fi->dir, ".") ==0 )
                    break;
                else ;    
                strcat (fi->dir, "/");
                strcat (fi->dir, dir);
                MessageBox (hDlg, fi->dir, "Error", MB_OK);
                //GetAbsolutePathName (dir, fi->dir);
                ChangeDirList (hDlg, IDC_DIRLST1, IDC_FILELST1, 
                                IDC_FILENAME, fi->dir);
                                
            }*/
            break;
        }
        
        case IDC_FILELST1:
        {
            if (code == LBN_SELCHANGE) {
                nSelect = 
                    SendDlgItemMessage(hDlg, IDC_FILELST1, LB_GETCURSEL, 0, 0);
                if(nSelect != -1)
                    SendDlgItemMessage(hDlg, IDC_FILELST1, LB_GETTEXT, 
                                nSelect, (LPARAM)fi->filename);
                SetWindowText(GetDlgItem(hDlg, IDC_FILENAME), fi->filename);
            }
            break;
        }
        
        case IDC_CLFILE1:
            if (code != 0) break;

            GetAbsolutePathName (DIR_DATA_CL, fi->dir);
            if( access( fi->dir, F_OK ) == -1){
               MessageBox( hDlg, "对不起,未找到刀位文件所在目录",
                            "提示信息", MB_OK | MB_ICONSTOP);
                break;
            }
            ChangeDirList (hDlg, IDC_DIRLST1, IDC_FILELST1, 
                            IDC_FILENAME, fi->dir);
            break;
        
        case IDC_NCFILE1:
            if (code != 0) break;

            GetAbsolutePathName (DIR_DATA_NC, fi->dir);
            if( access( fi->dir, F_OK ) == -1){
                MessageBox( hDlg, "对不起,未找到数控文件所在目录",
                            "提示信息", MB_OK | MB_ICONSTOP);
                break;
            }
            ChangeDirList (hDlg, IDC_DIRLST1, IDC_FILELST1, 
                            IDC_FILENAME, fi->dir);
            break;        
        
        case IDOK:
        {
            char msg[PATH_MAX + 16];

            if( code != 0) break;

            GetWindowText (GetDlgItem(hDlg, IDC_FILENAME), 
                           fi->filename, NAME_MAX);
            if (fi->filename[0] == '\0') {
                MessageBox (hDlg, 
                    "请注意文件名:\n\n输入的文件名中不要"
                    "夹杂空格,\n尤其头尾不要留有空格,\n文件名中不能使"
                    "用 / 字符.\n\n请输入正确的文件名.", 
                    "打开文件出错", 
                    MB_OK | MB_ICONINFORMATION);
                break;
            }
            
            strcpy(fi->fullname, fi->dir);
            strcat(fi->fullname, "/");
            strcat(fi->fullname, fi->filename);
            if (access (fi->fullname, F_OK) == -1) {
                if (!fi->IsEdit) {
                    sprintf (msg, "文件 %s 不存在!", fi->filename);
                    MessageBox (hDlg, msg, "打开文件出错", MB_OK | MB_ICONSTOP);
                    break;
                }
                else {
                    sprintf(msg, 
                            "文件:\n\n  %s\n\n 不存在,是否创建该文件?",
                            fi->filename);
                    if (MessageBox (hDlg, 
                                msg,
                                "确认信息", 
                                MB_YESNO | MB_ICONQUESTION) != IDYES)
                       break;
                }   
            }    
            EndDialog (hDlg, IDOK);
            break;
	    }

        case IDCANCEL:
            if( code != 0) break;

            EndDialog (hDlg, wParam);
            break;
        }
	
        break;
    }
    }
    return DefaultDialogProc (hDlg, message, wParam, lParam);
}

int FileOpenDialogBox (HWND hWnd, struct FileOpenInfo* fi)
{
    DlgFileOpenInfo.controls = CtrlFileOpenInfo;

    if (DialogBoxIndirectParam (&DlgFileOpenInfo, hWnd, 
          DialogFileOpenProc, (LPARAM)fi) == IDOK)
        return VACS_OK;
    else
        return VACS_ERROR_GUI;
}


DLGTEMPLATE DlgFileDeleteInfo = 
{
    WS_BORDER | WS_CAPTION, WS_EX_NONE,
    180, 80, 430, 315, "删除文件", 0, 0, 12, NULL
};

CTRLDATA CtrlFileDeleteInfo [] = 
{
    { "static", WS_VISIBLE | SS_SIMPLE,
        10, 10, 40, 40, IDC_STATIC, "LOGO", 0 },
    { "static", WS_VISIBLE | SS_LEFT,
        50, 10, 90, 24, IDC_STATIC, "目录", 0 },
    { "static", WS_VISIBLE | SS_LEFT,
        142, 10, 260, 24, IDC_STATIC, "文件", 0 },
    { "listbox", WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_VSCROLL | WS_BORDER,
        50, 35, 90, 164, IDC_DIRLST2, NULL, 0 },
    { "listbox", WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_VSCROLL | WS_BORDER,
        142, 35, 138, 164, IDC_FILELST2, NULL, 0 },
    { "static", WS_VISIBLE | SS_LEFT,
        50, 215, 60, 24, IDC_STATIC, "文件名:", 0 },
    { "edit", WS_VISIBLE | WS_TABSTOP | WS_BORDER,
        110, 210, 170, 24, IDC_FILETODEL, NULL, 0 },
    { "button", WS_VISIBLE | BS_AUTOCHECKBOX | WS_TABSTOP, 
        50, 250, 200, 26, IDC_CHKDEL, "删除文件,不经确认", 0 },
    { "button", WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
        305, 35, 100, 26, IDC_CLFILE2, "刀位文件", 0 },
    { "button", WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
        305, 70, 100, 26, IDC_NCFILE2, "数控文件", 0 },
    { "button", WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP,
        305, 210, 100, 26, IDOK, "删除", 0 },
    { "button", WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
        305, 245, 100, 26, IDCANCEL, "取消", 0 }
};


static int
DialogFileDeleteProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
    case MSG_INITDIALOG:
    {
        struct FileDeleteInfo* fi = (struct FileDeleteInfo*) lParam;
    
        ListDir (hDlg, IDC_DIRLST2, IDC_FILELST2, fi->dir);
        SetWindowAdditionalData2 (hDlg, (DWORD)lParam);
        return 1;
    }
        
    case MSG_COMMAND:
    {
    	struct FileDeleteInfo *fi = (struct FileDeleteInfo*)
				                    GetWindowAdditionalData2 (hDlg);
        int id = LOWORD( wParam );
        int code = HIWORD ( wParam );
        int nSelect;

        switch (id) {
        case IDC_FILELST2:
            if (code == LBN_SELCHANGE) {
                    nSelect = SendDlgItemMessage( hDlg, IDC_FILELST2,
                                                 LB_GETCURSEL, 0, 0);
                if (nSelect == -1)
                    break;
                SendDlgItemMessage(hDlg, IDC_FILELST2, LB_GETTEXT, 
                                  nSelect, (LPARAM)fi->filename);
                SetWindowText(GetDlgItem(hDlg, IDC_FILETODEL), 
                                  fi->filename);
            }
            break;
            
        case IDC_CLFILE2:
            if (code != 0) break;

            GetAbsolutePathName (DIR_DATA_CL, fi->dir);
            if (access( fi->dir, F_OK ) == -1) {
                MessageBox (hDlg, 
                        "对不起,未找到刀位文件所在目录",
                        "提示信息", 
                        MB_OK | MB_ICONSTOP);
                break;
            }
            ChangeDirList (hDlg, IDC_DIRLST2, IDC_FILELST2, 
                                    IDC_FILETODEL, fi->dir);
            break;
            

⌨️ 快捷键说明

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