Solved

Send text to notepad

Posted on 1998-12-27
7
1,667 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
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!

 

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

689 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