本文介绍了获得文本框的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在创建一个基于文件的应用程序,其中正在使用2个对话框Dial1和Dial2.
在Dial1上,我有1个文本框输入目录路径,并有1个按钮"Create Dir"(不是默认的Ok()按钮).
用户将输入目录路径并单击按钮,将创建目录,并且还将显示其他对话框Dial2.现在在Dial2上,再次有1个文本框输入文件名,并有1个按钮创建文件.在Dial2的按钮单击上,我想在目录中创建文件,该目录已在Dial1的文本框中输入.
直到创建目录并显示新对话框,一切都很好.但是当我输入文件名并单击按钮时,并没有获得Dial1的文本框的值.正在创建文件,但不在输入的目录路径中.简而言之,我想在Dial2中访问Dial1文本框的值.
我不知道应该采用哪种方法提取文本框值,以便也可以在另一个对话框中使用它.
请给我解决方法.

谢谢.

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.

推荐答案

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


filedialog.DoModal();
CString name=filedialog.filename;


在第二个对话框中,为文件名编辑框创建一个名称为文件名的DDX_Text变量.单击按钮时,使用处理程序
onok();
现在您可以在第一个对话框中创建一个文件路径,以便整个创建过程进入第一个对话框.我建议您尝试使用此路径.
我认为最好不要使用全局变量,因为您还有其他解决方案.


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.


GetDlgItemText(FindWindow(NULL, "Dial1"), IDC_EDIT1, szDial1Text, MAX_PATH);


或:


or:

GetDlgItemText(GetWindow(hwnd, GW_HWNDNEXT), IDC_EDIT1, szDial1Text, MAX_PATH);


这篇关于获得文本框的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 10:12