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

📄 dialog.c

📁 这是早期MiniGUI DOS版本的最终版
💻 C
📖 第 1 页 / 共 5 页
字号:
 */
int FAR OpenBoxProc( PDLGHEADER pDlgHeader, UINT uAction, WORD wID, LONG lParam )
{
    char filename[_MAX_PATH + 1];
    int iIndex, drive;
    PCTRLDATA pCtrlData;
    static LPOPENFILEBOX lpOpenFileBox;

    switch(uAction)
    {
        case INITDIALOG:
            lpOpenFileBox = (LPOPENFILEBOX)lParam;

            _chdrive(lpOpenFileBox->iInitDrive);
            _fstrcpy(filename, lpOpenFileBox->lpInitDir);
            _chdir(filename);

            SetEditBoxText(pDlgHeader, IDC_FILENAME, lpOpenFileBox->lpExt);
            _fstrcpy(filename, lpOpenFileBox->lpExt);
            FillFileListBox(pDlgHeader, IDC_FILE, filename);

            FillDirListBox(pDlgHeader, IDC_DIR);
        return DEFAULT;
        
        case FOCUSCOMMAND:
            if(wID == IDC_FILE)
            {
                iIndex = GetSelectedItem(pDlgHeader, IDC_FILE);
                GetListBoxItem(pDlgHeader, IDC_FILE, filename, iIndex);
                SetEditBoxText(pDlgHeader, IDC_FILENAME, filename);
                pCtrlData = GetControlData(pDlgHeader, IDC_FILENAME);
                OutFieldEditText(pCtrlData, FALSE);
                return DEFAULT;
            }
        break;                
            
        case COMMAND:
            switch(wID)
            {
                case IDOK:
                    _getdcwd(_getdrive(), filename, _MAX_PATH);
                    _fstrcpy(lpOpenFileBox->lpFileName, filename);
                    GetEditBoxText(pDlgHeader, IDC_FILENAME, filename, 13);
                    if(strchr(filename, '*') != NULL
                        || strchr(filename, '?') != NULL)
                    {
                        pCtrlData = GetControlData(pDlgHeader, IDC_FILE);
                        ReleaseListBoxBuff(pCtrlData);
                        
                        FillFileListBox(pDlgHeader, IDC_FILE, filename);
                        SetFocus(NULL);
                        FillListBox(pCtrlData);
                        return DEFAULT;
                    }
                    else if(!CheckFileName(lpOpenFileBox->fOpen, filename))
                        return DEFAULT;

                    // get path name
                    if(_fstrlen(lpOpenFileBox->lpFileName) > 3)
                        _fstrcat(lpOpenFileBox->lpFileName, "\\");
                    _fstrcat(lpOpenFileBox->lpFileName, filename);
                    
                     // set directory to the default directory.
                    _chdrive(lpOpenFileBox->iInitDrive);
                    _fstrcpy(filename, lpOpenFileBox->lpInitDir);
                    _chdir(filename);
                     return CLOSE;
                
                case IDCANCEL:
                    // set directory to the default directory.
                    *(lpOpenFileBox->lpFileName) = '\0';
                    _chdrive(lpOpenFileBox->iInitDrive);
                    _fstrcpy(filename, lpOpenFileBox->lpInitDir);
                    _chdir(filename);
                return CLOSE;
                
                case IDC_FILENAME:
                    _getdcwd(_getdrive(), filename, _MAX_PATH);
                    _fstrcpy(lpOpenFileBox->lpFileName, filename);
                    GetEditBoxText(pDlgHeader, IDC_FILENAME, filename, 13);
                    if(strchr(filename, '*') != NULL
                        || strchr(filename, '?') != NULL)
                    {
                        pCtrlData = GetControlData(pDlgHeader, IDC_FILE);
                        ReleaseListBoxBuff(pCtrlData);
                        
                        FillFileListBox(pDlgHeader, IDC_FILE, filename);
                        SetFocus(NULL);
                        FillListBox(pCtrlData);
                        return DEFAULT;
                    }
                    else if(!CheckFileName(lpOpenFileBox->fOpen, filename))
                        return DEFAULT;

                    // get path name
                    if(_fstrlen(lpOpenFileBox->lpFileName) > 3)
                        _fstrcat(lpOpenFileBox->lpFileName, "\\");
                    _fstrcat(lpOpenFileBox->lpFileName, filename);
                    
                    // set directory to the default directory.
                    _chdrive(lpOpenFileBox->iInitDrive);
                    _fstrcpy(filename, lpOpenFileBox->lpInitDir);
                    _chdir(filename);
                    return CLOSE;
                    
                case IDC_FILE:
                    if(GetListItemNum(pDlgHeader, IDC_FILE) < 1)
                        return DEFAULT;
                        
                    // get path name
                    _getdcwd(_getdrive(), filename, _MAX_PATH);
                    _fstrcpy(lpOpenFileBox->lpFileName, filename);
                    iIndex = GetSelectedItem(pDlgHeader, IDC_FILE);
                    GetListBoxItem(pDlgHeader, IDC_FILE, filename, iIndex);

                    if(!lpOpenFileBox->fOpen)
                    {
                        if(MessageBox(NULL, "给定的文件已存在,是否替换?", "文件另存为", 
                                MB_YESNO | MB_ICONQUESTION) == IDNO)
                            return DEFAULT;
                    }
                    if(_fstrlen(lpOpenFileBox->lpFileName) > 3)
                        _fstrcat(lpOpenFileBox->lpFileName, "\\");
                    _fstrcat(lpOpenFileBox->lpFileName, filename);

                    // set directory to the default directory.
                    _chdrive(lpOpenFileBox->iInitDrive);
                    _fstrcpy(filename, lpOpenFileBox->lpInitDir);
                    _chdir(filename);
                    return CLOSE;
                break;
                
                case IDC_DIR:
                    iIndex = GetSelectedItem(pDlgHeader, IDC_DIR);
                    drive = GetListItemNum(pDlgHeader, IDC_DIR) - iIndex;
                    if(drive < 3)
                    {
                        drive += 2;
                        _chdrive(drive);
                    }
                    else
                    {
                        GetListBoxItem(pDlgHeader, IDC_DIR, filename, iIndex);
                        _chdir(filename);
                    }
                    
                    _getdcwd(_getdrive(), filename, _MAX_PATH);
                    DrawTextInStaticItem(pDlgHeader, IDC_DIRECTORY, filename );

                    pCtrlData = GetControlData(pDlgHeader, IDC_DIR);
                    ReleaseListBoxBuff(pCtrlData);
                    FillDirListBox(pDlgHeader, IDC_DIR);
                    SetFocus(NULL);
                    FillListBox(pCtrlData);

                    GetEditBoxText(pDlgHeader, IDC_FILENAME, filename, 13);
                    pCtrlData = GetControlData(pDlgHeader, IDC_FILE);
                    ReleaseListBoxBuff(pCtrlData);
                    FillFileListBox(pDlgHeader, IDC_FILE, filename);
                    SetFocus(NULL);
                    FillListBox(pCtrlData);
                break;

                default:
                break;
            }
        break;

        case DRAWTEXT:
            if( wID == IDC_DIRECTORY)
            {
                _getdcwd(_getdrive(), filename, _MAX_PATH);
                cc_wt16(filename, ((PCTRLDATA)lParam)->lx, ((PCTRLDATA)lParam)->ty);
                return OWNER;
            }
        return DEFAULT;
        
        default:
        return DEFAULT;
    }
    return DEFAULT;
}

