|
-
Jul 22nd, 2001, 05:01 AM
#1
Thread Starter
Member
Reading from and write to a text box
O.S: Win98
Compiler: Dev-C++ version 4
Level: keen newbie
Hello,
I've created a text box (thanks to Vlatko and Steve) using CreateWindowEx function. I now need to know how you read from and write to the control.
Thanks
-
Jul 22nd, 2001, 05:45 AM
#2
Monday Morning Lunatic
Code:
SetWindowText(hEditCtl, "Text here!");
Code:
char *pcBuf;
int iLen = GetWindowTextLength(hEditCtl);
pcBuf = new char[iLen + 2];
GetWindowText(hEditCtl, pcBuf, iLen + 1);
// use pcBuf, then delete it
delete[] pcBuf;
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
-
Jul 22nd, 2001, 06:13 AM
#3
Frenzied Member
You can also send the WM_SETTEXT message. First get the textlength by sending the WM_GETTEXTLENGTH message:
WM_SETTEXT
An application sends a WM_SETTEXT message to set the text of a window.
WM_SETTEXT
wParam = 0; // not used; must be zero
lParam = (LPARAM)(LPCTSTR)lpsz; // address of window-text string
Parameters
lpsz
Value of lParam. Pointer to a null-terminated string that is the window text.
Return Values
The return value is TRUE if the text is set. It is FALSE (for an edit control), LB_ERRSPACE (for a list box), or CB_ERRSPACE (for a combo box) if insufficient space is available to set the text in the edit control. It is CB_ERR if this message is sent to a combo box without an edit control.
But the result is the same.
-
Jul 22nd, 2001, 10:33 AM
#4
Thread Starter
Member
One step closer..
Thanks parksie and Vlatko
-
Jul 22nd, 2001, 09:24 PM
#5
PowerPoster
If you're dealling with Dialog, you can use the SendDlgItemMessage or SetDlgItemText Api function call, so, all you need to know is the control ID and not the handle (HWND) 
PHP Code:
// Read the string from IDC_EDIT control
int sz=0;
char *str;
sz = SendDlgItemMessage(hDlg, IDC_EDIT1, WM_GETTEXTLENGTH, 0, 0);
sz = sz+1;
str = new char[sz];
memset(str, 0, sz);
SendDlgItemMessage(hDlg, IDC_EDIT1, WM_GETTEXT, sz, (LPARAM)str);
MessageBox(hDlg, str, NULL, MB_OK);
delete [] str;
// Write a new string into IDC_EDIT control
SetDlgItemText(hDlg, IDC_EDIT1, "TESTING");
regards,
-
Jul 23rd, 2001, 02:06 PM
#6
Thread Starter
Member
Thanks Chris
-
Sep 6th, 2001, 11:39 AM
#7
Junior Member
Chris,
How would one adapt this for use in VB ?
-
Sep 6th, 2001, 11:48 AM
#8
Monday Morning Lunatic
VB Code:
txtMyTextBox.Text = "whatever"
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
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
|