unit Unit1;interfaceuses
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* lpReservedfunction 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.
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* lpReservedfunction 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.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货