Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

GPX

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

This topic is 5231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
To your first question:

// HWND = handle to text-edit window

// str = string to append

void 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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
quote:
Original post by nonpop
To your first question:

// HWND = handle to text-edit window

// str = string to append

void 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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!