我一直在尝试在Edit控件中创建一个新行。我使用了来自Win32 - Appending text to an Edit Control的示例代码,只进行了一些小改动
要回答关于多行的问题,是的。
CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_MULTILINE,
0,0,300,500,hwnd,(HMENU)1,inst,NULL);
这是编辑过的代码
// get edit control from dialog
HWND hwndOutput = GetDlgItem( hwnd, IDC_OUTPUT );
// get the current selection
DWORD StartPos, EndPos;
SendMessage( hwndOutput, EM_GETSEL, reinterpret_cast<WPARAM>(&StartPos), reinterpret_cast<WPARAM>(&EndPos) );
// move the caret to the end of the text
int outLength = GetWindowTextLength( hwndOutput );
SendMessage( hwndOutput, EM_SETSEL, outLength, outLength );
//INSERTED CODE INSERTED CODE INSERTED CODE INSERTED CODE INSERTED CODE
// insert newline
SendMessage( hwndOutput, EM_REPLACESEL, TRUE, reinterpret_cast<LPARAM>((TCHAR*)"\n\r") );
int outLength = GetWindowTextLength( hwndOutput );
SendMessage( hwndOutput, EM_SETSEL, outLength, outLength );
//INSERTED CODE INSERTED CODE INSERTED CODE INSERTED CODE INSERTED CODE
// insert the text at the new caret position
SendMessage( hwndOutput, EM_REPLACESEL, TRUE, reinterpret_cast<LPARAM>(newText) );
// restore the previous selection
SendMessage( hwndOutput, EM_SETSEL, StartPos, EndPos );
文本按预期追加,但仍然没有换行符。我错过了什么?