如何在Win32编辑控件中删除CRLF?
我是 @in32的新手,并制作了简单的聊天应用程序。
现在,我实现编辑控件来编写消息,由 Enter 键提交,但不是 ctrl + enter 。 (我想要 ctrl + Enter 制作新行。)
我使用子过程制作了它们。
问题在于,当我通过 Enter 提交消息时,编辑控件将成为第二行,并且光标指出了这一点。
我想在按 Enter 时清楚地进行编辑控件。
这是我的代码
LRESULT CALLBACK SubEditProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
HDC hdc;
PAINTSTRUCT ps;
RECT rt = { 20,20,200,500 };
switch (uMsg)
{
case WM_KEYDOWN:
switch (wParam) {
case VK_RETURN:
if (!GetAsyncKeyState(VK_CONTROL)) {
hdc = GetDC(GetParent(hEdit));
TCHAR buff[1024];
GetWindowText(hEdit, buff, 1024);
SetDlgItemText(GetParent(hEdit), ID_EDIT, (LPCWSTR)"");
DrawText(hdc, buff, -1, &rt, DT_LEFT);
ReleaseDC(GetParent(hEdit), hdc);
}
break;
}
break;
default:
return CallWindowProc(DefEditProc, hWnd, uMsg, wParam, lParam);
}
return FALSE;
}
I'm new to @in32 and making simple chatting app.
Now I implement edit control to write message, submit by Enter key but not Ctrl + Enter. (I want Ctrl + Enter to make new line.)
I made them using sub procedure.
The problem is that when I submit message by Enter the edit control makes a second line, and cursor point that.
I want make edit control clearly when press Enter.
Here's my code
LRESULT CALLBACK SubEditProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
HDC hdc;
PAINTSTRUCT ps;
RECT rt = { 20,20,200,500 };
switch (uMsg)
{
case WM_KEYDOWN:
switch (wParam) {
case VK_RETURN:
if (!GetAsyncKeyState(VK_CONTROL)) {
hdc = GetDC(GetParent(hEdit));
TCHAR buff[1024];
GetWindowText(hEdit, buff, 1024);
SetDlgItemText(GetParent(hEdit), ID_EDIT, (LPCWSTR)"");
DrawText(hdc, buff, -1, &rt, DT_LEFT);
ReleaseDC(GetParent(hEdit), hdc);
}
break;
}
break;
default:
return CallWindowProc(DefEditProc, hWnd, uMsg, wParam, lParam);
}
return FALSE;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论