MFC EditBox中显示的CString无法回车,\r\n也不行

芝心的鱼 2017-03-07 11:57:59
我用的VS2010写程序,多字节字符集。
下面这段代码可以让Editbox里的内容每次另起一行,\r\n是有效果的。
m_socket.SendTo(SendText,SendText.GetLength(),uint_port,IP);
CString str,SendStr;
CString SendText;
SendStr.Format("Me:%s\r\n",SendText);
GetDlgItemText(IDC_EDIT_History,str);
str=str+SendStr;
SetDlgItemText(IDC_EDIT_History,str);
SetDlgItemText(IDC_EDIT_Send,"");

下面这段代码却不行。。。。
 char RecBuf[128]={0};
CString str,RecStr;
RecStr.Format("%s",RecBuf);
GetDlgItemText(AfxGetApp()->m_pMainWnd->m_hWnd,IDC_EDIT_Receive,(LPSTR)(LPCSTR)str,1024);
str=str+RecStr;
SetDlgItemText(AfxGetApp()->m_pMainWnd->m_hWnd,IDC_EDIT_Receive,str);
这里RecBuf是字符数组,上面那段SendText是CString,不知道是这个原因吗?怎么换行呀
...全文
370 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2017-03-08
  • 打赏
  • 举报
回复
你的edit设置多行了么
摩登码农 2017-03-08
  • 打赏
  • 举报
回复

str = str + RecStr + "\r\n";
SetDlgItemText(AfxGetApp()->m_pMainWnd->m_hWnd,IDC_EDIT_Receive,str);
赵4老师 2017-03-07
  • 打赏
  • 举报
回复
Edit Styles ES_AUTOHSCROLL Automatically scrolls text to the right by 10 characters when the user types a character at the end of the line. When the user presses the ENTER key, the control scrolls all text back to position 0. ES_AUTOVSCROLL Automatically scrolls text up one page when the user presses ENTER on the last line. ES_CENTER Centers text in a single-line or multiline edit control. ES_LEFT Left-aligns text in a single-line or multiline edit control. ES_LOWERCASE Converts all characters to lowercase as they are typed into the edit control. ES_MULTILINE Designates a multiple-line edit control. (The default is single line.) If the ES_AUTOVSCROLL style is specified, the edit control shows as many lines as possible and scrolls vertically when the user presses the ENTER key. If ES_AUTOVSCROLL is not given, the edit control shows as many lines as possible and beeps if ENTER is pressed when no more lines can be displayed. If the ES_AUTOHSCROLL style is specified, the multiple-line edit control automatically scrolls horizontally when the caret goes past the right edge of the control. To start a new line, the user must press ENTER. If ES_AUTOHSCROLL is not given, the control automatically wraps words to the beginning of the next line when necessary; a new line is also started if ENTER is pressed. The position of the wordwrap is determined by the window size. If the window size changes, the wordwrap position changes and the text is redisplayed. Multiple-line edit controls can have scroll bars. An edit control with scroll bars processes its own scroll-bar messages. Edit controls without scroll bars scroll as described above and process any scroll messages sent by the parent window. ES_NOHIDESEL Normally, an edit control hides the selection when the control loses the input focus and inverts the selection when the control receives the input focus. Specifying ES_NOHIDESEL deletes this default action. ES_OEMCONVERT Text entered in the edit control is converted from the ANSI character set to the OEM character set and then back to ANSI. This ensures proper character conversion when the application calls the AnsiToOem Windows function to convert an ANSI string in the edit control to OEM characters. This style is most useful for edit controls that contain filenames. ES_PASSWORD Displays all characters as an asterisk (*) as they are typed into the edit control. An application can use the SetPasswordChar member function to change the character that is displayed. ES_RIGHT Right-aligns text in a single-line or multiline edit control. ES_UPPERCASE Converts all characters to uppercase as they are typed into the edit control. ES_READONLY Prevents the user from entering or editing text in the edit control. ES_WANTRETURN Specifies that a carriage return be inserted when the user presses the ENTER key while entering text into a multiple-line edit control in a dialog box. Without this style, pressing the ENTER key has the same effect as pressing the dialog box’s default pushbutton. This style has no effect on a single-line edit control. See Also CEdit::Create
赵4老师 2017-03-07
  • 打赏
  • 举报
回复
CEdit::Create BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID ); Return Value Nonzero if initialization is successful; otherwise 0. Parameters dwStyle Specifies the edit control’s style. Apply any combination of edit styles to the control. rect Specifies the edit control’s size and position. Can be a CRect object or RECT structure. pParentWnd Specifies the edit control’s parent window (usually a CDialog). It must not be NULL. nID Specifies the edit control’s ID. Remarks You construct a CEdit object in two steps. First, call the CEdit constructor, then call Create, which creates the Windows edit control and attaches it to the CEdit object. When Create executes, Windows sends theWM_NCCREATE,WM_NCCALCSIZE,WM_CREATE, andWM_GETMINMAXINFO messages to the edit control. These messages are handled by default by the OnNcCreate, OnNcCalcSize, OnCreate, and OnGetMinMaxInfo member functions in the CWnd base class. To extend the default message handling, derive a class from CEdit, add a message map to the new class, and override the above message-handler member functions. Override OnCreate, for example, to perform needed initialization for the new class. Apply the following window styles to an edit control. WS_CHILD Always WS_VISIBLE Usually WS_DISABLED Rarely WS_GROUP To group controls WS_TABSTOP To include edit control in the tabbing order CEdit Overview | Class Members | Hierarchy Chart See Also CEdit::CEdit
hudaohai 2017-03-07
  • 打赏
  • 举报
回复
1、在代码中通过create创建Edit控件必须加入ES_MULTILINE 2、对话框中添加的Edit控件需要将Multiline属性设置为true
worldy 2017-03-07
  • 打赏
  • 举报
回复
Edit控件必须创建的时候必须加入ES_MULTILINE 风格,否则你不能显示多行文本
走好每一步 2017-03-07
  • 打赏
  • 举报
回复
RecBuf加换行了吗? Edit控件设成多行了吗?

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