怎么没人回答阿,简单的问题啊。。。(50分)

  • 主题发起人 主题发起人 hazf2008
  • 开始时间 开始时间
H

hazf2008

Unregistered / Unconfirmed
GUEST, unregistred user!
如何从进程名知道窗体句柄和进程ID啊 ?<br>比如获得QQ宠物的句柄。。。<br><br>谢谢各位。。。
 
怎么没人回答阿,简单的问题啊。。。
 
var Wnd: HWND; <br> &nbsp; &nbsp; &nbsp; Wnd := FindWindow(nil, 窗体Caption标题);
 
hw: HWND;<br> &nbsp;pid: dword;<br> &nbsp;h: THandle;<br> &nbsp;tt: Cardinal;<br>begin &nbsp;<br>hw:=FindWindow(nil,'进程名或窗口名'); &nbsp; &nbsp;///<br> &nbsp; &nbsp;if hw = 0 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// &nbsp; &nbsp; &nbsp; 获得句柄ID<br> &nbsp; &nbsp; &nbsp;Exit; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;///<br> &nbsp; &nbsp;GetWindowThreadProcessId(hw, @pid); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;///<br> &nbsp; &nbsp;h := OpenProcess(PROCESS_ALL_ACCESS, false, pid); &nbsp; &nbsp;///<br> &nbsp; &nbsp;if h = 0 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;///打开句柄<br> &nbsp; &nbsp; &nbsp;Exit;<br>end;<br><br><br>我只知道这么点,希望可以帮到你,另外我的ID不能提问,要二天后,借你的地盘问个问题,<br>不好意思!~<br>我要做一个(热血江湖)会加自动加血加蓝的外挂,<br>具体代码如下:<br>unit Mainf;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, ComCtrls,StdCtrls, ExtCtrls;<br><br>type<br> &nbsp;TMainForm = class(TForm)<br> &nbsp; &nbsp;TimerSM: TTimer;<br> &nbsp; &nbsp;TimerNG: TTimer;<br> &nbsp; &nbsp;TimerJN: TTimer;<br> &nbsp; &nbsp;CheckBoxSM: TCheckBox;<br> &nbsp; &nbsp;CheckBoxNG: TCheckBox;<br> &nbsp; &nbsp;EditSM: TEdit;<br> &nbsp; &nbsp;EditNG: TEdit;<br> &nbsp; &nbsp;CheckBoxJN: TCheckBox;<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp;Label1:TLabel;<br> &nbsp; &nbsp;procedure CheckBoxSMClick(Sender: TObject);<br> &nbsp; &nbsp;procedure TimerSMTimer(Sender: TObject);<br> &nbsp; &nbsp;procedure Button2Click(Sender: TObject);<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure CheckBoxNGClick(Sender: TObject);<br> &nbsp; &nbsp;procedure TimerNGTimer(Sender: TObject);<br> &nbsp; &nbsp;procedure CheckBoxJNClick(Sender: TObject);<br> &nbsp; &nbsp;procedure TimerJNTimer(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br>const<br> &nbsp;SHENGMING: dword = $01453318; //红<br> &nbsp;NEIGONG: dword = $0145331C; // 蓝<br><br>var<br> &nbsp;MainForm: TMainForm;<br><br> &nbsp;hw: HWND;<br> &nbsp;pid: dword;//游戏句柄ID<br> &nbsp;h: THandle;//游戏句柄<br> &nbsp;tt: Cardinal;<br> &nbsp;procedure KeyF2;//按键<br> &nbsp;procedure KeyF3;<br> &nbsp;procedure KeyF4;<br><br>implementation<br><br>{$R *.dfm}<br>procedure TMainForm.Button1Click(Sender: TObject);<br>begin<br> &nbsp;if &nbsp;h = 0 then //如果句柄没打开<br> &nbsp; begin<br> &nbsp; &nbsp;hw:=FindWindow(nil,'YB_OnlineClient'); &nbsp; &nbsp;///<br> &nbsp; &nbsp;if hw = 0 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/// &nbsp; &nbsp; &nbsp; 获得句柄ID<br> &nbsp; &nbsp; &nbsp;Exit; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;///<br> &nbsp; &nbsp;GetWindowThreadProcessId(hw, @pid); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;///<br> &nbsp; &nbsp;h := OpenProcess(PROCESS_ALL_ACCESS, false, pid); &nbsp; &nbsp;///<br> &nbsp; &nbsp;if h = 0 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;///打开句柄<br> &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;///<br> &nbsp; end;<br> &nbsp;TimerNG.Interval := 1000 div trunc(5);<br> &nbsp;TimerSM.Interval := 1000 div trunc(5);<br> &nbsp;TimerJN.Interval := 1000 div trunc(2);///每秒钟运行次数<br>end;<br>procedure TMainForm.CheckBoxSMClick(Sender: TObject);<br>begin<br> &nbsp; if CheckBoxSM.Checked then &nbsp;//控制Timer是否运行<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; EditSM.Enabled := false;<br> &nbsp; &nbsp; TimerSM.Enabled := true;<br> &nbsp; &nbsp;end<br> &nbsp; else<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; EditSM.Enabled := true;<br> &nbsp; &nbsp; TimerSM.Enabled := false;<br> &nbsp;end;<br>end;<br><br>procedure TMainForm.TimerSMTimer(Sender: TObject);<br>var<br> &nbsp;Sm: integer;<br> // tt: DWORD;<br>begin<br> &nbsp;ReadProcessMemory(h,pointer( SHENGMING), @Sm,sizeof(Sm), tt);<br>//扫描内存数据<br> &nbsp;<br> &nbsp;if ((Sm &lt;= StrToInt(EditSM.Text))and(Sm&lt;&gt;0)) and (h&lt;&gt;0) then<br>//如果血量值少于设定值并且不等于0<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp;KeyF3;<br> &nbsp; &nbsp; //按F3键<br> &nbsp; &nbsp; Label1.Caption :='F3运行中';<br> &nbsp; &nbsp; end;<br><br>end;<br><br>procedure KeyF2;<br>begin<br> &nbsp; keybd_event(VK_F2,mapvirtualkey(VK_F2,0),0,0);<br> &nbsp; keybd_event(VK_F2,mapvirtualkey(VK_F2,0),keyeventf_keyup,0);//按F2键<br>end;<br>procedure KeyF3;<br>begin<br> &nbsp; keybd_event(VK_F3,mapvirtualkey(VK_F3,0),0,0);<br> &nbsp; keybd_event(VK_F3,mapvirtualkey(VK_F3,0),keyeventf_keyup,0);//按F3键<br>end;<br>procedure KeyF4;<br>begin<br> &nbsp; keybd_event(VK_F4,mapvirtualkey(VK_F4,0),0,0);<br> &nbsp; keybd_event(VK_F4,mapvirtualkey(VK_F4,0),keyeventf_keyup,0);//按F4键<br>end;<br>procedure TMainForm.Button2Click(Sender: TObject);<br>begin<br> &nbsp;if h &lt;&gt; 0 then<br> &nbsp; begin<br> &nbsp; &nbsp;MessageBeep(0);<br> &nbsp; &nbsp;CloseHandle(h);<br> &nbsp; end;<br> &nbsp; close;<br>end;<br>end.<br><br>没有进游戏时,Label没有反应,<br>进入游戏了,按下按钮,当血量少于设定值时Label改变,说明Timer在运行,<br>可是游戏里不会自动加血,于是我改变了一下按键,把F3改成了F4,<br>游戏里还是没有反应,但我切到外挂窗口,按一下Alt键,外挂窗口关闭,<br>由此证明模拟键盘F4键一直进行中<br>后来我又换了一个模拟键盘的方法,<br>改变如下:<br>procedure KeyF3;<br>begin<br> &nbsp; PostMessage(Application.Handle, WM_KEYDOWN, VK_F4, 0);<br> &nbsp; PostMessage(Application.Handle, WM_KEYUP, VK_F4, 0);<br>end;<br>和<br>procedure KeyF3;<br>begin<br> &nbsp; PostMessage(h, WM_KEYDOWN, VK_F4, 0);<br> &nbsp; PostMessage(h, WM_KEYUP, VK_F4, 0);<br>end;<br>在游戏里还是没有反应,并且外挂窗口也没有反应了,但是Label标签改变<br>由是我再改成<br>procedure KeyF3;<br>begin<br> &nbsp; PostMessage(h, WM_KEYDOWN, VK_F4, 0);<br> &nbsp; PostMessage(h, WM_KEYUP, VK_F4, 0);<br> &nbsp; setcursorpos(500,400);<br> &nbsp; mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);<br> &nbsp; mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);<br>end;<br>这时鼠标在游戏里点击正常,键盘没有反应<br><br>在此麻烦大侠帮下忙,找下问题所在,<br>或再给几个模拟键盘的方法<br>非常感谢!!!!!
 

Similar threads

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