1、创建Edit控件
int x0=2,y0=2,control_width=240,control_height=200;
HWND hWndMsg = CreateWindow(L"edit", L"",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE,
x0, y0, control_width, control_height, hWndMain, NULL, NULL, NULL);
2、建立输出消息的函数
int mTextCounts = 0;
void show_msg(char * msg)
{
char EditText[4096] = "";
strcat_s(EditText, msg);
int len_in = strlen(EditText);
len_in++;
int nwLen = MultiByteToWideChar(CP_ACP, 0, EditText, len_in, NULL, 0);
LPWSTR lpszPath = new WCHAR[len_in];
MultiByteToWideChar(CP_ACP, 0, EditText, len_in, lpszPath, nwLen);
mTextCounts++;
if (mTextCounts >= 100)
{
mTextCounts = 0;
SendMessage(hWndMsg, WM_SETTEXT, true, (LPARAM)lpszPath);
}
SendMessage(hWndMsg, EM_SETSEL, -2, -1);
SendMessage(hWndMsg, EM_REPLACESEL, true, (LPARAM)lpszPath);
SendMessage(hWndMsg, WM_VSCROLL, SB_BOTTOM, true);
}
3、调用函数进行显示
#define MAX_StringNum 260
char app_msg[MAX_StringNum];
sprintf_s(app_msg, "Window Created.\r\n");
show_msg(app_msg);
4、重载,实现常量字符串显示
void show_msg(const char msg[]);
void show_msg(const char msg[])
{
char EditText[4096] = "";
strcat_s(EditText, msg);
int len_in = strlen(EditText);
len_in++;
int nwLen = MultiByteToWideChar(CP_ACP, 0, EditText, len_in, NULL, 0);
LPWSTR lpszPath = new WCHAR[len_in];
MultiByteToWideChar(CP_ACP, 0, EditText, len_in, lpszPath, nwLen);
mTextCounts++;
if (mTextCounts >= 100)
{
mTextCounts = 0;
SendMessage(hWndMsg, WM_SETTEXT, true, (LPARAM)lpszPath);
}
SendMessage(hWndMsg, EM_SETSEL, -2, -1);
SendMessage(hWndMsg, EM_REPLACESEL, true, (LPARAM)lpszPath);
SendMessage(hWndMsg, WM_VSCROLL, SB_BOTTOM, true);
}