Convert textBox entry to char

This is a Windows Forms Application. Using MS Visual Studio 2008
I would like to know how to convert a textbox entry to a char string.
I have a textbox that requires user input. I want to take the user input and convert it to a char string so that I can check the input for a valid entry. I know how to manipulate the char string to check for validity, I just cant figure out how to convert the textbox entry to the char string. Any help is appreciated.
You need to read about Windows Edit Controls. There's just too much to mention if you don't already know what they are.
http://msdn.microsoft.com/en-us/library/bb775458%28VS.85%29.aspx
I bought the Borland C++ Builder about 8 or 10 years ago but it's becoming outdated and the new version of C++ Builder cost too much so I'm trying to learn the MS Visual Studio C+. I have to admit, the C++ Builder seems to be much easier than the MS C++. To convert a textbox entry to a char string using Borland C++ Builder is very simple;

//Edit1 is the textbox
char NAME1[20];
StrCopy(NAME1,Edit1->Text.c_str());
//Now NAME1 contains the data that was in the textbox.
//I can now manipulate NAME1, check for validity and do what ever I want with it.

MS Visual Studio does not like this and gives you errors.
Using MS Visual Studio, how do you convert a textbox entry to a char string?

Borland C++ was out dated 10 years ago. It's native Windows library, OWL, was far better than MFC. In the end, we've all been forced onto MFC, it's the defacto standard.

However, many controls are build into Windows, so they're available from any language/framework.

You get the text with GetWindowText. This is Windows SDK function.
According to the MS Visual Studio 2008 index, the GetWindowText has nothing to do with a Form textBox.

The MS Visual Studio 2008 index definition for "GetWindowText" is; The GetWindowText function copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowText cannot retrieve the text of a control in another application.

Once again; I have a textBox (on a Form) that requires user input. I want to take the user input and convert it to a char string so that I can check the input for a valid entry. I know how to manipulate the char string to check for validity, I just cant figure out how to convert the Form textBox entry to the char string. Any help is appreciated.
The MS Visual Studio 2008 index definition for "GetWindowText" is; The GetWindowText function copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowText cannot retrieve the text of a control in another application.


You can also validate character by character as they're typed by handing EN_UPDATE/EN_CHANGE callback commands.
Last edited on
Thanks kbw but I'm not understanding this. The "GetWindowText" refers to a "title bar" or a "control". I'm working with a System.Windows.Forms.TextBox class and I dont see the relationship to title bars, controls and "GetWindowText".

If a have a windows form with several textBoxes and buttons and check boxes. I want to be able to retrieve the textBox entries, convert them to a char string in order to check for valid entries. I can manipulate a char string and do the validation part but I just cant figure out how to convert the textBox entry to a char string. As I said in a previous response, the Borland C++ Builder made it very easy;

//textBox1 is one of the textBoxes on the Form.
char NAME1[20];
StrCopy(NAME1,textBox1->Text.c_str());

but the MS Visual Studio C++ will not compile this.
I'm working with a System.Windows.Forms.TextBox class


So you're working with C++/CLI (.net) and not C++ and WinAPI/MFC as kbw was thinking. The two are actually different languages.

I would be very surprised if there isn't a TextBox.GetString() function or something of that sort. Look up the TextBox class in your reference material (ie: MSDN) and see what functions it offers.
Last edited on
Last edited on
Albatross, I can see nothing in any of those links that you list that give any indication on how to convert a textBox entry to a char string. I have spent hours looking thru the textBox methods, members, properties and controls and can not find anything that works.

Disch, the TextBox.GetString() is not a valid method for a Form textBox. If there is a method, I cant find it.
Eh... yeah, I sorta forgot that there was that bit about how to translate what's on the clipboard into a char string. Indeed, this isn't a simple problem.

That said, I wonder how one would actually do it. I'm not very familiar with the WinAPI, but there has to be a way that bypasses the clipboard as well. I'll leave this to someone who knows the API better than I do.

-Albatross
Topic archived. No new replies allowed.