日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Delphi隱藏當(dāng)前進(jìn)程

 intruder 2005-12-12
[Delphi]Delphi隱藏當(dāng)前進(jìn)程     → Kendy 發(fā)表于 2005-7-15 1:18:00
來(lái)源:南域劍盟

主要需要解決兩個(gè)問(wèn)題,即隱藏窗口和設(shè)定熱鍵。
一. 隱藏窗口
  通過(guò)API函數(shù)GETACTIVEWINDOW獲取當(dāng)前窗口;函數(shù)ShowWindow(HWND,nCmdShow)的參數(shù)nCmdShow取SW_HIDE時(shí)將之隱藏,取SW_SHOW時(shí)將之顯示。例如:showwindow(getactivewindow,sw_hide)。隱藏好窗體后,須記住窗體句柄以便恢復(fù)。
二. 鍵盤(pán)監(jiān)控
  為了實(shí)現(xiàn)鍵盤(pán)監(jiān)控須用到鉤子。

以下是程序的源文件:
---HKHide.pas---

unit HKHide;

interface

uses
 Windows, Messages, sysutils;

var
 hNextHookHide: HHook;
 HideSaveExit: Pointer;
 hbefore:longint;

function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;
     lParam: LPARAM): LRESULT; stdcall; export;
function EnableHideHook: BOOL; export;
function DisableHideHook: BOOL; export;
procedure HideHookExit; far;

implementation

function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;
     lParam: LPARAM): LRESULT; stdcall; export;
const _KeyPressMask = $80000000;
var
 f:textfile;
 temp:string;
begin
 Result := 0;
 If iCode < 0 Then
 begin
  Result := CallNextHookEx(hNextHookHide, iCode, wParam, lParam);
  Exit;
 end;
// 偵測(cè) Ctrl + Alt + F12 組合鍵
 if ((lParam and _KeyPressMask) = 0) //按下時(shí)生效
  and (GetKeyState(vk_Control) < 0)
  and (getkeystate(vk_menu)<0) and (wParam = vk_F12) then
 begin
  Result := 1;
  //文件不存在則創(chuàng)建
  if not fileexists(c:\test.txt) then
  begin
   assignfile(f,c:\test.txt);
   rewrite(f);
   writeln(f,0);
   closefile(f);
  end
  else begin
   assignfile(f,c:\test.txt);
   reset(f);
   readln(f,temp);
   hbefore:=strtoint(temp);
   begin
    hbefore:=getactivewindow;
    temp:=inttostr(hbefore);
    rewrite(f);
    writeln(f,temp);
    closefile(f);
    ShowWindow(hbefore, SW_HIDE);
   end
   else begin
    showwindow(hbefore,sw_show);
    rewrite(f);
    writeln(f,0);
    closefile(f);
   end;
  end;
 end;
end;

function EnableHideHook: BOOL; export;
begin
 Result := False;
 if hNextHookHide <> 0 then Exit;
 // 掛上 WH_KEYBOARD 這型的 HOOK, 同時(shí), 傳回值必須保留下
 // 來(lái), 免得 HOOK 呼叫鏈結(jié)斷掉
 hNextHookHide := SetWindowsHookEx(WH_KEYBOARD,
 KeyboardHookHandler,HInstance,0);
 Result := hNextHookHide <> 0;
end;

function DisableHideHook: BOOL; export;
begin
 if hNextHookHide <> 0 then
 begin
  Result:=True;
  UnhookWindowshookEx(hNextHookHide); // 解除 Keyboard Hook
  hNextHookHide:=0;
 end
 else
  Result:=False;
end;

procedure HideHookExit;
begin
 // 如果忘了解除 HOOK, 自動(dòng)代理解除的動(dòng)作
 if hNextHookHide <> 0 then DisableHideHook;
 ExitProc := HideSaveExit;
end;

end.

---HKPHide.dpr---

library HKPHide;

uses
 HKHide in HKHide.pas;

exports
 EnableHideHook,
 DisableHideHook;

begin
 hNextHookHide := 0;
 hbefore:=0;
 HideSaveExit := ExitProc;
 ExitProc := @HideHookExit;
end.

文件制作好后選Build All編譯成HKPHide.dll。

新建一個(gè)工程Project1
---Unit1.pas---

unit Unit1;

interface

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

type
 TForm1 = class(TForm)
  Button1: TButton;
  Button2: TButton;
  procedure Button1Click(Sender: TObject);
  procedure Button2Click(Sender: TObject);
 private
  { Private declarations }
 public
  { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.DFM}

function EnableHideHook: BOOL; external HKPHide.DLL;
function DisableHideHook: BOOL; external HKPHide.DLL;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if EnableHideHook then
 ShowMessage(HotKey Testing...);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 if DisableHideHook then
 ShowMessage(HotKey Testing..., DONE!!);
end;

end.

運(yùn)行程序按Button1后啟動(dòng)鉤子,這時(shí)運(yùn)行其他程序,按Ctrl+Alt+F12可將之隱藏,再按一下則恢復(fù)。以下程序在Delphi 4下通過(guò)。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多