高手,救命!想在局域网上模拟冰河,要截获其它Windows窗口,出现问题,请伸出援手,十万火急,送分,谢谢!(100分)

  • 主题发起人 主题发起人 章慧
  • 开始时间 开始时间

章慧

Unregistered / Unconfirmed
GUEST, unregistred user!
1。 如何 一用这程序就错
Var
h:hWnd;
Begin
h:=FindWindow('TForm1','Form1');
到这儿就错了,气死我了!

2。如何截获所有窗口其名字和Handle
3。我试着用CreateToolHelp32Snapshot;
为何只有第一遍有效?
加了CloseHandle也不行 !
这样岂不是有新程序进入不能发现,旧程序退出也不能发现?
更奇怪的是一旦挂上“地球村Earth Village字典”就可以使用多次?
高手,快救命!
 
是什么出错信息?
 
invaild pointer conversion
 
1.我用D4没有错误。
 
试一下:
Var
h:handle;
或var h:integer;
 
在计算机世界网站上有截取远程屏幕的代码,这是我改写的 :
unit SvrUnit;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, NMUDP;

type
TServer = class(TForm)
Image1: TImage;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
Edit1: TEdit;
Edit2: TEdit;
SUDP: TNMUDP;
BitBtn2: TBitBtn;
procedure ServerCreate(Sender: TObject);
procedure ServerDestroy(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure SUDPDataReceived(Sender: TComponent; NumberBytes: Integer;
FromIP: String; Port: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Server: TServer;

implementation

const
BufSize=2048;

var
RsltStream,TmpStream:TMemoryStream;

{$R *.DFM}

procedure TServer.ServerCreate(Sender: TObject);
begin
RsltStream:=TMemoryStream.Create;
TmpStream:=TMemoryStream.Create;
end;

procedure TServer.ServerDestroy(Sender: TObject);
begin
RsltStream.Free;
TmpStream.Free;
end;

procedure TServer.BitBtn1Click(Sender: TObject);
var
ReqCode:array[0..29] of char;
ReqCodeStr:string;
begin
ReqCodeStr:='show'+Edit1.Text;
StrpCopy(ReqCode,ReqCodeStr);
TmpStream.Clear;
RsltStream.Clear;
SUDP.RemoteHost:=Edit2.Text;
SUDP.SendBuffer(ReqCode,30);
end;

procedure TServer.SUDPDataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
ReqCode:array[0..29] of char;ReqCodeStr:string;
begin
ReqCodeStr:='show'+Edit1.text;
StrpCopy(ReqCode,ReqCodeStr);
SUDP.ReadStream(TmpStream);
RsltStream.CopyFrom(TmpStream,NumberBytes);
if NumberBytes< BufSize then { 数据已读完 }
begin
RsltStream.Position:=0;
Image1.Picture.Bitmap.LoadFromStream(RsltStream);
TmpStream.Clear;
RsltStream.Clear;
end else
begin
TmpStream.Clear;ReqCode:='show';
SUDP.RemoteHost:=Edit2.Text;
SUDP.SendBuffer(ReqCode,30);
end;
end;

end.
 
h:=FindWindow('TForm1',nil);
 
2.这是我的程序的一部分, 用于找出系统中所有正在运行的进程
procedure TForm1.updateitClick(Sender: TObject);
type
TProcessInfo = Record
ExeFile : String;
ProcessID : DWORD;
end;
pProcessInfo = ^TProcessInfo;
var
p:pProcessInfo;
ContinueLoop:BOOL;
FSnapshotHandle:THandle;
FProcessEntry32:TProcessEntry32;
begin
listbox1.Clear;
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);
while integer(ContinueLoop)<>0 do
begin
New(p);
p.ExeFile := FProcessEntry32.szExeFile;
p.ProcessID := FProcessEntry32.th32ProcessID;
listbox1.Items.Add(p.ExeFile+' -> '+inttostr(p.ProcessID));
ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);
end;
end;
 
获得所有窗口的标题和句柄
procedure TForm1.Button1Click(Sender: TObject);
var
hCurrentWindow:HWnd;
szText:array[0..254]of char;
begin
hCurrentWindow:=GetWindow(Handle,GW_HWNDFIRST);
While hCurrentWindow<>0 Do
Begin
If GetWindowText(hCurrentWindow,@szText,255)>0 then
ListBox1.Items.Add(Strpas(@szText));
hCurrentWindow:=GetWindow(hCurrentWindow,GW_HWNDNEXT);
end;
end;
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
I
回复
0
查看
785
import
I
后退
顶部