Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am creating a file based application where am using 2 dialog box, dial1 & dial2.
On dial1, I have 1 textbox to enter directory path, & 1 button "Create Dir" (It's not default Ok() button).
User will enter directory path & click on button, it will create directory, & will also display other dialog- dial2. Now on dial2, there is again 1 textbox to enter file name & 1 button to create file. On button click of dial2, I want to create file in the directory, which has been entered in textbox of dial1.
Upto creating directory & displaying of new dialog, all is fine. But when I enter file name & click on button, am not getting the value of dial1's textbox. File is being created but not in entered directory path. In short I want to access value of dial1's textbox, in dial2.
I don't know in which method I should extract textbox value, so that I can use it in another dialog also.
Please give me the solution.

Thanks.
Posted
Updated 16-Apr-11 1:17am
v3

Hey if you doing like this then
CString Directory ;//Global string
Cstring File ;
OnButtonDirectory()
{
  CDirectoryDialog m;
  if(m.DoModel()==ID_OK)
   {
     Directory =m.m_DirectoryText;  ///Directory text value m_DirectoryText
   }
}
OnButtonFileName()
{
  CFileSelection file;
  if(file.DoModel()==ID_OK)
  {
    File =file.m_leText;  ///File text value m_FileText
  }
}
OnFileCreate()
{
  CFile File;
  if(!CreateDirectory(Directory))
   {
     AfxMesageBox("Cannot create Directory";
   }
   SetCurrentDirectory(Directory);
   if(!ile.Open( File+".txt"))
   {
     AfxMessageBox("Can't create File");
   }
}

Try this,and reply
 
Share this answer
 
Comments
virus131 16-Apr-11 2:34am    
Am very much thankful for your answer, but am not using OK() button & I just want to know- How do I get value (path) of 1 dialog's textbox in other dialog. I know one way to do this is to set global object of dialog class but I don't know how to set global object for dialog class so that i can access same object from other dialog class. I really need help for this as am fresher & new to vc++.
[no name] 16-Apr-11 7:15am    
Hey Shweta right,Look this style of coding


#include "FileDialog.h" ///Include your file dailog

CDirectoryDialog::OnDirectoryBnClick()

{

CFileDialog myDialog;

CString fileName;

fileName=myDialog.filename; //Filename is member of your file dialog

}




Hi,
solution1:
i do not know why you want to create two dialog boxes for getting file path.you can get full file path from same edit box and you can create the file.still if you want to separate file and directory, use same dialog having two edit boxes.
Solution 2:
if it is your requirement to use two dialog boxes as in your example,then you can do it in two ways.
1.after creating your directory pass the path to your second dialog.for this there are lot of options,one way is using your own constructor of second dialog.
Or
2.after creating second dialog you take the file name(like the directory from first dialog).use this value in first dialog to create the file.here goes the idea,

in first dialog
filedialog.DoModal();
CString name=filedialog.filename;

in second dialog create a DDX_Text variable with name filename for file name edit box.on button click handler use
onok();
now you can create a file path in first dialog,so that the whole creation part goes to first dialog.i suggest you try this one.
I think its better not use global variables he you have another solutions.
 
Share this answer
 
Comments
virus131 16-Apr-11 5:22am    
Thanks a lot.... but am not getting you. How can I pass it using constructor of second dialog?
solution2:
Let your directory dialog is DirectoryDiag, and File dialog is FileDialog.
1st Idea:
Create a Constrcutor for FileDialog like this
CFileDialg::CFileDialog(CString& DirectoryPath)
{
//Save the DirectorPath in FileDialog Member variable.
}
In Directory Dilaog call fileDialog as
<pre>
void buttonClick_DirectoryDiag
{
//Your code for directory creation;
//After open the file dilaog
FileDialog fileDialog(Directorypath);
fileDialog.DoModal();
CString FilePath = FileDialog.FilePath;
}
2nd Idea:
user clicks on the button of DirectoryDiag after providing the directory path.So on button handler you probably do the following
<pre>
void buttonClick_DirectoryDiag
{
//Your code for directory creation;
//After open the file dilaog
FileDialog fileDialog;
fileDialog.DoModal();
CString FilePath = fileDialog.FilePath;
}
</pre>
Now in the File dialog you have a edit box for file path.so crate a DDX_Text(I think you know this) for that edit box and let the varaiabl name is FilePath.User Clicks on the button of FileDialog after providing the path.So in the button handler,
<pre>
void buttonClick_FileDialog
{
OnOk();//Updates All the controls data
}
</pre>
What you need to know is the HWND of dial1, after you get this either by calling GetWindow[^] (if you know the Z-order) or FindWindow[^] (if you know dialog's (that's dial1) title), just call GetDlgItemText to get the text from textbox.

Like this:
MIDL
GetDlgItemText(FindWindow(NULL, "Dial1"), IDC_EDIT1, szDial1Text, MAX_PATH);

or:
MIDL
GetDlgItemText(GetWindow(hwnd, GW_HWNDNEXT), IDC_EDIT1, szDial1Text, MAX_PATH);
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900