Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1804
  • Last Modified:

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
0
tolvumeistari
Asked:
tolvumeistari
  • 3
  • 3
1 Solution
 
ronit051397Commented:
procedure TForm1.Button1Click(Sender: TObject);
var H: Hwnd;
begin
  H:= FindWindowEx(Findwindow('notepad', nil), 0, 'edit', nil);
  SendMessage(H, WM_SETTEXT, 0, Integer(pChar('This is my message')));
end;

0
 
tolvumeistariAuthor Commented:
ohhh one left

i have to open notepad first with my button and then send the message
0
 
ronit051397Commented:
I am going home now, I'll continue tomorrow.
Bye
Ronit,
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
tolvumeistariAuthor Commented:
okey - thanks
0
 
ronit051397Commented:
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;

0
 
tolvumeistariAuthor Commented:
thanks - the points is yours...
0
 
slautinCommented:
With clipboard!

Memo1.CopyToClipboard;

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now