如何得到运行程序返回的句柄值
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
H : THandle;
PI : TProcessInformation;
implementation
{$R *.dfm}
type
PEnumInfo = ^TEnumInfo;
TEnumInfo = record
ProcessID : DWORD;
HWND : THandle;
end;
function EnumwindowsProc(Wnd: DWORD; var EI: TEnumInfo): Bool; stdcall;
var
PID : DWORD;
begin
GetWindowThreadProcessID(Wnd, @PID);
Result := (PID <> EI.ProcessID) or(not IsWindowVisible(WND)) or(not IsWindowEnabled(WND));
if not result then EI.HWND := WND;
end;
function FindMainWindow(PID: DWORD): DWORD;
var
EI : TEnumInfo;
begin
EI.ProcessID := PID;
EI.HWND := 0;
Enumwindows(@EnumwindowsProc, Integer(@EI));
Result := EI.HWND;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
SI : TStartupInfo;
S : String;
begin
ZeroMemory(@SI, SizeOf(SI));
ZeroMemory(@PI, SizeOf(PI));
SI.cb := SizeOf(SI);
if CreateProcess(nil,'D:\Program Files\StormII\Storm.exe', nil, nil, False, 0 ,nil,nil, SI, PI) then
begin
//注意!
WaitForInputIdle(PI.hProcess, INFINITE);
//INFINITE
H := FindMainWindow(PI.dwProcessID);
if H>0 then
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//PostThreadMessage(pi.dwThreadId, WM_QUIT, 0,0);
//SendMessage(H, WM_LBUTTONUP, MK_LBUTTON, makelparam(50,50));
SendMessage(H,WM_LBUTTONdown, MK_LBUTTON, makelparam(50,50));
//PostThreadMessage(pi.dwThreadId, WM_QUIT, 0,0);
end;
end.
现在是如何得到H返回的句柄值,如果在H := FindMainWindow(PI.dwProcessID);
设断点可以得到H返回的句柄值,但是不设置断点就得不到,希望能给我解决这个问题,谢谢,分不够,开贴再送
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
H : THandle;
PI : TProcessInformation;
implementation
{$R *.dfm}
type
PEnumInfo = ^TEnumInfo;
TEnumInfo = record
ProcessID : DWORD;
HWND : THandle;
end;
function EnumwindowsProc(Wnd: DWORD; var EI: TEnumInfo): Bool; stdcall;
var
PID : DWORD;
begin
GetWindowThreadProcessID(Wnd, @PID);
Result := (PID <> EI.ProcessID) or(not IsWindowVisible(WND)) or(not IsWindowEnabled(WND));
if not result then EI.HWND := WND;
end;
function FindMainWindow(PID: DWORD): DWORD;
var
EI : TEnumInfo;
begin
EI.ProcessID := PID;
EI.HWND := 0;
Enumwindows(@EnumwindowsProc, Integer(@EI));
Result := EI.HWND;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
SI : TStartupInfo;
S : String;
begin
ZeroMemory(@SI, SizeOf(SI));
ZeroMemory(@PI, SizeOf(PI));
SI.cb := SizeOf(SI);
if CreateProcess(nil,'D:\Program Files\StormII\Storm.exe', nil, nil, False, 0 ,nil,nil, SI, PI) then
begin
//注意!
WaitForInputIdle(PI.hProcess, INFINITE);
//INFINITE
H := FindMainWindow(PI.dwProcessID);
if H>0 then
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//PostThreadMessage(pi.dwThreadId, WM_QUIT, 0,0);
//SendMessage(H, WM_LBUTTONUP, MK_LBUTTON, makelparam(50,50));
SendMessage(H,WM_LBUTTONdown, MK_LBUTTON, makelparam(50,50));
//PostThreadMessage(pi.dwThreadId, WM_QUIT, 0,0);
end;
end.
现在是如何得到H返回的句柄值,如果在H := FindMainWindow(PI.dwProcessID);
设断点可以得到H返回的句柄值,但是不设置断点就得不到,希望能给我解决这个问题,谢谢,分不够,开贴再送
...全文
相关推荐
c#句柄操作大全.zip
c#源码工具能实现对第三方窗体的控件进行点击按钮,获取第三方窗体控件值,设置第三方窗体控件值,对第三方窗体进行按键等一系列操作,代码思路清晰备注明确。欢迎下载修改进行扩展,别忘记好评哟!
VB快速获取程序句柄
快速获取程序句柄,为sendmessage做前期工作,校验所获句柄正确性
易语言查找窗口句柄模块(含源码)
易语言查找窗口句柄模块(含源码),根据窗口标题查找窗口句柄。
根据窗体句柄传值.rar
VB利用windowsapi进行另一程序窗口操作。 如出现无法打开窗口,请先注册mscomct2.ocx
myspy查看句柄工具
世上最全最强悍的句柄查看工具,支持窗体控件句柄查看


Windows SDK/API