/*
 * Function: int FAR SimpleOpenBoxProc( PDLGHEADER pDlgHeader, UINT uAction, PCTRLDATA pCtrlData, LONG lParam ).
 *      This function Process the simple open file dialog box.
 * Parameters:
 *      pDlgHeader: the pointer to DLGHEADER structure.
 *      uAction: the Message given by DialogBoxParam function;
 *      pCtrlData: the control that have input focus;
 *      lParam: the LONG type parameter.
 * Return: 
 */
int FAR SimpleOpenBoxProc( PDLGHEADER pDlgHeader, UINT uAction, WORD wID, LONG lParam )
{
    char filename[_MAX_PATH + 1];
    PCTRLDATA pCtrlData;
    static LPOPENFILEBOX lpOpenFileBox;
    int iIndex;

    switch(uAction)
    {
        case INITDIALOG:
            lpOpenFileBox = (LPOPENFILEBOX)lParam;

            _chdrive(lpOpenFileBox->iInitDrive);
            _fstrcpy(filename, lpOpenFileBox->lpInitDir);
            _chdir(filename);

            SetEditBoxText(pDlgHeader, IDC_FILENAME, lpOpenFileBox->lpExt);
            _fstrcpy(filename, lpOpenFileBox->lpExt);
            FillFileListBox(pDlgHeader, IDC_FILE, filename);
        return DEFAULT;
        
        case FOCUSCOMMAND:
            if(wID == IDC_FILE)
            {
                iIndex = GetSelectedItem(pDlgHeader, IDC_FILE);
                GetListBoxItem(pDlgHeader, IDC_FILE, filename, iIndex);
                SetEditBoxText(pDlgHeader, IDC_FILENAME, filename);
                pCtrlData = GetControlData(pDlgHeader, IDC_FILENAME);
                OutFieldEditText(pCtrlData, FALSE);
                return DEFAULT;
            }
        break;                
            
        case COMMAND:
            switch(wID)
            {
                case IDOK:
                    _getdcwd(_getdrive(), filename, _MAX_PATH);
                    _fstrcpy(lpOpenFileBox->lpFileName, filename);
                    GetEditBoxText(pDlgHeader, IDC_FILENAME, filename, 13);
                    if(strchr(filename, '*') != NULL
                        || strchr(filename, '?') != NULL)
                    {
                        pCtrlData = GetControlData(pDlgHeader, IDC_FILE);
                        ReleaseListBoxBuff(pCtrlData);
                        
                        FillFileListBox(pDlgHeader, IDC_FILE, filename);
                        SetFocus(NULL);
                        FillListBox(pCtrlData);
                        return DEFAULT;
                    }
                    else if(!CheckFileName(lpOpenFileBox->fOpen, filename))
                        return DEFAULT;

                    // get path name
                    if(_fstrlen(lpOpenFileBox->lpFileName) > 3)
                        _fstrcat(lpOpenFileBox->lpFileName, "\\");
                    _fstrcat(lpOpenFileBox->lpFileName, filename);
                    
                     // set directory to the default directory.
                    _chdrive(lpOpenFileBox->iInitDrive);
                    _fstrcpy(filename, lpOpenFileBox->lpInitDir);
                    _chdir(filename);
                     return CLOSE;
                
                case IDCANCEL:
                    // set directory to the default directory.
                    *(lpOpenFileBox->lpFileName) = '\0';
                    _chdrive(lpOpenFileBox->iInitDrive);
                    _fstrcpy(filename, lpOpenFileBox->lpInitDir);
                    _chdir(filename);
                return CLOSE;
                
                case IDC_FILENAME:
                    _getdcwd(_getdrive(), filename, _MAX_PATH);
                    _fstrcpy(lpOpenFileBox->lpFileName, filename);
                    GetEditBoxText(pDlgHeader, IDC_FILENAME, filename, 13);
                    if(strchr(filename, '*') != NULL
                        || strchr(filename, '?') != NULL)
                    {
                        pCtrlData = GetControlData(pDlgHeader, IDC_FILE);
                        ReleaseListBoxBuff(pCtrlData);
                        
                        FillFileListBox(pDlgHeader, IDC_FILE, filename);
                        SetFocus(NULL);
                        FillListBox(pCtrlData);
                        return DEFAULT;
                    }
                    else if(!CheckFileName(lpOpenFileBox->fOpen, filename))
                        return DEFAULT;

                    // get path name
                    if(_fstrlen(lpOpenFileBox->lpFileName) > 3)
                        _fstrcat(lpOpenFileBox->lpFileName, "\\");
                    _fstrcat(lpOpenFileBox->lpFileName, filename);
                    
                    // set directory to the default directory.
                    _chdrive(lpOpenFileBox->iInitDrive);
                    _fstrcpy(filename, lpOpenFileBox->lpInitDir);
                    _chdir(filename);
                    return CLOSE;
                    
                case IDC_FILE:
                    if(GetListItemNum(pDlgHeader, IDC_FILE) < 1)
                        return DEFAULT;
                        
                    // get path name
                    _getdcwd(_getdrive(), filename, _MAX_PATH);
                    _fstrcpy(lpOpenFileBox->lpFileName, filename);
                    iIndex = GetSelectedItem(pDlgHeader, IDC_FILE);
                    GetListBoxItem(pDlgHeader, IDC_FILE, filename, iIndex);

                    if(!lpOpenFileBox->fOpen)
                    {
                        if(MessageBox(NULL, "给定的文件已存在,是否替换?", "文件另存为", 
                                MB_YESNO | MB_ICONQUESTION) == IDNO)
                            return DEFAULT;
                    }
                    if(_fstrlen(lpOpenFileBox->lpFileName) > 3)
                        _fstrcat(lpOpenFileBox->lpFileName, "\\");
                    _fstrcat(lpOpenFileBox->lpFileName, filename);

                    // set directory to the default directory.
                    _chdrive(lpOpenFileBox->iInitDrive);
                    _fstrcpy(filename, lpOpenFileBox->lpInitDir);
                    _chdir(filename);
                    return CLOSE;
                break;
                
                default:
                break;
            }
        break;

        case DRAWTEXT:
            if( wID == IDC_DIRECTORY)
            {
                _getdcwd(_getdrive(), filename, _MAX_PATH);
                cc_wt16(filename, ((PCTRLDATA)lParam)->lx, ((PCTRLDATA)lParam)->ty);
                return OWNER;
            }
        return DEFAULT;
        
        default:
        return DEFAULT;
    }
    return DEFAULT;
}

