我们在程序中对文件打开 操作时,会用到CFileDialog.
当前这个例程介绍如何定制CFileDialog,使之大150个象素点。
效果如下图
上位机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();
}
源代码下载地址:
|