Well, create the regular application, drop a button
onto its main form and add modify OnClick event as follows:
|
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
Ini: TIniFile;
ThreadId: Integer;
begin
Ini:=TIniFile.Create('SvComEx22.dat');
ThreadId:=Ini.ReadInteger('Ex22SvcA','ThreadId',0);
Ini.Free;
if ThreadId = 0 then
Raise Exception.Create('Service Ex22SvcA is not started');
PostThreadMessage(THreadId,WM_USER+1,220,1000);
PostThreadMessage(THreadId,WM_USER+1,440,1000);
end;
|
Save and compile the client, install and run the
service. Then run the client application and press a button. You will hear a
couple of beeps meaning that our service successfully receives windows
messages!
The source code of this step is available
here (zip, 5.4kb). By the way it plays a well known
melody instead of two beeps :)
|