Win32 Question (visual c++6) :: How to implement a chat box , with an edit box ? +

Started by
5 comments, last by GPX 20 years, 1 month ago
Hi, I''m making a simple chat, and I''m using an edit box (readonly) as the main chat window, in which all the user messages appear. I have 2 problems : 1. How can i add only a single line to my edit box ? Right now, I''m using WM_SETTEXT : each time a message is recieved, i add that message to all the text there has been in the chat box so far, and copying it entirely to the edit box using wm_settext. That means, if there have been 1000 messages post on the chat box, for each new message it will copy 1000+ lines to the edit box, which is really not the way it should be ... so how can i add a single line to an edit box ? 2. How can i automaticly scroll the edit box to the bottom ? i tried GetRange, and SetPos but I''ve had many problems with that, like it scrolls the vertical scroll to the bottom, but the text doesn''t scroll with it ... If there aren''t good answers to my questions, maybe u could suggest another implementation to the chat box instead of an edit box ? Big Thanks ahead.
Yoni Levy.
Advertisement
maybe i can do this with a rich edit box or something ?
i dunno :O
Yoni Levy.
To your first question:
// HWND = handle to text-edit window// str = string to appendvoid append_str (HWND wnd, char const* str){    int len = GetWindowTextLength (wnd);    SendMessage (wnd, EM_SETSEL, (WPARAM) len, (LPARAM) len);    SendMessage (wnd, EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) str);}



"???" --nonpop, every day
actually theres a SetWindowText() function which does that for you :-D, anyways... id use that...
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
He wanted to append the string, not replace everything. There''s a difference...
if you're ok with using DirectPlay, set up a text box as a child object like this:

// Text Box
hLB_TextBox = CreateWindowEx(
WS_EX_CLIENTEDGE, "TEXTBOX", NULL,
WS_CHILD|WS_VISIBLE|LBS_NOTIFY|WS_VSCROLL|WS_BORDER,
10,
55,
315,
250,
hWnd,(HMENU)IDC_hLB_TextBox,hInstance,NULL);

and then make a function to display the text in the box (preferrably in a header file) like this:

void vShowInBox(HWND hChildHandle, char *szText)

so that later you can just use it like this:

vShowInBox(hLB_TextBox,"chat string or whatever goes here");

try this out (by the way, I hate DirectPlay because its microsoft, but thats just me. or half of gamedev.net)

[edit: i forgot scrolling the box down!]

to scroll the box down, flag the last bit of text you put in there as highlighted, or selected, or whatever, and then it will scroll:

MessageBeingSentFromSomeone(hChildHandle,LB_SETCURSEL,Line-1,0);

(btw, never do that^ with your variables )


[edited by - Whelzorn on February 28, 2004 8:42:28 PM]
01001001001000000111010001101000011010010110111001101011001000000111100101101111011101010010000001110111011010010110110001101100001000000110011001101001011011100110010000101100001000000111010001101000011000010111010000100000011110010110111101110101001000000110000101110010011001010010000001101101011001010111001001100101011011000111100100100000011010010110111001110011011010010110010001100101001000000110000100100000011010100110010101101100011011000111100100101110
quote:Original post by nonpop
To your first question:
// HWND = handle to text-edit window// str = string to appendvoid append_str (HWND wnd, char const* str){    int len = GetWindowTextLength (wnd);    SendMessage (wnd, EM_SETSEL, (WPARAM) len, (LPARAM) len);    SendMessage (wnd, EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) str);}



"???" --nonpop, every day


OMG Thanks you so much !!
not only that it works, it also solved my scrolling problem !!
now i can use :
SendMessage(hWndMainServerChat,EM_SCROLL,SB_LINEDOWN,0);
to scroll 1 line down each time a new message is recieved

and btw, to the one with direct play, i dont use direct play :\ i use winsock2, but thanks alot anyway
This forum rox.


Yoni Levy.

[edited by - GPX on February 29, 2004 4:38:23 AM]
Yoni Levy.

This topic is closed to new replies.

Advertisement