tolvumeistari
asked on
Send text to notepad
Hi..
I have a little program that have to send texts to notepad and the user will then save it.
E.g all the text in listbox ( send directly to notepad )
Thanks in advance
tolv
I have a little program that have to send texts to notepad and the user will then save it.
E.g all the text in listbox ( send directly to notepad )
Thanks in advance
tolv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am going home now, I'll continue tomorrow.
Bye
Ronit,
Bye
Ronit,
ASKER
okey - thanks
I am back. Write the following code:
implementation
var ThreadID: DWORD;
function GetWindowHandle(H: HWnd; pWin: Pointer): Boolean; stdcall;
begin
Result:=True;
if IsWindowEnabled(H) and IsWindowVisible(H) then
begin
HWnd(pWin^):=H;
Result:=False;
end;
end;
function GetThreadWindow(tId: Integer): HWnd;
var H: HWnd;
begin
H:=0;
EnumThreadWindows(tId, @GetWindowHandle, Integer(@H));
Result:=H;
end;
function CreateProcessSimple(FFileP ath: string): String;
var
pi: TProcessInformation;
si: TStartupInfo;
begin
FillMemory(@si, Sizeof(si), 0);
si.cb:=Sizeof(si);
CreateProcess(Nil, PChar(FFilePath), Nil, Nil, False, NORMAL_PRIORITY_CLASS, Nil, Nil, si, pi );
WaitForInputIdle(pi.hProce ss, INFINITE);//wait until process loads
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
ThreadID:=pi.dwThreadId;
end;
procedure TForm1.Button1Click(Sender : TObject);
var H: HWnd;
begin
CreateProcessSimple('notep ad'); //execute the notepad process
H:=FindWindowEx(GetThreadW indow(Thre adID), 0, 'edit', nil);//find the control handle
SendMessage(H, WM_SETTEXT, 0, Integer(pChar('This is my message')));//send the text
end;
implementation
var ThreadID: DWORD;
function GetWindowHandle(H: HWnd; pWin: Pointer): Boolean; stdcall;
begin
Result:=True;
if IsWindowEnabled(H) and IsWindowVisible(H) then
begin
HWnd(pWin^):=H;
Result:=False;
end;
end;
function GetThreadWindow(tId: Integer): HWnd;
var H: HWnd;
begin
H:=0;
EnumThreadWindows(tId, @GetWindowHandle, Integer(@H));
Result:=H;
end;
function CreateProcessSimple(FFileP
var
pi: TProcessInformation;
si: TStartupInfo;
begin
FillMemory(@si, Sizeof(si), 0);
si.cb:=Sizeof(si);
CreateProcess(Nil, PChar(FFilePath), Nil, Nil, False, NORMAL_PRIORITY_CLASS, Nil, Nil, si, pi );
WaitForInputIdle(pi.hProce
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
ThreadID:=pi.dwThreadId;
end;
procedure TForm1.Button1Click(Sender
var H: HWnd;
begin
CreateProcessSimple('notep
H:=FindWindowEx(GetThreadW
SendMessage(H, WM_SETTEXT, 0, Integer(pChar('This is my message')));//send the text
end;
ASKER
thanks - the points is yours...
With clipboard!
Memo1.CopyToClipboard;
Memo1.CopyToClipboard;
ASKER
i have to open notepad first with my button and then send the message