Heterogeneous screen protection

zhaozj2021-02-16  59

We know that you can set the screen saver when there is no operation on your computer in a certain period of time. We can also plan planning tasks to let our computer start us working on a set time. These two functions are good ideas, so Microsoft has retained them. However, we may have a better idea, I hope to work after the computer is idle for a while, not just start the screen saver. We can temporarily call it as a heterogeneous screen protected. However, how do we achieve it?

Not very difficult? For those who learn to program, it will be slightly moving. Is not it?

I think so. However, when I really do it, I found there is a difficult place: How do we determine that the computer is idle?

But this is not tight, I think. We can take the start-up screen saver to the task we need. However, I think there is a better way.

I found this method, and the code is also very simple. I want to put my experience and share it with you.

If we do hooks, whether it is a keyboard hook, mouse hook, or other system hook, must remember this function? I counted, in the "Computer Lovers", this function is also frequent.

Not much, today's core is the function of SetWindowsHookex, there is no other place to explain. I originally want to add a comment to the program, but you look at the program, it really doesn't have to say anything, so don't say anything. Haha!

The program is programmed under Delphi6.0 Windows Me.

Unit unit1;

Interface

Uses

Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Extctrls, stdctrls, shellapi;

Type

TFORM1 = Class (TFORM)

Label1: TLABEL;

Timer1: TTIMER;

Procedure formcreate (Sender: TOBJECT);

Procedure Timer1Timer (Sender: TOBJECT);

Procedure formclose (Sender: Tobject; VAR Action: Tclosection);

Private

{Private Declarations}

public

{Public declarations}

END;

VAR

FORM1: TFORM1;

HHOOK: Integer;

TimetAl: Integer;

BNOTRUNING: BOOLEAN;

IMPLEMentation

{$ R * .dfm}

Const

Timescount = 10;

Function JournalRecordproc (icode: integer; wparam: wparam; lparam: lparam): LRESULT; stdcall;

Begin

TimeTotal: = 0;

Result: = 0;

END;

Function Starthook: Boolean;

Begin

Result: = FALSE;

IF hHOOK = 0 THEN

Begin

HHOOK: = SETWINDOWSHOKEX (WH_JournalRecord, JournalRecordProc, Hinstance, 0);

IF HHOOK> 0.

END;

END;

Procedure stophook;

Begin

IF hHOOK> 0 THEN

Begin

UnHookWindowsHookex (HHOOK);

HHOOK: = 0;

END;

END;

Procedure TFORM1.FormCreate (Sender: TOBJECT);

Begin

HHOOK: = 0;

BNOTRUNNING: = True;

STARTHOOK;

END;

Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT);

Begin

INC; TIMETAl

Label1.caption: = floattostr (Timetotal);

IF (Timetary> Timescount) and bnotrunning then

Begin

BNOTRUNNING: = false;

Shellexecute (Handle, 'Open', Pchar ('Notepad'),

NIL, NIL, SW_SHOW;

END;

END;

Procedure TFORM1.FORMCLOSE (Sender: TpoBject; VAR Action: Tclosection);

Begin

Stophook;

END;

End.

The program is very short? I just launched a notepad, demonstrating how I did this function, did not take more consideration. If you want to use this method, I suggest that you first have more control over your task, including start, progress, process, end, etc. You can also list the task. If you don't know how to control external programs, you can go to http://www.9cbs.net to refer to my other embarrassment: "Start the external program and wait for its end."

Ok, in addition to screen protection and planning tasks, you have a choice. Just achieve it.

转载请注明原文地址:https://www.9cbs.com/read-22725.html

New Post(0)