我现在的CODE procedure TForm1.Timer1Timer(Sender: TObject); //3秒定时 var hCurrentWindow: LongWord; szText: array[0..254] of char; begin memo1.Clear; hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST); while hCurrentWindow <> 0 do begin //edit1.text是我旺旺的id,旺旺的窗口标题通常 交谈的旺旺id - 我的旺旺id if GetWindowText(hCurrentWindow, @szText, 255)>0 then if AnsiEndsStr(Edit1.Text, StrPas(@szText)) and checkbox1.Checked then begin Memo1.Lines.Add(StrPas(@szText)); //显示交谈的旺旺id - 我的旺旺id WinExec('led.exe on 0 4',SW_HIDE); //usb设备上led0 打开4秒,它大于3秒,因此会常亮。 end; hCurrentWindow:=GetWindow(hCurrentWindow, GW_HWNDNEXT); end; end;这个code目前可以工作,我担心用AnsiEndsStr会导致误报。我单片机软硬件还好,delphi就差好多了。我通过了解发现旺旺和旺旺打开的进程id都是一样而且是唯一的。因此我想从进程id入手,先找到旺旺进程id然后找和旺旺进程id相同的窗口这样比较妥帖。不晓得说的对不对,请大家给意见。看看需要什么函数。谢谢
ShellMessageHook 我没有看到这个函数,麻烦问一下做什么用的。 再次谢谢回帖的同志。
procedure TForm1.Timer1Timer(Sender: TObject); var ProcessName: string; //进程名 ProcessID: integer; //进程表示符 i: integer; ContinueLoop: BOOL; FSnapshotHandle: THandle; //进程快照句柄 FProcessEntry32: TProcessEntry32; //进程入口的结构体信息 begin Listbox1.Items.Clear; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //创建一个进程快照 FProcessEntry32.dwSize := Sizeof(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); //得到系统中第一个进程 //循环例举 while ContinueLoop do begin ProcessName := FProcessEntry32.szExeFile; ProcessID := FProcessEntry32.th32ProcessID; //edit2.text 路径 edit1.text 文件名 if AnsiEndsStr(Edit2.Text,ProcessName ) and AnsiEndsStr(Edit1.Text,GetProcessPath(ProcessID)) then Listbox1.Items.add('应用程序名:' + ProcessName + '#进程ID:' + inttostr(ProcessID) + '路径:' + GetProcessPath(ProcessID)); ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; end; 现在可以找到旺旺的进程id啦,可是怎样从进程id 到 所有窗口的标题呢?
procedure TForm1.Timer1Timer(Sender: TObject); //3秒定时
var
hCurrentWindow: LongWord;
szText: array[0..254] of char;
begin
memo1.Clear;
hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin //edit1.text是我旺旺的id,旺旺的窗口标题通常 交谈的旺旺id - 我的旺旺id
if GetWindowText(hCurrentWindow, @szText, 255)>0 then
if AnsiEndsStr(Edit1.Text, StrPas(@szText)) and checkbox1.Checked then
begin
Memo1.Lines.Add(StrPas(@szText)); //显示交谈的旺旺id - 我的旺旺id
WinExec('led.exe on 0 4',SW_HIDE); //usb设备上led0 打开4秒,它大于3秒,因此会常亮。
end;
hCurrentWindow:=GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
end;这个code目前可以工作,我担心用AnsiEndsStr会导致误报。我单片机软硬件还好,delphi就差好多了。我通过了解发现旺旺和旺旺打开的进程id都是一样而且是唯一的。因此我想从进程id入手,先找到旺旺进程id然后找和旺旺进程id相同的窗口这样比较妥帖。不晓得说的对不对,请大家给意见。看看需要什么函数。谢谢
再次谢谢回帖的同志。
var
ProcessName: string; //进程名
ProcessID: integer; //进程表示符
i: integer;
ContinueLoop: BOOL;
FSnapshotHandle: THandle; //进程快照句柄
FProcessEntry32: TProcessEntry32; //进程入口的结构体信息
begin
Listbox1.Items.Clear;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //创建一个进程快照
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); //得到系统中第一个进程
//循环例举
while ContinueLoop do
begin
ProcessName := FProcessEntry32.szExeFile;
ProcessID := FProcessEntry32.th32ProcessID; //edit2.text 路径 edit1.text 文件名
if AnsiEndsStr(Edit2.Text,ProcessName ) and AnsiEndsStr(Edit1.Text,GetProcessPath(ProcessID)) then
Listbox1.Items.add('应用程序名:' + ProcessName + '#进程ID:' + inttostr(ProcessID) + '路径:' + GetProcessPath(ProcessID));
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
end;
现在可以找到旺旺的进程id啦,可是怎样从进程id 到 所有窗口的标题呢?