How would I make my program make text appear in a read-only edit box?
Printable View
How would I make my program make text appear in a read-only edit box?
SetDlgItemText() will do that.
Thanx. Now, how would I put it in the next line? Like in a chatroom.
Uses something similiar to:
m_strString = "This is the First line \n\r This is the second";
// or it may be just a "\n", i forget which;
SetDlgItemText(IDC_EDIT1, m_strString);
Thanks again. Now, how would I make it write it in the edit box, then later, write in something else on the next line. Like a chatroom.
Hi,
Well in theory you would put your first line of text in, then get it into a varible then append that varible then display it in the control.
Now heres some code, im used to using SetWindowText() it works but you can use SetDlgItemText() if you want...
Code:char szNewBuffer[100];
//make the first line you want to display
char szBuffer[100] = "This Is The First Line\r\n";
//now display it
SetWindowText(hWndMyEdit, szBuffer);
//now later in ur prog get the current text
GetWindowText(hWndMyEdit, szNewBuffer, 100);
//Now Append szNewBuffer onto the end of the first buffer
//then display it
strcat(szBuffer, szNewBuffer);
SetWindowText(hWndMyEdit, szBuffer);
Thats just off the top of my head, but you should be able to fiddle around with that and apply it to your program.
Hope that helps.
TNT
Um, how do I put this...
I don't get it.
Hi,
I will try to explain it a little simpler:
Say you have a chat prog as you said and say your edit box looks like this:
##############
# This Is Line 1 #
# #
# #
##############
So you have one line of text in it, "This is line 1". And if i understand you correctly and sorry if i dont, you want to add another line of text to it. So it looks like this:
##############
# This Is Line 1 #
# This Is Line 2 #
# #
##############
Ok so to do this first once youve made your edit box you put in the first line like this:
in the below code im asuming that you created your edit box using hWndEdit.
Code:char szLine1[100] = "This Is Line 1";
SetWindowText(hWndEdit, szLine1);
Ok so you now have an edit box with "This is line 1" in it.
Now at another point in your program you want to add another line to it, which i think is what your talking about.
Code:char szLine2[100] = "\r\nThis Is Line 2";
//now szLine2 needs to be added onto szLine1 then be displayed:
strcat(szLine1, szLine2); //string.h
//so now szLine1 contains:
//ThisIsLine1
//ThisisLine2
//So now you have added another line we just need to update
//the edit box:
SetWindowText(hWndEdit, szLine2);
Once Done your edit box will have both lines of text in this proccess can be adapted to add multiple lines of text.
I think that is clearer than before, but sorry if i misunderstood your question.
Cheers
TNT
Thank you. Your explanation is perfect.
Look into HDC's.
If you are making a mainly chat app, you should use a Device Context to draw on. Rather than a large editbox. Will be easier in the long run.
Can use scrolling functions, different colours, fonts ect.
Use a Frame control and GetDC().
See
"Errors with resource bitmaps....HELP PLEASE"
for code to create a HDC.
I would also question the wisdom of using an edit box control for displaying this kind of output. I think I would be inclined to use a list box.
Yes, you're right. How do you display info in a list box?
Just do this:
SendMessage(handle_of_listbox, LB_ADDSTRING, (WPARAM)"String to add", (LPARAM)13);
>>SendMessage(handle_of_listbox, LB_ADDSTRING, (WPARAM)"String to add", (LPARAM)13);
I think it is
SendMessage(handle_of_listbox, LB_ADDSTRING, (WPARAM)0, (LPARAM)"String to add");