Hide Current Process

Source: Internet
Author: User

The program that restores the current window, because the current process may be running in Full-screen mode, you need to specify a specific hotkey to make the program window disappear and not present on the taskbar. Here's how to use Delphi to achieve this. The main need to solve two problems, that is, hidden windows and set hotkeys.

A. Hide window

Get the current window through API function GetActiveWindow, the parameters of function ShowWindow (hwnd,ncmdshow) are hidden when sw_hide is taken, and displayed when Sw_show. For example: ShowWindow (getactivewindow,sw_hide). After you hide the form, you must remember the form handle for recovery.

Two. Keyboard monitoring

In order to achieve keyboard monitoring must use the hook.

The following is the source file for the program:

---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;


//Detect Ctrl + ALT + F12 key combination


if ((LParam and _keypressmask) = 0)//When pressed to take effect


and (Getkeystate (Vk_control) < 0)


and (Getkeystate (Vk_menu) <0) and (WParam = vk_f12) then


begin


Result: = 1;


//file does not exist then create


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;


//Hook Wh_keyboard This type, at the same time, return value must be retained


//Come, lest the HOOK call chain break off


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); Lift keyboard Hook


hnexthookhide:=0;


End


Else


Result:=false;


end;


procedure Hidehookexit;


begin


//If you forget to lift the HOOK, the action of the automatic agent is lifted


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.


files are made and then the build all is compiled into HKPHide.dll.


a new project 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.

Run the program after pressing Button1 to start the hook, then run other programs, press CTRL+ALT+F12 can hide it, and then restore. The following procedure is passed under Delphi 4.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.