The Client for an Internet Access Control Application - Small and Main Window
(Page 2 of 4 )
The client has two parts. The first part is what a user will see when a session has started. This includes a small window that will tell the user how much time she has left for her session. And the other is the main window that shows the ads.
In the source code for the client, I’ve set the ads window to cover the entire screen. But you can of course modify it to suit. Also, when the ads window is set, keyboard and mouse access will be disabled. This is because you do not expect anyone to use the workstation concerned, and the workstation will only be activated if a session has been started for it. Below is a listing of the main code for the client application:
Listing 1:
unit uclient;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,idsync,idcommandhandlers, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdCmdTCPClient, OleCtrls,
SHDocVw,INIFiles, jpeg, ExtCtrls;
type
TReadingThread = class(TThread)
protected
FConn: TIdTCPConnection;
procedure Execute; override;
public
constructor Create(AConn: TIdTCPConnection); reintroduce;
end;
TLog = class(TIdSync)
protected
FMsg: String;
procedure DoSynchronize; override;
public
constructor Create(const AMsg: String);
class procedure AddMsg(const AMsg: String);
end;
TForm1 = class(TForm)
edname: TEdit;
btnConnect: TBitBtn;
btnDiscon: TBitBtn;
btnExit: TBitBtn;
tc: TIdCmdTCPClient;
one: TButton;
wb: TWebBrowser;
setof: TTimer;
procedure btnExitClick(Sender: TObject);
procedure tcConnected(Sender: TObject);
procedure btnDisconClick(Sender: TObject);
procedure btnConnectClick(Sender: TObject);
procedure tcDisconnected(Sender: TObject);
procedure oneClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure setofTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
//this var will control mouse/keyboard access with timer
setoff:boolean;
function GetComputerName: string;
function FuncAvail(dllName, funcName: string; var p: pointer): boolean;
end;
var
Form1: TForm1;
rt: TReadingThread = nil;
path:string;
BlockInput : function(Block: BOOL): BOOL; stdcall;
implementation
uses utimer;
{$R *.dfm}
//***shutdown function
function TimedShutDown(Computer: string; Msg: string; Time: Word; Force: Boolean; Reboot: Boolean): Boolean;
var
rl: Cardinal;
hToken: Cardinal;
tkp: TOKEN_PRIVILEGES;
begin
//get user privileges to shutdown the machine
if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
ShowMessage('Cannot open process token.')
else
begin
if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then
begin
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1;
AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);
if GetLastError <> ERROR_SUCCESS then
ShowMessage('Error adjusting process privileges.');
end
else
ShowMessage('Cannot find privilege value.');
end;
Result := InitiateSystemShutdown(PChar(Computer), PChar(Msg), Time, Force, Reboot)
end;
//**end shutdown function
The shutdown function, as the name suggests, is responsible for shutting down a connected workstation. When the shutdown code is executed, a timed shutdown dialog box will appear on the workstation's screen. Finally, the computer will be shut down.
Next: Disable Mouse and Keyboard Access >>
More Delphi-Kylix Articles
More By David Web