GetWindowText例子 procedure TForm1.Button1Click(Sender: TObject); var TheText: PChar; // this will hold the window text TextLen: Integer; // the length of the window text begin {get the length of the window text} TextLen:=GetWindowTextLength(Form1.Handle); {dynamically allocate space based on the window text length} GetMem(TheText,TextLen); {get the window text. we must add 1 to account for the terminating null character} GetWindowText(Form1.Handle,TheText,TextLen+1); {display this text in the edit box} Edit1.Text:=string(TheText); {free the memory for the new string} FreeMem(TheText);end;procedure TForm1.Button2Click(Sender: TObject); begin {set the text of the window to the string in the edit box} SetWindowText(Form1.Handle, PChar(Edit1.Text)); end;
谢谢各位回答我的问题!----liigou2m(UpToMe) 的程序我试过了,只能取编辑框的一行文本,对于多行文本就无能为力了。lt30(PASCAL) 的思路(用sendmessage函数发一个消息)我也用过: Clipboard.Clear; SendMessage(hwnd,EM_SETSEL,0,-1); //Select All SendMessage(hwnd,WM_COPY,0,0); //Copy to clipboard SendMessage(hwnd,EM_SETSEL,0,0); //unSelect all Memo1.Lines.Clear; Memo1.PasteFromClipboard; 以上代码可以取到记事本和EditPlus里面的所有文本,但对word和delphi的编辑区却无能为力!(UltraEdit我没有试过。)我希望能够取到所有主流编辑器中的文本。 请朋友们帮帮我!
既然lt30(PASCAL) 的思路可以了,你把他方法再扩展一下不就行了首先发送 Ctrl+ A 消息给该编辑区 再COPY不就可以了吗!
如果WM_COPY消息没效果,你还可以试试发送CTRL+C消息!:)呵呵,我没测试!
我觉得用windows自带的函数应该可以完成,还有多上网看看。
象delphi、UltraEdit等的编辑区,其“类名”并不是Edit或TEdit, 所以不接受类似wm_copy的(用于标准编辑区)消息。各位,我该怎么办呀?! //已知编辑区的句柄,如何获得里面的全部文本? 解决了我给200分,300分也行!zwjchina(蒲石)的思路(首先发送 Ctrl+ A 消息给该编辑区,再COPY)好像有戏, 我回去试一下,先谢过了!////////////
具体消息的代号请查找WINDOWS 消息
VC里的好象用到SEVEROBJECTS!!!!
procedure TForm1.Button1Click(Sender: TObject);
var
TheText: PChar; // this will hold the window text
TextLen: Integer; // the length of the window text
begin
{get the length of the window text}
TextLen:=GetWindowTextLength(Form1.Handle); {dynamically allocate space based on the window text length}
GetMem(TheText,TextLen); {get the window text. we must add 1 to account for the terminating null character}
GetWindowText(Form1.Handle,TheText,TextLen+1); {display this text in the edit box}
Edit1.Text:=string(TheText); {free the memory for the new string}
FreeMem(TheText);end;procedure TForm1.Button2Click(Sender: TObject);
begin
{set the text of the window to the string in the edit box}
SetWindowText(Form1.Handle, PChar(Edit1.Text));
end;
Clipboard.Clear;
SendMessage(hwnd,EM_SETSEL,0,-1); //Select All
SendMessage(hwnd,WM_COPY,0,0); //Copy to clipboard
SendMessage(hwnd,EM_SETSEL,0,0); //unSelect all
Memo1.Lines.Clear;
Memo1.PasteFromClipboard;
以上代码可以取到记事本和EditPlus里面的所有文本,但对word和delphi的编辑区却无能为力!(UltraEdit我没有试过。)我希望能够取到所有主流编辑器中的文本。 请朋友们帮帮我!
再COPY不就可以了吗!
所以不接受类似wm_copy的(用于标准编辑区)消息。各位,我该怎么办呀?!
//已知编辑区的句柄,如何获得里面的全部文本? 解决了我给200分,300分也行!zwjchina(蒲石)的思路(首先发送 Ctrl+ A 消息给该编辑区,再COPY)好像有戏,
我回去试一下,先谢过了!////////////