Solved

Send text to notepad

Posted on 1998-12-27
7
1,547 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
  • 3
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 50 total points
Comment Utility
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
Comment Utility
ohhh one left

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

Expert Comment

by:ronit051397
Comment Utility
I am going home now, I'll continue tomorrow.
Bye
Ronit,
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:tolvumeistari
Comment Utility
okey - thanks
0
 
LVL 5

Expert Comment

by:ronit051397
Comment Utility
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
Comment Utility
thanks - the points is yours...
0
 
LVL 1

Expert Comment

by:slautin
Comment Utility
With clipboard!

Memo1.CopyToClipboard;

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now