We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,617 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Help with chat interface (WINAPI)

I am developing a network chat application, I am using Winapi, my main window is a dialog (created from a .rc file).

I am looking into a way of doing an text box where my outuput text can be like this:

Welcome to ##### chat server!
Person1 says: Hi folks, what's up?
Person2 says: Hey... that's Person1!
*Person2 pokes Person1.*
Person1 says: Hey!

I'm using a simple EDIT TEXT control ATM. I've been trying to implement a RICH EDIT CONTROL but it seems to be very hard to do...

Anyone know of a good way to obtain the result in the quote.. should i use some kind of control or window class that I'm missing?

Any information is welcome, a simple demonstration code is more than welcome :)

2
Contributors
3
Replies
2 Weeks
Discussion Span
2 Years Ago
Last Updated
4
Views
Question
Answered
darkbreaker
Newbie Poster
21 posts since Nov 2010
Reputation Points: 43
Solved Threads: 3
Skill Endorsements: 0

MSDN says: http://msdn.microsoft.com/en-us/library/ms645489(v=vs.85).aspx

See under the "Initializing a Text Buffer" section here:
http://msdn.microsoft.com/en-us/library/bb775456(v=vs.85).aspx#text_buffer

pseudorandom21
Practically a Posting Shark
890 posts since Jan 2011
Reputation Points: 216
Solved Threads: 110
Skill Endorsements: 0

Oops I guess my first post was unclear, I am looking into a way to outuput colored text in the controls in my interface.

I know it is possible in RichEdit Control, but I am not being successful into moving the caret to the start of each line to color the diferent parts. :P

darkbreaker
Newbie Poster
21 posts since Nov 2010
Reputation Points: 43
Solved Threads: 3
Skill Endorsements: 0

I got this working a few days ago, gonna post my solution so anyone having the same problem can learn with it :)

HWND richtextHandler //must be global

int chatlog_ADD(const char* msg, int mode=0)
{
    CHARRANGE selection;
    CHARFORMAT fontFormat;
    
    memset(&fontFormat, 0, sizeof fontFormat);
    fontFormat.cbSize = sizeof fontFormat;
    
    switch(mode)
    {
        case 0:  //DEFAULT BLUE TEXT
            fontFormat.dwMask = CFM_COLOR;
            fontFormat.crTextColor = RGB(0,0,255);         
            break;
        case 1:  //BOLD RED TEXT
            fontFormat.dwEffects = CFE_BOLD;
            fontFormat.dwMask = CFM_COLOR|CFM_BOLD;
            fontFormat.crTextColor = RGB(255,0,0);          
            break;

        case 3:  //DARK GREEN TEXT
            fontFormat.dwMask = CFM_COLOR;
            fontFormat.crTextColor = RGB(0,128,0);  
            break;                              
    }

    //Move caret to the end of the text
    selection.cpMin = -1;
    selection.cpMax = -1;
    SendMessage(richtextHandler, EM_EXSETSEL, 0, (LPARAM)&selection); 
    
    //Retrieves the curent position
    SendMessage(richtextHandler, EM_EXGETSEL, 0, (LPARAM)&selection);
    
    //ADDs the text
    SendMessage(richtextHandler, EM_REPLACESEL, 0, (LPARAM)msg); 
    
    //Move caret back to the start of the line (position retrieved earlier)
    SendMessage(richtextHandler, EM_EXSETSEL, 0, (LPARAM)&selection); 
    
    //Set endindg position to the end of the line
    selection.cpMax = -1;
    
    //Selects the line you added
    SendMessage(richtextHandler, EM_EXSETSEL, 0, (LPARAM)&selection);
    
    //Applies the format
    SendMessage(richtextHandler , EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &fontFormat); 
    
    //Set the caret to the end again
    selection.cpMin = -1;
    selection.cpMax = -1;
    SendMessage(richtextHandler, EM_SETSEL, 0,(LPARAM)&selection );
    
    //Scrolls down the scroll bar :)
    SendMessage(richtextHandler, WM_VSCROLL, SB_BOTTOM, (LPARAM)NULL);
}
darkbreaker
Newbie Poster
21 posts since Nov 2010
Reputation Points: 43
Solved Threads: 3
Skill Endorsements: 0
Question Answered as of 2 Years Ago by pseudorandom21

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.1003 seconds using 2.66MB