Converting textBox1->Text into a basic string.

How would I do this in Visual C++ 9?

Page 1 of 1

4 Replies - 6112 Views - Last Post: 09 June 2009 - 04:22 PM Rate Topic: -----

#1 azjherben   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 89
  • Joined: 25-March 09

Converting textBox1->Text into a basic string.

Post icon  Posted 07 June 2009 - 07:55 AM

Converting textBox1->Text into a basic string.
How would I do this in Visual C++ 9?
Is This A Good Question/Topic? 0
  • +

Replies To: Converting textBox1->Text into a basic string.

#2 AndyH1963   User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 201
  • Joined: 22-June 08

Re: Converting textBox1->Text into a basic string.

Posted 07 June 2009 - 09:10 AM

I'll presume that your text box is on a CDialog and it's control ID is IDC_EDIT1:

TCHAR szBuf[256];
GetDlgItemText(IDC_EDIT1, szBuf, strlen(szBuf));
string sText(szBuf);



Is that what you were after?
Was This Post Helpful? 0
  • +
  • -

#3 prabh   User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 383
  • Joined: 27-December 08

Re: Converting textBox1->Text into a basic string.

Posted 07 June 2009 - 09:15 AM

View PostAndyH1963, on 7 Jun, 2009 - 08:10 AM, said:

I'll presume that your text box is on a CDialog and it's control ID is IDC_EDIT1:

TCHAR szBuf[256];
GetDlgItemText(IDC_EDIT1, szBuf, strlen(szBuf));
string sText(szBuf);



Is that what you were after?

you are right
Dude
Was This Post Helpful? 0
  • +
  • -

#4 azjherben   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 89
  • Joined: 25-March 09

Re: Converting textBox1->Text into a basic string.

Posted 07 June 2009 - 11:55 AM

What is that?
It dosn't even have "textBox1->Text" in it.
Was This Post Helpful? 0
  • +
  • -

#5 jjl   User is offline

  • Engineer
  • member icon

Reputation: 1271
  • View blog
  • Posts: 4,998
  • Joined: 09-June 09

Re: Converting textBox1->Text into a basic string.

Posted 09 June 2009 - 04:22 PM

View Postazjherben, on 7 Jun, 2009 - 10:55 AM, said:

What is that?
It dosn't even have "textBox1->Text" in it.

Thats because you are doing a Forms application which is .NET, there showing you how to do it
in MFC, by the ID which is better. forms is quite lame and even lamer because you need the .NET framework.
But here you Go:
String* myStr = textBox1->text; // to string

int myInt = Convert::toInt32(myStr); // to int






View PostAndyH1963, on 7 Jun, 2009 - 08:10 AM, said:

I'll presume that your text box is on a CDialog and it's control ID is IDC_EDIT1:

TCHAR szBuf[256];
GetDlgItemText(IDC_EDIT1, szBuf, strlen(szBuf));
string sText(szBuf);



Is that what you were after?


Why not make it simple? add a variable myTextBox;

CString str;
myTextBox.GetWindowText(str);


This post has been edited by ImaSexy: 09 June 2009 - 04:22 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1