CFileDialog

Hi..All,
      i want to create one gui in vc++..
in my dialog window i want to add FileDialog how to do this....pls.help me out...

Thanks and regards
Thaz
thazimAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GloriousRainCommented:
Example for CFileDialog

void CTestApp::OnDoFileDialog()
{
     CString OpenFilter;
          OpenFilter = "Text File (*.txt)|*.txt|";
          OpenFilter += "HTML File (*.htm;*.html)|*.htm;*.html|";
          OpenFilter += "All Files (*.*)|*.*||";

     CFileDialog FileOpenDialog(
          TRUE,
          NULL,
          NULL,
          OFN_FILEMUSTEXIST |     OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
          OpenFilter,                         // filter
          AfxGetMainWnd());                         // the parent window


        FileOpenDialog.DoModal();
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jacobkristensenCommented:
You can put a button on your dialog by dragging it from the resource toolbar onto the dialog.
Then give it a name and an appropriate ID.
Next, double click the button and a box will appear. Here you can enter the name of the function handling a click on the button. (one will be suggested)
After clicking OK, you will see a code snippet looking like:

void CMyDlg::OnButton1()
{
  // TODO: Add your control notification handler code here

}

here you can add the code to display a open-file-dialog:
CFileDialog dlg(true);

If you want to make the dialog a bit more specific to your needs you can do something like this

char szFilter[] = "Text files(*.txt)|*.txt|All Files (*.*)|*.*||";
CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY, szFilter);

The first parameter (true) tells the CFileDialog that is should be a open-file-dialog if you put 'false' instead, it will be a save-file-dialog.
the szFilter variable defines which files you want to be visible in the dialog.


The description from MSDN is this:

CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );

Parameters

bOpenFileDialog

Set to TRUE to construct a File Open dialog box or FALSE to construct a File Save As dialog box.

lpszDefExt

The default filename extension. If the user does not include an extension in the Filename edit box, the extension specified by lpszDefExt is automatically appended to the filename. If this parameter is NULL, no file extension is appended.

lpszFileName

The initial filename that appears in the filename edit box. If NULL, no filename initially appears.

dwFlags

A combination of one or more flags that allow you to customize the dialog box. For a description of these flags, see theOPENFILENAME structure in the Win32 SDK documentation. If you modify the m_ofn.Flags structure member, use a bitwise-OR operator in your changes to keep the default behavior intact.

lpszFilter

A series of string pairs that specify filters you can apply to the file. If you specify file filters, only selected files will appear in the Files list box. See the Remarks section for more information on how to work with file filters.

pParentWnd

A pointer to the file dialog-box object?s parent or owner window.

0
thazimAuthor Commented:
yep...the code works ...but...the thing is..
i want to add FileDialog...like button to my dialog....
where to write this code so that...on init itself i want to display Filedialog....without any button clik....


0
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

jacobkristensenCommented:
in your dialogs OnInitDialog handler...
0
thazimAuthor Commented:
my project workspace is dialog based...
i wanna to add CFiledialog in my dialog without doing onButtonClick ....and other stuff....
if i write above mentioned code in OnInitDialog()..
this first opens the CFiledialog...then if i click cancel then..my mine dialog is opening....so..
pls tell me where to put this Cfiledialog code exactly..
 thanks
thaz
0
GloriousRainCommented:
Hi,
When do you want to display CFileDialog?
0
thazimAuthor Commented:
if i run my application the first thing i want to display is one Big Dialog with this FileDialog on both left and right side of the main[big] dialog...
0
DanRollinsCommented:
You want two CFileDialog boxes oepn at once? That is very odd, so I'll assume that I misunderstood you.

To open a single CFileDialog automatically, add the code that has been described above, but add this code to OnInitDialog():

PostMessage( WM_COMMAND, IDC_BUTTON1, 0 );

where IDC_BUTTON1 is the ID of the button that opens the CFileDialog.  This effectively 'clicks the button' for you.  If you don't want that button to be seen, you can use the dialog editor to turn off the "visible" attribute.

-- Dan
0
GloriousRainCommented:
In InitInstance() of CYourApp class,
before the code of calling main dialog, open CFileDialog there.
Ex:

