sendmessage用不了

baiylhnh 2013-01-18 06:51:09
我想现实的功能是把MEMO中的文本.一行一行的弄到记事本里
但是每次执行都盖掉了原来的文本.怎么让他们实现自动换行并不盖掉原来的内容

var windows,windowsex:hwnd;
procedure writetxt();
var i:dword;
temp:string;
begin
windows:=FindWindow('Notepad',nil);
if windows<>0 then
begin
windowsex:=FindWindowEx(windows,0,'edit',nil);
while True do
begin
if i>form1.Memo1.Lines.Count-1 then
i:=0
else
begin
SendMessage(windowsex,WM_SETTEXT,Length(form1.Memo1.Text),
Integer(PChar(form1.Memo1.lines[i]))); //问题肯定出在这里
inc(i);
sleep(2500);
end;
end;
end
else
showmessage('22222222222');
end;


还有一个问题.我向指定的窗口发送回车
sendmessage(windows,WM_CHAR,13,0) //为什么一点反应也没有.句柄没有错
...全文
566 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
parhelia512 2013-01-19
  • 打赏
  • 举报
回复
引用 6 楼 baiylhnh 的回复:
非常感谢你的回答.但是没有用.还是把原来的内容给盖掉了
请确认加入了SendMessage(windowsex,WM_GETTEXT,sizeof(str),integer(@str)); 如果还是覆盖,请查看这行运行后str的值是否为notepad当前的内容
baiylhnh 2013-01-19
  • 打赏
  • 举报
回复
引用 5 楼 parhelia512 的回复:
直接上代码: Delphi/Pascal code?1234567891011121314151617181920212223242526var windows,windowsex:hwnd; procedure writetxt();var i:dword; temp:string; str:array[0..255] of char;begin windows……
非常感谢你的回答.但是没有用.还是把原来的内容给盖掉了
baiylhnh 2013-01-19
  • 打赏
  • 举报
回复
引用 7 楼 parhelia512 的回复:
引用 6 楼 baiylhnh 的回复:非常感谢你的回答.但是没有用.还是把原来的内容给盖掉了 请确认加入了SendMessage(windowsex,WM_GETTEXT,sizeof(str),integer(@str)); 如果还是覆盖,请查看这行运行后str的值是否为notepad当前的内容
我自己搞定了.不应该用WM_GETTEXT应该用WM_Char 最后一个问题.我用sendmessage(h,wm_char,13,0);往记事本里发回车OK 但是一进入游戏.就没反应了.为什么啊
parhelia512 2013-01-18
  • 打赏
  • 举报
回复
直接上代码:

var windows,windowsex:hwnd;

procedure writetxt();
var i:dword;
  temp:string;
  str:array[0..255] of char;
begin
  windows:=FindWindow('Notepad',nil);
  if windows<>0 then
  begin
    windowsex:=FindWindowEx(windows,0,'edit',nil);
    i:=0;
    while True do
    begin
      if i<form1.Memo1.Lines.Count then
      begin
        SendMessage(windowsex,WM_GETTEXT,sizeof(str),integer(@str));
        SendMessage(windowsex,WM_SETTEXT,0,Integer(PChar(string(str)+form1.Memo1.lines[i]+#13#10)));
        inc(i);
        sleep(2500);
      end;
    end;
  end
  else
    showmessage('22222222222');
end;
baiylhnh 2013-01-18
  • 打赏
  • 举报
回复
引用 2 楼 HSFZXJY 的回复:
楼上说的对,我觉得你的想法很奇怪
我在练习线程操作..不然我吃饱了撑啊
baiylhnh 2013-01-18
  • 打赏
  • 举报
回复
引用 1 楼 sololie 的回复:
为什么不把memo内所有内容保存为一个文本文件,然后调用记事本打开该文件?
我在练习线程操作..不然我吃饱了撑啊
hsfzxjy 2013-01-18
  • 打赏
  • 举报
回复
楼上说的对,我觉得你的想法很奇怪
sololie 2013-01-18
  • 打赏
  • 举报
回复
为什么不把memo内所有内容保存为一个文本文件,然后调用记事本打开该文件?

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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