I have created an edit box using win32 app. I want that what ever strings are entered into the edit box should be retained in it.
For example:
I have two strings:
1. "hello world"
2. "Great to have you"
When I enter second string, the first disappears. I want that second string should come in next line and this continues for next strings as well. This is same as what happens in a chat output box.
I have one more issue apart from this. Suppose a function fails and I do check the error using GetLastError() function. I want to pass this error in the edit box using SetDlgItemText(). However, SetDlgItemText() takes only char string as input in a buffer. How to send the error which is integer.
For #2, convert the integer to a string. The following is good for C++. Note that I have defined the tstring data type to accommodate for both ANSI and Unicode builds.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <sstream>
#ifdef _UNICODE
typedef std::wstring tstring;
typedef std::wstringstream tstringstream;
#else
typedef std::string tstring;
typedef std::stringstream tstringstream;
#endif
int i = 5;
tstring s;
tstringstream out;
out << i;
s = out.str();
//At this point, s is a std::string (or std::wstring) that contains the number as a string.
//Use it with SetDlgItemText().
SetDlgItemText(theDlgWnd, theEditID, s.c_str());
Thanks for the reply. I had solved the second issue by myself. However, the first issue is not about using multiline edit control. I am already doing it. My issue is somewhat different. I want to enter the two strings programmically. It should store the strings coming from program one after the other.
I imagine that you want to keep the previous string and just append the new one. In this case I would keep the entire string myself, concatenate, and then pass to the control with WM_SETTEXT.
1 2 3 4 5 6 7 8 9 10 11
//At procedure level, or maybe file level, you declare:
tstring strConversation;
//Then you append to this string variable any new text. Let's assume there is a function for that.
void AppendNewText(tstring &newText)
{
strConversation += strConversation.size() ? TEXT("\r\n") : TEXT("");
strConversation += newText;
//Finally, you set the text in the control. This may or may not be appropriate here.
SendMessage(myEditControl, WM_SETTEXT, 0, strConversation.c_str());
}
EDIT: I just remembered that you use SetDlgItemText():