上面两位说的很正确,你可以利用showwindow这个函数来对其他窗口进行操作。不过如果你想
在玩游戏时你想操作自如的话,你就必须在系统里注册一个快捷键。
我的方法是利用hook来在系统中放一个全局的钩子,然后他就可以监视你的热键啦。当你在玩游戏时
看到老板来的时候,你在键盘上按ctrl+h就隐藏目标,ctrl+s就显示目标,很方便的。
钩子的代码如下: hook.dll
library hook;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Windows,
messages,
Classes;
{$R *.RES}
const
KeyPressMask=0x80000000; //键盘掩码常量
CM_MYMessage = WM_USER + $1000;
var
HookKeyBoard: HHook;
MyHandle,FileM: THandle;
PReceptor: ^Integer;
Hidefile:string;
//读取文件信息
function GetTextFromFile(AFile : String; var ReturnString : string) : boolean;
var
FileStream : TFileStream;
begin
result := false;
if not fileexists(AFile) then exit;
FileStream := TFileStream.Create(AFile,fmOpenRead);
try
if FileStream.Size > 0 then
begin
SetLength(ReturnString,FileStream.Size);
FileStream.Read(ReturnString[1],FileStream.Size);
result := true;
end;
finally
FileStream.Free;
end;
end;
function CallBackKeyHook(Code: Integer; msg: WPARAM; keyhook: LPARAM): LRESULT;stdcall;
var
HHandle:Thandle;
i:integer;
begin
Result := 0;
If Code < 0 Then
begin
result:=callnexthookex(hookkeyboard,code,msg,keyhook);
Exit;
end;
if ((keyhook) and (KeyPressMask) = 0) and(GetKeyState(vk_Control) < 0) and (msg= Ord('H')) then
begin
Result := 1;
Hhandle:=findwindow(nil,pchar(Hidefile));
showwindow(HHandle,SW_hide);
end;
if ((keyhook) and (KeyPressMask) = 0) and(GetKeyState(vk_Control) < 0) and (msg= Ord('S')) then
begin
Result := 1;
Hhandle:=findwindow(nil,Pchar(Hidefile));
showwindow(HHandle,SW_Normal);
end;
end;
procedure HookOff; stdcall;
begin
UnHookWindowsHookEx(HookKeyBoard);
end;
procedure HookOn; stdcall;
var
str,filename:string;
position:integer;
begin
filename:=getcurrentdir+'HideExe.ini';
if GetTextFromFile(filename,Str) then
Hidefile:=trim(str);
HookKeyBoard := SetWindowsHookEx(WH_KEYBOARD, @CallBackKeyHook, HInstance, 0);
end;
exports
HookOn, HookOff;
begin
end.
你可以在上面稍加扩充就可以做成一个非常棒的东东啦,至于调用这个hook.dll的函数不要我
说了吧。
你做一个exe文件,在设一下Application.ShowMainForm:=false;在create事件中加入调用hook.dll
中的hookon函数就可以啦。
很easy吧/俺玩星际就用这东西:)不要对俺领导说哦/