simple chat program

This is a discussion on simple chat program within the Windows Programming forums, part of the Platform Specific Boards category; I'm new to using the Win32 API but am trying to use it and its dialogs to create a simple ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    13

    simple chat program

    I'm new to using the Win32 API but am trying to use it and its dialogs to create a simple chat program. Where there is one edit box that you write in and another read-only edit box to display what you typed after you press the enter button. I've gotten it to work so when you press enter it will put the text you entered in the read-only box but if you put more in and push enter again then it just erases what is in the display with what you just typed. I've been searching the help files for Win32 but haven't been able to come up with a way to not erase the text but add it, preferably on the next line. Any suggestions on how to do this? I am just limiting myself to basic API for now since I am a beginner.

  2. #2
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    how are you setting the text ? i guess you are using WM_SETTEXT works like SetWindowText().. instead you should use EM_REPLACESEL (or ReplaceSel() function) dont forget to set the selection first using EM_SETSEL (or SetSel() function)
    Last edited by eXistenZ; 12-06-2005 at 04:18 AM.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    13

    using strings with a gui

    ok I've gotten my program to now append strings to the end of content in an read-only edit control using the EM_REPLACESEL trick. But now i've ran into a problem which probably came form my lack of knowledge of c. I am trying to append a new line character which I believe is "\r\n" in windows. So I have a char* buf that I'm trying to send into my SendDlgItemMessage(hwnd, IDC_TEXTDISPLAY, EM_REPLACESEL, FALSE, (LPARAM)buf);

    Now I set up buf by saying:

    buf = (char*)GlobalAlloc(GPTR, 4096);

    char newline[] = "\r\n";

    buf = newline;

    but when I run the program and the SendDlgItemMessage() goes it puts like chinese characters into edit box??

    So I tried a different approach:

    string temp = "\r\n";
    strcat(buf, temp.c_str());

    but it still wouldn't put the newline in, finally I tried

    string temp = "A\r\n";
    strcat(buf, temp.c_str());

    And it finally sort of worked because it put a newline in, but it leaves this box like [] at the end of each line. This is weird behavior, does anyone have any idea how to fix this? Am I using the char* right when I'm developing a windows app?

    Thanks

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Does the edit have the ES_MULTILINE style?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    13
    yes it does have the ES_MULTILINE style on it. It really has to do with the cstrings they act different than I expected. This is so frustrating cause I'm so close to have something actually working but just can't seem to figure it out

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    13
    Just wanted to bump to try and get some help. Its the wierdest thing when I have a char* buf and then add it to the end of the edit box it all comes up in chinese. Also, normally when I have a char* then if I want to turn it into a c++ string then I just pass it to a string like string(char*). But when I'm doing it in my project only the first character of the char* gets passed to the new string. Any ideas on how to work with these c-style strings so I get more desired result?

    edit: I think I found out what may be causing my problem. In some of the winAPI methods I am using it requires that you pass it a LPWSTR and I just cast a normal char* and passed it well I think this may be why my results are coming up in chinese. Does anyone have any insight if this seems plausible and if so how to get around this?
    Last edited by daioyayubi; 12-07-2005 at 10:54 AM.

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    What API method are you using which requires a LPWSTR? Pretty much all the API methods take a LPTSTR. If you can, post your code. That will help us to identify your problem.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Perhaps learning either C or C++ first would be a start, rather than diving straight into the win32 API and then randomly guessing whether it's char[], char * or std::string which is required.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple window program
    By baniakjr in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2006, 02:46 PM
  2. Help with simple program
    By nik2007 in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2006, 08:54 AM
  3. Replies: 4
    Last Post: 07-05-2004, 07:41 PM
  4. simple frontend program problem
    By gandalf_bar in forum Linux Programming
    Replies: 16
    Last Post: 04-22-2004, 06:33 AM
  5. Simple Math Program
    By RazielX in forum C Programming
    Replies: 3
    Last Post: 03-04-2004, 05:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21