获得文本框的价值 [英] Getting value of textbox

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

问题描述



我正在创建一个基于文件的应用程序,其中正在使用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.

推荐答案

嘿,如果你这样做的话
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



解决方案1:
我不知道为什么要创建两个对话框以获取文件路径.可以从同一编辑框获取完整的文件路径,也可以创建文件.盒.
解决方案2:
如果您需要像示例中那样使用两个对话框,则可以通过两种方式进行操作.
1.创建目录后,将路径传递到第二个对话框.为此,有很多选项,一种方法是使用您自己的第二个对话框的构造函数.

2.创建第二个对话框后,取文件名(如第一个对话框中的目录).在第一个对话框中使用此值创建文件.
在第一个对话框中
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;


在第二个对话框中,为文件名编辑框创建一个名称为文件名的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.


您需要知道的是Dial1的HWND,在通过调用GetWindow [ FindWindow [
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:
GetDlgItemText(FindWindow(NULL, "Dial1"), IDC_EDIT1, szDial1Text, MAX_PATH);


或:


or:

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


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