QQ登录

只需一步,快速开始

上位机MFC文件对话框实现

[ 复制链接 ]
我们在程序中对文件打开 操作时,会用到CFileDialog.
当前这个例程介绍如何定制CFileDialog,使之大150个象素点。
效果如下图

上位机MFC文件对话框实现

上位机MFC文件对话框实现

运行附件内的例程,在界面上点击工具栏的打开文件图标会弹出文件对话框。
此对话框的效果就是当前例程定制的。

例程比较简单,主要代码段为
BOOL CMyFileDialog::OnInitDialog() // Override
{
    // This variable should be changed acording to your wishes
    // about the size of the finished dialog
    const UINT iExtraSize = 150;
    // Number of controls in the File Dialog
    const UINT nControls = 7;   

    // Get a pointer to the original dialog box.
    CWnd *wndDlg = GetParent();

    RECT Rect;
    wndDlg->GetWindowRect(&Rect);
    // Change the size
    wndDlg->SetWindowPos(NULL, 0, 0,
                        Rect.right - Rect.left,
                        Rect.bottom - Rect.top + iExtraSize,
                        SWP_NOMOVE);

    // Control ID's - defined in <dlgs.h>
    UINT Controls[nControls] = {stc3, stc2, // The two label controls
                                edt1, cmb1, // The eidt control and the drop-down box
                                IDOK, IDCANCEL,
                                lst1}; // The Explorer window

    // Go through each of the controls in the dialog box, and move them to a new position
    for (int i=0 ; i<nControls ; i++)
    {
        CWnd *wndCtrl = wndDlg->GetDlgItem(Controls);
        wndCtrl->GetWindowRect(&Rect);
        wndDlg->ScreenToClient(&Rect); // Remember it is child controls

        // Move all the controls according to the new size of the dialog.
        if (Controls != lst1)
            wndCtrl->SetWindowPos(NULL,
                            Rect.left, Rect.top + iExtraSize,
                            0, 0, SWP_NOSIZE);
        else // This is the explorer like window. It should be sized - not moved.
            wndCtrl->SetWindowPos(NULL, 0, 0,
                                Rect.right - Rect.left,
                                Rect.bottom - Rect.top + iExtraSize,
                                SWP_NOMOVE);
    }

    // Remember to call the baseclass.
    return CFileDialog::OnInitDialog();
}


源代码下载地址:
请点击此处下载

请先注册会员后在进行下载

已注册会员,请先登录后下载

文件名称:CUSTOM_DIALOG.rar 
文件大小:38.82 KB  售价:1金币
下载权限: 不限 以上或 VIP会员   [购买捐助会员]   [充值积分]   有问题联系我


回复

使用道具 举报

点击查看
快速回复 返回列表 客服中心 搜索