| 发表于:2008-01-10 14:57:024楼 得分:0 |
我把之前的方式改成了在dll通过消息来控制form,但是现在问题也出来了,当不聚焦于mainform那个窗体的时候, form.show是失效的,应该是传进去的handle有莫名其妙的东西,应该怎么办? 我作了如下修改: **** dll **** - delphi(pascal) code
unit qqtitlehook;
interface
uses
windows, messages, sysutils, variants, classes, graphics, controls, forms,
dialogs, stdctrls, commctrl, strutils;
const
my_move=wm_user+100;
my_show=wm_user+101;
my_hide=wm_user+102;
var
hkqqchat: hhook;
hwqqchat: hwnd ;
kid: integer;
hwqqchatchild: hwnd;
hwqqchatchildnext: hwnd;
tlqqchat: string;
clsname: string;
hglobal: thandle;
msgboxglobal: thandle;
msgsendbuttonglobal: thandle;
ptext,pglobal: pchar;
pptext: array [0..255] of char;
buf: array [0..1024] of char;
oldproc:pointer;
mhandle,keyhandle:integer;
form1handle: thandle;
const
csqq = '#32770';
function showmsgproc(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;export;
function showmsgf8proc(icode,wparam,lparam:integer):lresult;stdcall;export;
function enablewheelhook(f: thandle) : boolean; stdcall; export;
function disablewheelhook: boolean; stdcall; export;
implementation
function showmsgproc(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;export;
begin
sendmessage(form1handle,my_move,mouse.cursorpos.x,mouse.cursorpos.y);
result := callnexthookex(mhandle,icode,wparam,lparam);
end;
function showmsgf8proc(icode,wparam,lparam:integer):lresult;stdcall;export;
const
_keypressmask=$80000000;
begin
if ((lparam and _keypressmask) = 0) and (wparam = vk_f5) then
begin
sendmessage(form1handle,my_show,0,0);
result:=1;
exit;
end;
if ((lparam and _keypressmask) = 0) and (wparam = vk_f6) then
begin
sendmessage(form1handle,my_hide,0,0);
result:=1;
exit;
end;
result:= callnexthookex(keyhandle, icode, wparam, lparam);
end;
function enablewheelhook(f: thandle): boolean; stdcall; export;
begin
if hkqqchat=0 then
begin
form1handle := f;
keyhandle := setwindowshookex(wh_keyboard,@showmsgf8proc, hinstance,0);
mhandle := setwindowshookex(wh_journalrecord,@showmsgproc, hinstance ,0);
result := true;
end
else
result := false;
end;
function disablewheelhook: boolean; stdcall; export;
begin
if mhandle <>0 then
begin
unhookwindowshookex(mhandle);
mhandle := 0;
end;
if keyhandle<>0 then
begin
unhookwindowshookex(keyhandle);
keyhandle := 0;
end;
result := true;
end;
end.
*** 调用一方 *** - delphi(pascal) code
unit unit1;
interface
uses
windows, messages, sysutils, variants, classes, graphics, controls, forms,
dialogs, stdctrls ,ui;
type
tformmain = class(tform)
button1: tbutton;
button2: tbutton;
procedure button1click(sender: tobject);
procedure button2click(sender: tobject);
private
{ private declarations }
public
{ public declarations }
end;
var
formmain: tformmain;
function enablewheelhook(f: thandle):boolean; stdcall; external 'hookprj.dll' name 'enablewheelhook';
function disablewheelhook:boolean; stdcall; external 'hookprj.dll' name 'disablewheelhook';
implementation
{$r *.dfm}
procedure tformmain.button1click(sender: tobject);
begin
if enablewheelhook(form1.handle) then
begin
showmessage('启动钩子成功');
end;
end;
procedure tformmain.button2click(sender: tobject);
begin
disablewheelhook;
form1.close;
end;
end.
**** tform1 类 ***** - delphi(pascal) code
unit ui;
interface
uses
windows, messages, sysutils, variants, classes, graphics, controls, forms,
dialogs, stdctrls, menus, comctrls;
const
my_move=wm_user+100;
my_show=wm_user+101;
my_hide=wm_user+102;
type
tform1 = class(tform)
label1: tlabel;
procedure oncreate(sender: tobject);
private
{ private declarations }
procedure mymessagemove(var msg:tmessage);message my_move;
procedure mymessageshow(var msg:tmessage);message my_show;
procedure mymessagehide(var msg:tmessage);message my_hide;
public
{ public declarations }
end;
var
form1: tform1;
implementation
{$r *.dfm}
//自写函数
procedure tform1.oncreate(sender: tobject);
begin
label1.autosize := true;
form1.alphablend := true;
form1.alphablendvalue := 150;
form1.borderstyle := bsnone;
form1.width := label1.width + 20;
form1.height := label1.height + 10;
end;
procedure tform1.mymessagemove(var msg:tmessage);
begin
form1.left := msg.wparam+ 10;
form1.top:= msg.lparam - form1.height;
end;
procedure tform1.mymessageshow(var msg:tmessage);
begin
form1.show;
form1.formstyle := fsstayontop;
end;
procedure tform1.mymessagehide(var msg:tmessage);
begin
form1.hide;
end;
end.
| | |
|