Solved

Send text to notepad

Posted on 1998-12-27
7
1,633 Views
Last Modified: 2008-02-26
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
Comment
Question by:tolvumeistari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 50 total points
ID: 1353266
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
 

Author Comment

by:tolvumeistari
ID: 1353267
ohhh one left

i have to open notepad first with my button and then send the message
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1353268
I am going home now, I'll continue tomorrow.
Bye
Ronit,
0
Technology Partners: 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!

 

Author Comment

by:tolvumeistari
ID: 1353269
okey - thanks
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1353270
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
 

Author Comment

by:tolvumeistari
ID: 1353271
thanks - the points is yours...
0
 
LVL 1

Expert Comment

by:slautin
ID: 1353272
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 127
PHP preg_replace code convert to Delphi 14 82
Tvertscrollbox like a whatsapp layout 5 53
enhance the following code 3 42
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question