wealsh 2004年12月24日
能修一下这段代码吗?
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
hwndmu: HWND;
hhook1: HHOOK;
hinstance: LongWord;
bs: Boolean = false;
oldproc: FARPROC;
function HookProc(nCode: Integer; wParam: WPARAM ; lParam: LPARAM): LRESULT; stdcall;
function WINPROC(hwnd: HWND ;umsg: TMessage; wparam: WPARAM ;lparam: LPARAM): LRESULT; stdcall;
function winmu(): Boolean; stdcall;

implementation

{$R *.dfm} // unsigned long reason, void* lpReserved

function DllEntryPoint(hinst: LongWord): integer;
begin
hinstance := hinst ;
result := 1;
end;

//安装WH_GETMESSAGE钩子到指定的线程中
function SetHook(hwindow: HWND): Boolean;Stdcall;
var
thid: DWORD;
begin
//if(hhook == NULL) 获取前端窗口句炳,当然也可以用FindWindow(NULL,"MU")
//来替代
thid := GetWindowThreadProcessId(hwindow,nil);
hhook1 := SetWindowsHookEx(WH_GETMESSAGE,HookProc,hinstance,thid);
if hhook1 = NULL then
begin
ShowMessage('Set Hook fails');
result := false;
end
else
result := true;
end;

//卸载钩子
function RemoveHook():Boolean;Stdcall;
begin
if hhook1 = NULL then
begin
ShowMessage('Hook Removed');
result := false;
end
else
begin
UnhookWindowsHookEx(hhook1);
result := true;
end;
end;

//钩子回调函数
function HookProc(nCode: Integer; wParam: WPARAM ; lParam: LPARAM): LRESULT;
begin
if ncode < 0 then
result := CallNextHookEx(hhook1,ncode,wparam,lparam);
//用一个bool变量让我们的winmu()只调用一次
if bs <> winmu() then
begin
bs := true;
result := CallNextHookEx(hhook1,ncode,wparam,lparam);
end;
end;

function winmu(): Boolean; stdcall;
var
style,exstyle: DWORD;
devmode: TDeviceMode;
begin
hwndmu := GetForegroundWindow();
if EnumDisplaySettings(nil, 0, devmode) then
begin
devmode.dmPelsWidth := 1024;
devmode.dmPelsHeight := 768;
devmode.dmBitsPerPel := 32;
devmode.dmDisplayFrequency := 75;
ChangeDisplaySettings(devmode,0);
end;
//修改窗体的style属性
style := GetWindowLong(hwndmu,GWL_STYLE);
style := style or WS_CAPTION ;
SetWindowLong(hwndmu,GWL_STYLE,style);
//修改窗体的exstyle属性exstyle=GetWindowLong(hwndmu,GWL_EXSTYLE);
exstyle := exstyle or WS_EX_APPWINDOW or WS_EX_WINDOWEDGE;
SetWindowLong(hwndmu,GWL_EXSTYLE,exstyle);
//设置窗体的位置,取消其最前端显示,为图简单807,632是我自己随便设的
//当然最好是先用AdjustWindowRect函数调整一下大小
//SetWindowPos(hwndmu,HWND_NOTOPMOST,0,0,807,632,SWP_SHOWWINDOW);
ShowWindow(hwndmu,SW_SHOWNORMAL);
//修改窗体的回调函数地址到我们自己定义的回调函数
//oldproc=(FARPROC)GetWindowLong(hwndmu,GWL_WNDPROC);
if SetWindowLong(hwndmu,GWL_WNDPROC,WINPROC) = 0 then
Result := false
else
Result := True;
end;
end;

//自己定义的回调函数
function WINPROC(hwnd: HWND, umsg :TMessage, WPARAM wparam, LPARAM lparam): LRESULT;
begin
//消息过滤
case umsg.Msg of
WM_ACTIVATEAPP: result := 0;//这里是个关键,
WM_ACTIVATE: result := 0;
WM_KILLFOCUS: result := 0;
WM_SETFOCUS: result := 0;
WM_CLOSE: result := 0;
WM_TIMER:
begin
if wparam = 0x3e9 then
begin
KillTimer(hwnd,wparam); //把这个计时器kill
break;
end;
result := CallWindowProc(oldproc,hwnd,umsg,wparam,lparam);
end;
end;
end;

end.
...全文
39 点赞 收藏 1
写回复
1 条回复

还没有回复,快来抢沙发~

发动态
发帖子
非技术区
创建于2007-08-02

587

社区成员

5.4w+

社区内容

Delphi 非技术区
社区公告
暂无公告