65.9K
CodeProject is changing. Read more.
Home

Showing Our Template Not Below but Side by Side the CFileDialog Controls

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.22/5 (6 votes)

Sep 24, 2006

CPOL

1 min read

viewsIcon

37456

downloadIcon

1142

Why our template is added at the bottom; here is the way we can add our control side by side other CFileDialog controls

Sample Image - CFileDialogX.jpg

Introduction

Everyone who understands VC++ tries at one time to customize the File Open Dialog according to his needs. You can see that there are several such customized dialog boxes on CodeProject too. But I tried to do what nobody has done yet. In this article, I also tried to prove myself.

Why a New Customized CFileOpenDialog

Whenever we try to add a template to this file open dialog, it adds our template at the bottom of the real dialog giving us a second citizen feeling, a bit if not much. Why not prove us as first degree citizens. But how? Here I am going to customize this file open dialog. But I am adding my work side by side the real dialog. This means that now my added control will not show at the bottom, but it will show next to the listview control of the real file open dialog.

How Is This Done?

I derived a new class from CFileDialog. In this derived class, I handle the OnInitDialog() virtual method. This function is called whenever the entire dialog is completed in memory but not yet shown on the screen. So this is the best time to customize this dialog according to my needs. So I add my new control here.

BOOL CFileDialogX::OnInitDialog()
{
CFileDialog::OnInitDialog();
CRect rect;
CWnd * parent = GetParent();
parent->GetWindowRect(&rect);
parent->SetWindowPos(0,rect.left,rect.top,rect.Width()+200,rect.Height(),0);
ScreenToClient(rect);
CRect staticWinRect(rect.Width(),rect.top+65,rect.Width()+200-20,rect.Height()-100);
CFont * pfont = parent->GetFont();
mStaticPreview.Create("VC++ shows its 
mystries",WS_CHILD|WS_VISIBLE|WS_BORDER,staticWinRect,parent);
mStaticPreview.SetFont(pfont,false);
return TRUE; 
}

And in OnFileNameChange() notification, I update some stuff about the selected file or folder. But anything can be added there.

Using the Code

It is an easy class CFileDialogX. You just create an object of it and show the dialog normally as you do CFileDialog.

CFileDialogX mFileOpenDialog(true);
mFileOpenDialog.DoModal(); 

History

  • 23 Sep 2006: Initial version