Bu kod bu konu içinde paylaşılan kod. Ben kopyalayıp denedim. Burada tek dikkat edilecek nokta Whatsupp uygulamasını (WEB olanı değil) bilgisayarınıza kurmuş olmanız lazım.
Kod:
unit Unit5;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ShellApi, Vcl.StdCtrls;
type
TForm5 = class(TForm)
Button1: TButton;
btn1: TButton;
procedure Button1Click(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
procedure SendKey(hWnd: THandle; KeyStroke: Word);
begin
PostMessage(hWnd, WM_SETFOCUS, 0, 0);
PostMessage(hWnd, WM_KEYDOWN, KeyStroke, 0);
PostMessage(hWnd, WM_KEYUP, KeyStroke, 0);
end;
procedure WhatsAppMesaj;
var
SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
ExecuteFile, ParamString, StartInString: string;
MyHandle: THandle;
MMessage : ansistring;
begin
MMessage := 'Merhaba...!!!';
ExecuteFile:='whatsapp://send/?phone=+905322445***'+'&text='+MMessage;
FillChar(SEInfo, SizeOf(SEInfo), 0);
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
with SEInfo do begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpFile := PChar(ExecuteFile);
// lpParameters := PChar(ParamString);
{
StartInString specifies the
name of the working directory.
If ommited, the current directory is used.
}
// lpDirectory := PChar(StartInString);
nShow := SW_SHOWNORMAL
end;
if ShellExecuteEx(@SEInfo) then begin
repeat
Application.ProcessMessages;
//** Send Enter Key !!!
MyHandle:=FindWindow(nil, 'Whatsapp');
SendKey(MyHandle,VK_RETURN);
GetExitCodeProcess(SEInfo.hProcess, ExitCode);
until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
//ShowMessage('WhatsApp terminated');
end
else ShowMessage('Error starting WhatsApp!');
end;
procedure TForm5.btn1Click(Sender: TObject);
begin
WhatsAppMesaj;
end;
procedure TForm5.Button1Click(Sender: TObject);
var
MyHandle: THandle;
begin
MyHandle:=FindWindow(nil, 'WhatsApp');
SendMessage(MyHandle, WM_CLOSE, 0, 0);
form5.Close;
end.