Link to home
Start Free TrialLog in
Avatar of tolvumeistari
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
ASKER CERTIFIED SOLUTION
Avatar of ronit051397
ronit051397

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tolvumeistari
tolvumeistari

ASKER

ohhh one left

i have to open notepad first with my button and then send the message
I am going home now, I'll continue tomorrow.
Bye
Ronit,
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(FFilePath: 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.hProcess, 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('notepad'); //execute the notepad process
  H:=FindWindowEx(GetThreadWindow(ThreadID), 0, 'edit', nil);//find the control handle
  SendMessage(H, WM_SETTEXT, 0, Integer(pChar('This is my message')));//send the text
end;

thanks - the points is yours...
With clipboard!

Memo1.CopyToClipboard;