Click here to Skip to main content
15,885,244 members
Articles / Desktop Programming / MFC

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

Rate me:
Please Sign up or sign in to vote.
4.22/5 (6 votes)
23 Sep 2006CPOL1 min read 37K   1.1K   12   2
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.

C++
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.

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

History

  • 23 Sep 2006: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Pakistan Pakistan
tanvon malik ( real name Tanveer Ahmad )I am a CNC Programmer, cnc setter, cnc operator. want to know about me visit my websites.
CNC Programming
CNC Manuals
DXF & GCode Files with Online Viewers
Komment.me

I been in Switzerland MAG former +FMS+ for CNC training.


Most interesting technologies I like COM MFC DirectShow such as filter development. I am from Pakistan.
Have worked on projects mostly related video capturing, video data processing and real time object tracking on videos. For these I have worked on projects which use "Open CV Library". Which is mostly used for capturing data and its processing.

Comments and Discussions

 
QuestionWhat a great / simple solution Pin
code_junkie26-Sep-06 2:26
code_junkie26-Sep-06 2:26 
What a great / simple solution. You could change everything about the window using this technique Big Grin | :-D Thanks!
AnswerRe: What a great / simple solution Pin
tanvon malik6-Sep-08 21:39
tanvon malik6-Sep-08 21:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.