home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programming Unleashed
/
Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso
/
misc
/
wintalk
/
main.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-03-20
|
2KB
|
91 lines
unit Main;
{ Program copyright (c) 1995 by Charles Calvert }
{ Project Name: WINTALK }
{ Use this program along with the DOS program called
WINTALK to find out how a Windows program can talk
to a DOS program. }
interface
uses
WinTypes, WinProcs, SysUtils,
Classes, Graphics,
Controls,
Printers, Forms, Messages, StdCtrls;
type
TForm1 = class(TForm)
BTalkDos: TButton;
Edit1: TEdit;
BSetData: TButton;
TEnterData: TLabel;
Edit2: TEdit;
procedure BTalkDosClick(Sender: TObject);
procedure BSetDataClick(Sender: TObject);
end;
var
Form1: TForm1;
implementation
uses
StrBox, UtilBox;
{$R *.DFM}
procedure TForm1.BTalkDosClick(Sender: TObject);
const
FILENAME = 'wintalk.exe';
var
hText: THandle;
S: String;
i: Integer;
begin
S := StripLastToken(ParamStr(0), '\');
S := S + '\' + FileName;
i := WinExecAndWait(FILENAME, SW_SHOWNORMAL);
if i < 32 then begin
Edit2.Text := IntToStr(i);
Exit;
end;
OpenClipBoard(Handle);
hText := GetClipBoardData(CF_TEXT);
S := StrPas(GlobalLock(hText));
GlobalUnlock(hText);
CloseClipBoard;
Edit2.Text := S;
end;
procedure SendToClipBoard(Handle: THandle; S: String);
var
HText: THandle;
P: PChar;
B: Array[0..25] of Char;
begin
HText := GlobalAlloc(GHND, Length(S) + 1);
P := GlobalLock(HText);
Move(S[1], P^, Length(S));
GlobalUnLock(HText);
OpenClipboard(Handle);
EmptyClipBoard;
SetClipBoardData(CF_TEXT, HText);
CloseClipBoard;
end;
procedure TForm1.BSetDataClick(Sender: TObject);
var
S: String;
begin
S := Edit1.Text;
if Length(S) = 0 then begin
Edit1.Text := 'Write something here!';
exit;
end;
SendToClipBoard(Handle, S);
end;
end.