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.
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)
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";
but it still wouldn't put the newline in, finally I tried
string temp = "A\r\n";
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?
Does the edit have the ES_MULTILINE style?
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 :confused:
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?
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.
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.