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
:confused:
Printable View
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
:confused:
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;
You can also send the WM_SETTEXT message. First get the textlength by sending the WM_GETTEXTLENGTH message:
But the result is the same.Quote:
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.
Thanks parksie and Vlatko
:D
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) :)
regards,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");
Thanks Chris
:D
Chris,
How would one adapt this for use in VB ?
:rolleyes:VB Code:
txtMyTextBox.Text = "whatever"