/*
 * Function: BOOL GUIAPI DialogBoxParam( PGUIINFO pGUIInfo, int Index, BOOL (FAR *DlgProc)(),LPSTR lpStr );
 *      This function create dialog box, and manage dialog. This is common
 *   funtion.
 * Parameters:
 *      Index: index of dialog box;
 *      DlgProc: a pointer to the dialog process function;
 *      pStr: the parameter that give the DlgProc function, 
 *            it often is a pointer.
 * Return: 
 *      success----TRUE;
 *      failure----FALSE, maybe cannot create swape file.
 */
BOOL GUIAPI DialogBoxParam( PGUIINFO pGUIInfo, PDLGHEADER pDlgHeader, int (FAR *DlgProc)(PDLGHEADER, UINT, WORD, LONG), LPSTR lpStr)
{   
    MSG Msg;
    _vmhnd_t hdlImage;
    
    SetPtrVis(HIDE);
    SetFocus(NULL);
    if(pGUIInfo)
    {
        do
        {
            if(GetMessageFromQueue(pGUIInfo, &Msg))
            {
                TranslateAccelerator(pGUIInfo, &Msg);
                DisptchMessage(pGUIInfo, &Msg);
            }
            else
                break;
        }while(TRUE);
        
        Msg.uMsg = MSG_KILLFOCUS;
        Msg.wParam = 0;
        Msg.lParam = 0L;
        DisptchMessage(pGUIInfo, &Msg);

⌨️ 快捷键说明

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