-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwmipc.pas
114 lines (89 loc) · 2.62 KB
/
wmipc.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
unit wmipc;
interface
uses
Windows, classes, SysUtils, Messages;
{
type
TCopyDataStruct = record
dwData: DWORD;
cbData: DWORD;
lpData: Pointer;
end;
{
TCopyDataStruct = packed record
dwData: DWORD_PTR;
cbData: DWORD_PTR;
lpData: Pointer;
end;
}
procedure wm_sendstringex(sender: HWND; target: hwnd; strtosend: string);
procedure wm_sendstring(sender: HWND; title: string; strtosend: string);
procedure wm_sendcommand(window: string; _message, command: Cardinal; const param: Cardinal = 0);
implementation
procedure wm_sendcommand(window: string; _message, command: Cardinal; const param: Cardinal = 0);
var
receiverHandle: THandle;
begin
try
receiverHandle := FindWindow(nil, PChar(window));
if receiverHandle <> 0 then
SendMessage(receiverHandle, _message, command, param);
except
on e: exception do
begin
end;
end;
end;
procedure wm_sendstring(sender: HWND; title: string; strtosend: string);
var
copyDataStruct: TCopyDataStruct;
receiverHandle: THandle;
begin
try
copyDataStruct.dwData := sender;
CopyDataStruct.cbData := (Length(strtosend) + 1) * SizeOf(Char);
copyDataStruct.lpData := PChar(strtosend);
receiverHandle := FindWindow(nil, PChar(title));
if receiverHandle <> 0 then
begin
SendMessage(receiverHandle, WM_COPYDATA, sender, LPARAM(@CopyDataStruct));
end;
except
on e: exception do
begin
end;
end;
end;
function GetWindowTitle(HWND: THandle): string;
var
Buffer: array[0..255] of Char;
begin
SetString(Result, Buffer, GetWindowText(HWND, Buffer, Length(Buffer)));
end;
function GetWindowClassName(HWND: THandle): string;
var
Buffer: array[0..255] of Char;
begin
SetString(Result, Buffer, GetClassName(HWND, Buffer, Length(Buffer)));
end;
procedure wm_sendstringex(sender: HWND; target: hwnd; strtosend: string);
var
copyDataStruct: TCopyDataStruct;
begin
if not iswindow(sender) then begin
outputdebugstring(pchar('sendstring: sender hwnd is invalid'));
exit;
end;
if not iswindow(target) then begin
outputdebugstring(pchar('sendstring: target hwnd is invalid'));
exit;
end;
outputdebugstring(pchar(GetWindowClassName(target)));
outputdebugstring(pchar(GetWindowTitle(target)));
outputdebugstring(pchar(strtosend));
CopyDataStruct.dwData := sender;
CopyDataStruct.cbData := (Length(strtosend) + 1) * SizeOf(Char);
CopyDataStruct.lpData := PChar(strtosend);
SendMessage(target, WM_COPYDATA, sender, LPARAM(@CopyDataStruct));
end;
end.