|
-
Jun 25th, 2001, 02:10 PM
#1
Thread Starter
Frenzied Member
Textfield...
Let's say I have a textfield, a command button and a string.
How would I transfer the value of the textfield to the string when the button is pressed????
-
Jun 25th, 2001, 03:02 PM
#2
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 25th, 2001, 04:42 PM
#3
Frenzied Member
Code:
long fl =SendMessage(edithwnd,WM_GETTEXTLENGTH,0,0);
TCHAR *ft = new TCHAR[++fl];
SendMessage(edithwnd,WM_GETTEXT,fl,(LPARAM)ft);
/*ft contains text*/
-
Jun 25th, 2001, 04:43 PM
#4
Frenzied Member
If you are using a dialogue then you can use the GetDlgItemText function.
Also you can use the string class (much easier to manipulate with the string).
-
Jun 25th, 2001, 04:47 PM
#5
Assuming you have the handle:
Code:
LPSTR sText;
DWORD dwLength = GetWindowTextLength(handle);
sText = (char*)GlobalAlloc(GPTR, dwLength + 1);
GetWindowText(handle, sText, dwLength + 1);
-
Jun 25th, 2001, 05:06 PM
#6
Monday Morning Lunatic
Megatron - your code isn't macro-safe You need to use TCHAR. Incidentally, why use GlobalAlloc when new[] gives you type-safety?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 26th, 2001, 07:05 AM
#7
Thread Starter
Frenzied Member
Hi guys!
It's a dialog...
I tried out the following code, but windows closed my program......did I do that.....
Code:
LPSTR strText;
GetDlgItemText(hDlg,Text1, strText, 40);
MessageBox(NULL, strText, "Test", MB_OK);
-
Jun 26th, 2001, 07:14 AM
#8
Monday Morning Lunatic
It closed because you didn't allocate a buffer. You need to use TCHAR* and GetTextLength, as posted above. Then, just use:
Code:
basic_string<TCHAR> sText = pcBuf; // or whatever it's called
delete[] pcBuf;
I normally typedef basic_string<TCHAR> to tstring to make life easier.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 27th, 2001, 08:09 AM
#9
Thread Starter
Frenzied Member
I don't quite get it, parksie.....could you please put together a small example....
-
Jun 27th, 2001, 11:21 AM
#10
Monday Morning Lunatic
Catch the button's notification message (see the PSDK for details, look under BN_CLICK ). Then use Vlatko's code, posted above.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 27th, 2001, 06:44 PM
#11
Here's a DialogProc from a working program. replace IDC_TEXTBOXNAME and IDC_BUTTONNAME with the names of the textbox and the button.
Code:
BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM)
{
HWND edithwnd;
TCHAR *ft;
switch(uMsg) {
case WM_CLOSE:
EndDialog(hDlg, 0);
break;
case WM_INITDIALOG:
SetDlgItemText(hDlg, IDC_TEXTBOXNAME, "Text Goes Here");
break;
case WM_COMMAND:
if(wParam == MAKEWPARAM(IDC_BUTTONNAME, BN_CLICKED))
{
edithwnd = GetDlgItem(hDlg, IDC_TEXTBOXNAME);
long fl =SendMessage(edithwnd,WM_GETTEXTLENGTH,0,0);
ft = new TCHAR[++fl];
SendMessage(edithwnd,WM_GETTEXT,fl,(LPARAM)ft);
MessageBox(hDlg, ft, "Textbox Says...", MB_OK);
}
break;
default:
return FALSE;
}
return TRUE;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|