[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

CFileDialog

Posted on 2001-07-03
21
Medium Priority
?
674 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:thazim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 5
  • 2
  • +3
21 Comments
 
LVL 2

Accepted Solution

by:
GloriousRain earned 400 total points
ID: 6251498
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
 
LVL 1

Assisted Solution

by:jacobkristensen
jacobkristensen earned 400 total points
ID: 6251507
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
 

Author Comment

by:thazim
ID: 6251714
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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 1

Expert Comment

by:jacobkristensen
ID: 6251726
in your dialogs OnInitDialog handler...
0
 

Author Comment

by:thazim
ID: 6251780
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
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6251797
Hi,
When do you want to display CFileDialog?
0
 

Author Comment

by:thazim
ID: 6251823
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 6251859
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
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6251860
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
 

Author Comment

by:thazim
ID: 6251865

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
 

Author Comment

by:thazim
ID: 6251877
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
 

Author Comment

by:thazim
ID: 6251905
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
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6251918
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
 

Author Comment

by:thazim
ID: 6251951
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
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6251957
Now i see :)
0
 

Author Comment

by:thazim
ID: 6251965
What happend ???
0
 

Author Comment

by:thazim
ID: 6252026
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 6252133
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
 

Author Comment

by:thazim
ID: 6252270
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
 
LVL 12

Expert Comment

by:migel
ID: 6253489
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
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9490241
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question