CYourApp::InitInstance()
{
// Open CFileDialog
    CString OpenFilter;
         OpenFilter = "Text File (*.txt)|*.txt|";
         OpenFilter += "HTML File (*.htm;*.html)|*.htm;*.html|";
         OpenFilter += "All Files (*.*)|*.*||";

    CFileDialog FileOpenDialog(
         TRUE,
         NULL,
         NULL,
         OFN_FILEMUSTEXIST |     OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
         OpenFilter,                         // filter
         AfxGetMainWnd());                         // the parent window


       FileOpenDialog.DoModal();
...
...
// Open MainDialog
CMainDlg dlg;
     m_pMainWnd = &dlg;
     int nResponse = dlg.DoModal();
     if (nResponse == IDOK)
     {
          // TODO: Place code here to handle when the dialog is
          //  dismissed with OK
     }
     else if (nResponse == IDCANCEL)
     {
          // TODO: Place code here to handle when the dialog is
          //  dismissed with Cancel
     }
...
}
0
thazimAuthor Commented:

one more change in that....
in that CFiledialog..i want to remove...
FileName ...that textbox..and open button and cancel button also...
how do i remove those buttons from FileDialog..
pls....:-(
Taz
0
thazimAuthor Commented:
i tried this long back...but..this also first calls Cfiledialog then...on cancel mode it will call main dialog...but...this is not my question...
0
thazimAuthor Commented:
Hi..DanRollins ,
   U r correct...but..the this code displays FileDialog..in center...i want to put that into left and right of the main dialog...moreever my main dialog should be active first...
 
  This is mainly to show File transfer between one machine to another....so i have to add more buttons..and lot of work is there to Do....

 one filedialog is local ...and another filedialog is remote machine....
how do i fetch the remote m/c dir and files???


0
GloriousRainCommented:
So you needn't open CMainDialog after open CFileDialog
CYourApp::InitInstance()
{
// Open CFileDialog
   CString OpenFilter;
        OpenFilter = "Text File (*.txt)|*.txt|";
        OpenFilter += "HTML File (*.htm;*.html)|*.htm;*.html|";
        OpenFilter += "All Files (*.*)|*.*||";

   CFileDialog FileOpenDialog(
        TRUE,
        NULL,
        NULL,
        OFN_FILEMUSTEXIST |     OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
        OpenFilter,                         // filter
        AfxGetMainWnd());                         // the parent window


      FileOpenDialog.DoModal
...
}

May have i missunderstood?
0
thazimAuthor Commented:
Now....the main dialog gets activates only if i close the filedialog...this sholud'nt be the case...

1. in my main dialog
  i have....a] Inquiry
            b] Connect
            c] Disconect
            d] two file transfer buttons...
one is from client to server
another is from server to client....

these are the buttons in my main dialog and with two file dilogs....
 so....now what happens..always...Filedialog takes the action...what to do??
0
GloriousRainCommented:
Now i see :)
0
thazimAuthor Commented:
What happend ???
0
thazimAuthor Commented:
is that possible or not....??
actully this one is i finished in JAVA...but..
i want this thing in VC++....

tell me ....i have to use propertysheet or what????
i'm not expereince in vc++...
Help me out.
thanks :-))
0
DanRollinsCommented:
thazim,
You have now asked seven questions, by my count, and you are offering only 50 points.  In the USA, we have a dogma called "Capitalism" and it, ALAS!,  prevents me from continuing here.  Sorry.

Also, it does not make sense to display two CFileDialog boxes, under any circumstances.

-- Dan
0
thazimAuthor Commented:
hey....i can offer u 200 also...its not the problem...
there should be way to display two filedialog....
coz...we can set the postion for each dialog na....???
i don't know really...

okay...if u wish mail me regarding this...
i don't know how much i can give...so sorry that i gave only 50 points....

0
migelCommented:
Hi!
IMHO you need to write manually dialog with two filelists it is not so difficult - you can see it at www.codeguru.com in the tree view control section
0
Roshan DavisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: DanRollins, jacobkristensen, GloriousRain (points to be split)

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.