Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 12th, 2005, 10:11 PM   #1
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 4 groovicus is on a distinguished road
Reading from a textarea

In java, when one wants to read text from a text area, they do something like
string[] s = textArea.getText();

I am assuming that C++ has something similar, but I sure can't find it in any of the APIs. Can someone point me in the proper direction please?
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Old Dec 13th, 2005, 3:00 AM   #2
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4 ivan is on a distinguished road
There are some ways to do it:

UINT GetDlgItemText(

    HWND hDlg,	        // handle of dialog box
    int nIDDlgItem,	 // identifier of control
    LPTSTR lpString,	// address of buffer for text
    int nMaxCount 	// maximum size of string
   );

int GetWindowText(

    HWND hWnd,	       // handle of window or control with text
    LPTSTR lpString,	// address of buffer for text
    int nMaxCount 	// maximum number of characters to copy
 
      );

LRESULT SendMessage(

    HWND hWnd,	                    // handle of destination window
    WM_GETTEXT,	                   // message to send
    (WPARAM) cchTextMax,	// number of characters to copy
   (LPARAM) lpszText 	            // address of buffer for text 
   );

Hope that helps.

EDIT: sorry for the tab-spaces, they got corrupted when I pasted the text
ivan is offline   Reply With Quote
Old Dec 13th, 2005, 5:57 AM   #3
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,031
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by groovicus
In java, when one wants to read text from a text area, they do something like
string[] s = textArea.getText();

I am assuming that C++ has something similar, but I sure can't find it in any of the APIs. Can someone point me in the proper direction please?
If you're using some framework like .NET or MFC, there will be easy-to-use methods to get the text of pretty much any control that can have text assigned to it, including text boxes (ie edit controls), buttons, labels, etc.

If you're using the raw Win32 API, you need to realize that all the controls like buttons, scrollbars, etc are just windows. When you create one of these predefined controls, you're creating a window of the appropriate 'window class'. A window class, not to be confused with C++ classes, is a sort of 'template' from which you can create instances. Each class has its own class name (a string), and has been pre-registered by Windows for you, which explains why you don't need to write a WinProc to catch the messages aimed at the control. In fact, the WinProc for most (all?) of these controls will handle events like clicking, and translate those into WM_COMMAND messages fired back at the parent window.

Anyways, the upshot of all this is that since controls are just windows, you can use SetWindowText() and GetWindowText() to manipulate the text. On regular windows, it's the caption in the title bar, on buttons, labels (static controls in raw API terminology), etc, it's the text on the control, and for some, like scrollbars, it will be ignored. Remember, these functions will just send WM_SETTEXT or WM_GETTEXT to the target window.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Dec 13th, 2005, 8:38 AM   #4
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 4 groovicus is on a distinguished road
I am using the .net framework... I'm pretty sure that once I have time to understand everything that the IDE is throwing at me, I'll be able to figure it out.

Thanks for the input.
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Old Dec 14th, 2005, 6:57 AM   #5
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,031
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by groovicus
I am using the .net framework... I'm pretty sure that once I have time to understand everything that the IDE is throwing at me, I'll be able to figure it out.

Thanks for the input.
What I say below about using properties might not work in C++. I know it won't work in normal C++, but I believe you can enable managed extensions that let VC++ use properties. It should be in your compiler switches somewhere, or perhaps it's automatically set (likely if you created a .NET application/project).

Properties are essentially a hybrid between methods and attributes. They are like attributes in that you just access them like object.property or objectPtr->property (note the lack of parentheses), but they are like methods in that the return value is determined by code (giving you encapsulation). They are kinda neat, but by no means essential; the only real benefit is they can help the code look cleaner. The downside is that you can't tell from a line of code whether something is accessing a property, or a public data member.

That said, try the 'Text' property of the relevant control. Basic ones like buttons, textboxes, and labels all have it. For some of the more complex controls, like comboboxes and stuff, they either don't have it, or have it plus other properties/methods to get the additional bits of text. Usually the text is a String, but sometimes you need to convert it (like if it's an item in a listbox).
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Dec 14th, 2005, 9:45 AM   #6
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 4 groovicus is on a distinguished road
I have been using the pre-defined templates, and you are describing pretty much what I am seeing, only it is a horrible jumble of files... when I double click on a button in the IDE, it takes me to the prototype in the header file of the form. There is also a .cpp for the form, which I always thought the relevant code went, but the way it is presented, it appears that it wants you to put the execution code in the header ??.. anyway, it's a mess.

I think at this point I would be better off rolling my own code so at least I can understand what the heck is going on. But I will look to the Text properties and see what I can come up with.
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Old Dec 15th, 2005, 1:45 AM   #7
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,031
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by groovicus
I have been using the pre-defined templates, and you are describing pretty much what I am seeing, only it is a horrible jumble of files... when I double click on a button in the IDE, it takes me to the prototype in the header file of the form. There is also a .cpp for the form, which I always thought the relevant code went, but the way it is presented, it appears that it wants you to put the execution code in the header ??.. anyway, it's a mess.

I think at this point I would be better off rolling my own code so at least I can understand what the heck is going on. But I will look to the Text properties and see what I can come up with.
Yeah, I don't really have any experience using the .NET framework from C++. I believe the limits of my experience were in creating a .NET C++ 'windows forms application', and seeing how it insisted on code in headers, at which point I went 'ugh' and stopped.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:47 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC