#include <stdio.h>
#include <tchar.h>
#include <time.h>
#include <Windows.h>
#include <CommCtrl.h>
#include <WindowsX.h>
#include "resource.h"
#pragma comment(lib, "comctl32.lib")
#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' language='*' publicKeyToken='6595b64144ccf1df'\"")
void add_new_line(HWND hedit, HWND hstatic)
{
char str[100];
char *p, *q;
int i, len, size;
time_t t;
struct tm tm;
// 根据当前时间生成新行内容
time(&t);
localtime_s(&tm, &t);
strftime(str, sizeof(str), "当前时间: %Y-%m-%d %H:%M:%S", &tm);
len = GetWindowTextLengthA(hedit) + 2 + strlen(str); // 新文本长度 = 原有文本长度 + 换行符长度 + 新行长度
size = len + 1; // 新文本长度 + 字符串结束符长度
p = (char *)malloc(size);
if (p != NULL)
{
// 新添加一行
GetWindowTextA(hedit, p, size); // 获取原有文本
if (p[0] != '\0')
strcat_s(p, size, "\r\n"); // 添加换行符
strcat_s(p, size, str); // 添加新行
SetWindowTextA(hedit, p); // 设置新文本
// 计算总行数
i = 1;
for (q = strstr(p, "\r\n"); q != NULL; q = strstr(q + 2, "\r\n"))
i++;
_snprintf_s(str, sizeof(str), sizeof(str) - 1, "行数: %d", i);
SetWindowTextA(hstatic, str);
free(p);
// 光标移动到末尾
SetFocus(hedit);
Edit_Scroll(hedit, i, 0);
Edit_SetSel(hedit, len, len);
}
}
LRESULT CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int wmId;
HWND hedit, hstatic;
switch (uMsg)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
switch (wmId)
{
case IDOK:
hedit = GetDlgItem(hDlg, IDC_EDIT1);
hstatic = GetDlgItem(hDlg, IDC_STATIC2);
add_new_line(hedit, hstatic);
break;
case IDCANCEL:
EndDialog(hDlg, 0);
break;
}
case WM_INITDIALOG:
break;
}
return 0;
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
int ret;
InitCommonControls();
ret = DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
return ret;
}
没有合适的资源?快使用搜索试试~ 我知道了~
Win32 EditControl多行文本框自动换行,并在添加新行时自动将光标移到末尾
共63个文件
tlog:32个
pdb:4个
res:3个
1 下载量 63 浏览量
2023-08-05
23:48:00
上传
评论
收藏 453KB ZIP 举报
温馨提示
Win32 EditControl多行文本框自动换行,并在添加新行时自动将光标移到末尾
资源推荐
资源详情
资源评论
收起资源包目录
多行文本框换行2.zip (63个子文件)
last_line
last_line
resource.h 1KB
last_line.vcxproj 4KB
Release
CL.write.1.tlog 1KB
rc.command.1.tlog 2KB
rc.write.1.tlog 778B
last_line.exe.intermediate.manifest 638B
mt.command.1.tlog 1KB
mt.read.1.tlog 3KB
rc.read.1.tlog 7KB
last_line.log 2KB
last_line.res 272B
vc100.pdb 76KB
link.command.1.tlog 5KB
link-cvtres.read.1.tlog 2B
link.read.1.tlog 9KB
cl.command.1.tlog 2KB
link.write.1.tlog 2KB
link-cvtres.write.1.tlog 2B
last_line.lastbuildstate 67B
mt.write.1.tlog 904B
main.obj 49KB
CL.read.1.tlog 40KB
last_line.vcxproj.filters 1KB
last_line.vcxproj.user 143B
last_line.rc 4KB
main.c 2KB
Debug
CL.write.1.tlog 1KB
rc.command.1.tlog 3KB
rc.write.1.tlog 2KB
link.1744-cvtres.write.1.tlog 2B
last_line.exe.intermediate.manifest 638B
mt.command.1.tlog 1KB
last_line.exe.embed.manifest.res 744B
link.1744.read.1.tlog 2B
mt.read.1.tlog 1KB
rc.read.1.tlog 8KB
vc100.idb 259KB
last_line.log 955B
last_line.Build.CppClean.log 2KB
last_line_manifest.rc 208B
last_line.res 272B
vc100.pdb 76KB
link.1744-cvtres.read.1.tlog 2B
link.command.1.tlog 5KB
link-cvtres.read.1.tlog 2B
link.read.1.tlog 9KB
cl.command.1.tlog 2KB
link.write.1.tlog 3KB
last_line.exe.embed.manifest 680B
link-cvtres.write.1.tlog 2B
last_line.lastbuildstate 65B
mt.write.1.tlog 390B
main.obj 25KB
link.1744.write.1.tlog 2B
CL.read.1.tlog 40KB
last_line.aps 18KB
last_line.suo 11KB
Release
last_line.pdb 963KB
last_line.exe 58KB
last_line.sln 894B
Debug
last_line.ilk 372KB
last_line.pdb 491KB
last_line.exe 31KB
共 63 条
- 1
资源评论
巨大八爪鱼
- 粉丝: 1544
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功