有这么一个问题,大家帮忙想想主意!(300分)

  • 主题发起人 主题发起人 Blabber
  • 开始时间 开始时间
angelgekk继续你的程序啊,我今天没时间看了.明天好好学习一下,有问题再问你.谢谢
 
h:=FindWindow('窗体类名','窗体Caption'); &nbsp;//例 FindWindow('TForm1','Form1');<br>ch:=FindWindowEx(h,0,'控件类名','控件Text'); //例 FindWindowEx(h,0,'TButton','Button1');<br>ClickWindow(ch); //点击找到按钮的句柄<br><br>procedure ClickWindow(hwnd: HWND; X: Integer = 0; Y: Integer = 0);<br>begin<br>&nbsp; if IsWindow(hWnd) then<br>&nbsp; begin<br>&nbsp; &nbsp; SendMessage(hwnd,WM_LBUTTONDOWN,MK_LBUTTON,Y shl 16 or X);<br>&nbsp; &nbsp; SendMessage(hwnd,WM_LBUTTONUP,MK_LBUTTON,Y shl 16 or X);<br>&nbsp; end;<br>end;<br>
 
如果用FindWindowEx不能找到合适的Handle,那么可以用EnumChildWindows枚举所有窗体上控件的Handle,例:<br>var<br>&nbsp; Step: Integer = 0;<br><br>function EnumChildProc(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;<br>begin<br>&nbsp; Result:=True;<br><br>&nbsp; Inc(Step);<br>&nbsp; case Step of<br>&nbsp; &nbsp; 3: &nbsp;SetWindowText(hwnd,'要赋的值'); //比如窗体上第三个为文本框T1<br>&nbsp; &nbsp; 5: &nbsp;SendString(hwnd,'要赋的值'); //比如窗体上第五个为文本框T2,有些程序没办法用SetWindowText改变文本框的值,那么可以用模拟按键的方法给其赋值,具体代码在下面<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; Step:=0;<br>&nbsp; EnumChildWindows(找到的窗体句柄,@EnumChildProc,0);<br>end;<br><br>procedure SendShift(hwnd: HWND; Down: Boolean);<br>var<br>&nbsp; vKey,ScanCode,wParam: Word;<br>&nbsp; lParam: LongInt;<br>begin<br>&nbsp; vKey:=$10;<br><br>&nbsp; ScanCode:=MapVirtualKey(vKey,0);<br>&nbsp; wParam:=vKey or ScanCode shl 8;<br>&nbsp; lParam:=LongInt(ScanCode) shl 16 or 1;<br><br>&nbsp; if not Down then<br>&nbsp; &nbsp; lParam:=lParam or LongInt($C0000000);<br>&nbsp; SendMessage(hwnd,WM_KEYDOWN,wParam,lParam);<br>end;<br><br>procedure SendCtrl(hwnd: HWND; Down: Boolean);<br>var<br>&nbsp; vKey,ScanCode,wParam: Word;<br>&nbsp; lParam: LongInt;<br>begin<br>&nbsp; vKey:= $11;<br><br>&nbsp; ScanCode:=MapVirtualKey(vKey,0);<br>&nbsp; wParam:=vKey or ScanCode shl 8;<br>&nbsp; lParam:=LongInt(ScanCode) shl 16 or 1;<br><br>&nbsp; if not Down then<br>&nbsp; &nbsp; lParam:=lParam or LongInt($C0000000);<br>&nbsp; SendMessage(hwnd,WM_KEYDOWN,wParam,lParam);<br>end;<br><br>procedure SendKey(hwnd: HWND; Key: Char);<br>var<br>&nbsp; vKey,ScanCode,wParam: Word;<br>&nbsp; lParam,ConvKey: LongInt;<br>&nbsp; Shift,Ctrl: Boolean;<br>begin<br>&nbsp; ConvKey:=OemKeyScan(Ord(Key));<br>&nbsp; Shift:=(ConvKey and $00020000)&lt;&gt;0;<br>&nbsp; Ctrl:=(ConvKey and $00040000)&lt;&gt;0;<br>&nbsp; ScanCode:=ConvKey and $000000FF or $FF00;<br>&nbsp; vKey:=Ord(Key);<br>&nbsp; wParam:=vKey;<br>&nbsp; lParam:=LongInt(ScanCode) shl 16 or 1;<br><br>&nbsp; if Shift then<br>&nbsp; &nbsp; SendShift(hwnd,True);<br>&nbsp; if Ctrl then<br>&nbsp; &nbsp; SendCtrl(hwnd,True);<br><br>&nbsp; SendMessage(hwnd,WM_KEYDOWN,wParam,lParam);<br>&nbsp; SendMessage(hwnd,WM_CHAR,wParam,lParam);<br><br>&nbsp; lParam:=lParam or LongInt($C0000000);<br>&nbsp; SendMessage(hwnd,WM_KEYUP,wParam,lParam);<br><br>&nbsp; if Shift then<br>&nbsp; &nbsp; SendShift(hwnd,False);<br>&nbsp; if Ctrl then<br>&nbsp; &nbsp; SendCtrl(hwnd,False);<br>end;<br><br>procedure SendString(hwnd: HWND; Str: String);<br>var<br>&nbsp; i: Integer;<br>begin<br>&nbsp; for i:=1 to Length(Str) do<br>&nbsp; &nbsp; SendKey(hwnd,Str);<br>end;<br><br><br>相信以上几步后满足你的要求是没问题的了
 
谢谢,我会尽快学习你的方案.
 
TO:pihome<br>谢谢你,真有种大侠风范~~~~~~~~
 
学习学习,顺便收藏!<br>其实找控件句柄一般也就是FindWindow,FindWindowEx,EnumWindows,EnumChildWindows<br>给你个用EnumChildWindows枚举窗体控件的例子:<br><br>unit Unit3;<br><br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>&nbsp; function EnumChildWndProc(AhWnd:HWnd; AlParam:lParam):boolean;stdcall;<br><br>implementation<br><br>{$R *.dfm}<br><br>function EnumChildWndProc(AhWnd:HWnd; AlParam:lParam):boolean;stdcall;<br>var<br>&nbsp; WndClassName: array[0..254] of Char;<br>&nbsp; str: string;<br>begin<br>&nbsp; GetClassName(AhWnd, wndClassName, 254);<br>&nbsp; with Form1.Memo1 do<br>&nbsp; begin<br>&nbsp; &nbsp; Lines.add('ClassName: ' + string(wndClassName));<br>&nbsp; &nbsp; Lines.add('Handle: ' + IntToStr(AhWnd));<br>&nbsp; end;<br>&nbsp; result:=true;<br>end;<br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; hWnd:LongInt;<br>begin<br>&nbsp; memo1.Lines.Clear;<br>&nbsp; hWnd := FindWindow(nil, PChar(Edit1.Text));<br>&nbsp; if hWnd &lt;&gt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; EnumChildWindows(hWnd, @EnumChildWndProc, 0);<br>&nbsp; end;<br>end;<br>end.<br><br>其实如果知道控件text的话,用<br>h:=FindWindow('窗体类名','窗体Caption'); &nbsp;//例 FindWindow('TForm1','Form1');<br>ch:=FindWindowEx(h,0,'控件类名','控件Text'); //例 FindWindowEx(h,0,'TButton','Button1');<br>也就得了!
 
用勾子去勾它
 
他们说的方法你试过了么??
 
简单的问题弄得这么复杂,你现在搞定了吗?
 
&nbsp;收藏,好东西要与朋友共享的!!!
 

Similar threads

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