huklin

Hi,

I have created a textbox, but I'm not sure how to update the text inside the box.
Furthermore, the text I put inside the box does not support new lines \n, so how can i display text which has \n

Below is the code I used to create the text box. Thanks a lot for your help.

---------------------------------------------------

CreateWindowEx(

0,
"EDIT","Sample Text",WS_VISIBLE | WS_CHILD |
WS_VSCROLL ,
10,50,170,50,myDialog,(HMENU)textbox_id,NULL,NULL
);




Re: UI Development for Windows Vista updating created textbox with new text

Paul Marriott

You use SetWindowText or SetDlgItemText to fill in the contents of the edit box.

A multiline edit box is specified with ES_MULTILINE in window style CreateWindowEx call (WS_VISIBLE|WS_CHILD|ES_MULTILINE)





Re: UI Development for Windows Vista updating created textbox with new text

mike60622

How did you solve this I'm trying to update an existing edit box with an integer and its turning into a nightmare.





Re: UI Development for Windows Vista updating created textbox with new text

Paul Marriott

In win32 api, you would use SetDlgItemInt to write the value of an integer to an edit control

ID=dld id in dialog box resource.

ivalue=integer value.

SetDlgItemInt(hDlg,ID,ivalue,0);

See

http://msdn2.microsoft.com/en-us/library/ms645518.aspx

If you are writing in c++ or classes etc, this would be different.





Re: UI Development for Windows Vista updating created textbox with new text

huklin

Thanks a lot, this is exactly what I was looking for.

However, one thing I still cannot do is the multi-line feature - here is how i created the window:

HWND testBox = CreateWindowEx(

0,

"EDIT","1st line \n 2nd line \n",WS_VISIBLE | WS_CHILD |ES_MULTILINE,

10,50,170,50,myDialog,(HMENU)textbox_id,NULL,NULL

);

Is there a reason why the \n doesn't display as a new line

Finally, is there a way to append onto the previous text of the box instead of overwriting it

Thanks a lot!




Re: UI Development for Windows Vista updating created textbox with new text

Paul Marriott

The line break character is "\r\n", thus to see

Line 1

Line 2

Line 3

You would write "Line 1\r\nLine 2\r\nLine 3"

Appending can't be done directly using a single function call, rather you have to use EM_SETSEL message to set the insertion point at the end of the edit control and then use EM_REPLACESEL to add the new text to the existing contents of the control, OR else you could use a memory block to keep a copy of the current text, addto the end of it when required and then replace the whole memory block again to the control using SetDlgItemText.