当他遇上她时
//Delphi 中
library MyModule;
uses
Windows, Messages, SysUtils;
type
DGFor3 = record
x: Longint;
y: Longint;
mdc: Longint;
end;
function MouseDC(): DGFor3; stdcall;
var
Cur: TPoint;
begin
GetCursorPos(Cur);
Result.mdc := WindowFromPoint(Cur);
Result.x := Cur.x;
Result.y := Cur.y;
end;
function GetTxt(hWnd:longint):PChar;stdcall;
var
nName:PChar;
Si:integer;
begin
Si:=GetWindowTextLength(hWnd)+1;
GetMem(nName,Si);
GetWindowText(hWnd,nName,Si);
result:=nName;
FreeMem(nName,0);
end;
exports
GetTxt;
begin
end.
'VB中
Private Declare Function MouseDC Lib "D:\Mian\Delphi\MyModule\MyModule.dll" () As DGFor3
Private Declare Function GetTxt Lib "D:\Mian\Delphi\MyModule\MyModule.dll" (ByVal hWnd As Long) As String
Private Sub Timer1_Timer()
text1.Text = GetTxt(MouseDC.MDC)
End Sub
type DGFor3
x as long
y as long
mdc as long
end type
以上代码遇到个别变动标题的窗体的时候会错误。