858 lines
26 KiB
C++
858 lines
26 KiB
C++
|
||
/****************************************\
|
||
|* */
|
||
#define ESTOY_PROBANDO
|
||
// #define SIN_BLOQUEOS
|
||
/* *|
|
||
\****************************************/
|
||
|
||
|
||
//---------------------------------------------------------------------------
|
||
#include <vcl.h>
|
||
#pragma hdrstop
|
||
|
||
#include "CtrlDog.h"
|
||
#include "CtrlD_PasswordDlg.h"
|
||
//---------------------------------------------------------------------------
|
||
#pragma package(smart_init)
|
||
#pragma link "Phantom"
|
||
#pragma link "DigitNum"
|
||
#pragma resource "*.dfm"
|
||
|
||
#include <winuser.h>
|
||
#include <registry.hpp>
|
||
|
||
#define RECORDSYSTEM "C:\\WinRCD.log"
|
||
|
||
TDog *Dog;
|
||
//---------------------------------------------------------------------------
|
||
__fastcall TDog::TDog(TComponent* Owner)
|
||
: TForm(Owner)
|
||
{
|
||
try {
|
||
Memo1->Lines->LoadFromFile( RECORDSYSTEM );
|
||
if ( Memo1->Lines->Count > 400 )
|
||
{
|
||
for ( int i=0; i<100; i++ )
|
||
Memo1->Lines->Delete( 3 );
|
||
}
|
||
} catch(...) {
|
||
Memo1->Lines->Clear();
|
||
}
|
||
|
||
siMinimizar = new TStringList();
|
||
noMinimizar = new TStringList();
|
||
snMinimizar = new TStringList();
|
||
noAbrir = new TStringList();
|
||
ObtenListaAplicaciones();
|
||
|
||
|
||
AllowClose = false;
|
||
CanBeDisconect = true;
|
||
|
||
Dig1->Value = 0; Dig2->Value = 0;
|
||
|
||
TrayMessage(NIM_ADD);
|
||
TrayMessage(NIM_MODIFY);
|
||
|
||
Application->OnMinimize = AppRestore;
|
||
|
||
HookAutoStartProgram();
|
||
|
||
Top = ( Screen->Height / 2) - (Height / 2 );
|
||
Left = ( Screen->Width / 2 )- (Width / 2 );
|
||
iLockSystem( true );
|
||
|
||
|
||
/*
|
||
typedef struct tagACCEL { // accl
|
||
BYTE fVirt;
|
||
WORD key;
|
||
WORD cmd;
|
||
} ACCEL;
|
||
*/
|
||
/*
|
||
ACCEL AltTAB;
|
||
AltTAB.fVirt = FALT;
|
||
AltTAB.key = VK_TAB;
|
||
AltTAB.cmd = 0;
|
||
HACCEL hAltTAB = CreateAcceleratorTable( &AltTAB, 1 );
|
||
|
||
*/
|
||
Tiempo = EncodeTime( 0, 0, 0, 0 );
|
||
TryClose = false;
|
||
|
||
/****/
|
||
Tiempo = EncodeTime( 0, 0, 30, 0 );
|
||
SetState(true);
|
||
/****/
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::DrawItem(TMessage& Msg)
|
||
{
|
||
IconDrawItem((LPDRAWITEMSTRUCT)Msg.LParam);
|
||
TForm::Dispatch(&Msg);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::MyNotify(TMessage& Msg)
|
||
{
|
||
POINT MousePos;
|
||
|
||
switch(Msg.LParam)
|
||
{
|
||
case WM_RBUTTONUP:
|
||
if ( GetCursorPos(&MousePos) )
|
||
{
|
||
PopupMenu1->PopupComponent = Dog;
|
||
SetForegroundWindow(Handle);
|
||
PopupMenu1->Popup(MousePos.x, MousePos.y);
|
||
PopupMenu1->PopupComponent = 0;
|
||
}
|
||
break;
|
||
case WM_LBUTTONDBLCLK:
|
||
Height = 126;
|
||
Visible = true;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
TForm::Dispatch(&Msg);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool __fastcall TDog::TrayMessage(DWORD dwMessage)
|
||
{
|
||
NOTIFYICONDATA tnd;
|
||
PSTR pszTip;
|
||
|
||
pszTip = TipText();
|
||
|
||
tnd.cbSize = sizeof(NOTIFYICONDATA);
|
||
tnd.hWnd = Handle;
|
||
tnd.uID = IDC_MYICON;
|
||
tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
|
||
tnd.uCallbackMessage = MYWM_NOTIFY;
|
||
|
||
if (dwMessage == NIM_MODIFY)
|
||
{
|
||
tnd.hIcon = IconHandle();
|
||
if (pszTip)
|
||
lstrcpyn(tnd.szTip, pszTip, sizeof(tnd.szTip));
|
||
else
|
||
tnd.szTip[0] = '\0';
|
||
}
|
||
else
|
||
{
|
||
tnd.hIcon = NULL;
|
||
tnd.szTip[0] = '\0';
|
||
}
|
||
|
||
return (Shell_NotifyIcon(dwMessage, &tnd));
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
HANDLE __fastcall TDog::IconHandle(void)
|
||
{
|
||
return Image1 -> Picture->Icon->Handle;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
PSTR __fastcall TDog::TipText(void)
|
||
{
|
||
if (Timer1->Enabled)
|
||
return ("Acceso al sistema premitido");
|
||
else
|
||
{
|
||
Memo1->Lines->Insert( 0, DateTimeToStr(Now()) + " ATACANTE DESCONOCIDO (ACCESO NO AUTORIZADO)" );
|
||
Memo1->Lines->Insert( 0, DateTimeToStr(Now()) + " -------- ALARMA SILENCIOSA ACTIVADA -------" );
|
||
Memo1->Lines->SaveToFile( RECORDSYSTEM );
|
||
return ("SISTEMA PROTEGIDO");
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
LRESULT IconDrawItem(LPDRAWITEMSTRUCT lpdi)
|
||
{
|
||
HICON hIcon;
|
||
hIcon = (HICON)LoadImage(g_hinst, MAKEINTRESOURCE(lpdi->CtlID), IMAGE_ICON, 16, 16, 0);
|
||
if (!hIcon)
|
||
return(FALSE);
|
||
|
||
DrawIconEx(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top, hIcon, 16, 16, 0, NULL, DI_NORMAL);
|
||
return(TRUE);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::SetState( bool OnOff )
|
||
{
|
||
/////////////
|
||
Memo1->Lines->Insert( 0, "Terminal " + (OnOff ? AnsiString("ON") : AnsiString("OFF") ) );
|
||
if ( OnOff )
|
||
{
|
||
TiempoInicio = TDateTime::CurrentTime();
|
||
|
||
Memo1->Lines->Insert( 0, " `------ Durante --> " + Tiempo.TimeString() );
|
||
unsigned short hour, min, sec, msec;
|
||
Tiempo.DecodeTime( &hour, &min, &sec, &msec );
|
||
Timer1->Interval = msec + ( sec + ( (min+2) + hour*60 )*60 )*1000 ;
|
||
Timer1->Enabled = true;
|
||
|
||
Reloj->Enabled = true;
|
||
Dig1->Value = hour; Dig2->Value = min;
|
||
SystemLock->Enabled = false;
|
||
iLockSystem( false );
|
||
} else {
|
||
Tiempo = 0;
|
||
SystemLock->Enabled = true;
|
||
Timer1->Enabled = false;
|
||
Reloj->Enabled = false;
|
||
Dig1->Value = 0; Dig2->Value = 0;
|
||
iLockSystem( true );
|
||
}
|
||
Memo1->Lines->SaveToFile( RECORDSYSTEM );
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::ServerSocketAccept(TObject *Sender,
|
||
TCustomWinSocket *Socket)
|
||
{
|
||
StatusBar1->SimpleText = "Conexi<EFBFBD>n aceptada de " + Socket->RemoteAddress;
|
||
Memo1->Lines->Insert( 0, StatusBar1->SimpleText );
|
||
|
||
int CodOp; double pTiempo;
|
||
CanBeDisconect = false;
|
||
|
||
Socket->ReceiveBuf( &CodOp, sizeof(int) );
|
||
|
||
switch( CodOp )
|
||
{
|
||
// On / Off
|
||
case 6669:
|
||
Socket->ReceiveBuf( &CodOp, sizeof(int) );
|
||
Socket->ReceiveBuf( &pTiempo, sizeof(double) );
|
||
Tiempo = pTiempo;
|
||
SetState( CodOp ? true : false );
|
||
CodOp = 54321;
|
||
Socket->SendBuf( &CodOp, sizeof(int) );
|
||
break;
|
||
// CERRAR WINDOWS
|
||
case 6660:
|
||
Socket->ReceiveBuf( &CodOp, sizeof(int) );
|
||
Socket->ReceiveBuf( &pTiempo, sizeof(double) );
|
||
Tiempo = pTiempo;
|
||
CodOp = 54321;
|
||
Socket->SendBuf( &CodOp, sizeof(int) );
|
||
CanBeDisconect = true;
|
||
Memo1->Lines->Insert( 0, "Recibida petici<63>n de CERRAR WINDOWS ::" + Socket->RemoteAddress );
|
||
CerrarWindows1Click(0);
|
||
break;
|
||
// Query TIME
|
||
case 6661:
|
||
Memo1->Lines->Insert( 0, "Recibida petici<63>n de Tiempo ::" + Socket->RemoteAddress );
|
||
Socket->SendBuf( &Tiempo, sizeof(double) );
|
||
// Socket->SendBuf( &TiempoInicio, sizeof(double) );
|
||
Socket->SendBuf( &(Tiempo - ( TDateTime::CurrentTime() - TiempoInicio )), sizeof(double) );
|
||
CodOp = 54321;
|
||
Socket->SendBuf( &CodOp, sizeof(int) );
|
||
Memo1->Lines->Insert( 0, " -----> Tiempo pedido " + Tiempo );
|
||
Memo1->Lines->Insert( 0, " -----> Tiempo inicio " + TiempoInicio );
|
||
Memo1->Lines->Insert( 0, " -----> Servidor " + Socket->RemoteAddress );
|
||
break;
|
||
// Actualizar listas
|
||
case 6662:
|
||
{
|
||
int NumApli, i;
|
||
TRegistry *Registro;
|
||
char *Buffer;
|
||
|
||
Registro = new TRegistry;
|
||
|
||
Registro -> OpenKey( "\\Software\\JDsoft\\CtrlMstr", true );
|
||
|
||
Memo1->Lines->Insert( 0, "Actualizando Listas ::" + Socket->RemoteAddress );
|
||
|
||
Socket->ReceiveBuf( &NumApli, sizeof(int) );
|
||
Buffer = new char[ 15*NumApli ];
|
||
Registro -> WriteInteger( "NAppl-sC", NumApli );
|
||
for ( i=0; i<NumApli; i++ )
|
||
Socket->ReceiveBuf( (Buffer+15*i), sizeof(char)*15 );
|
||
Registro -> WriteBinaryData( "LAppl-sC", Buffer, sizeof(char)*15*NumApli+1 );
|
||
delete Buffer;
|
||
|
||
Socket->ReceiveBuf( &NumApli, sizeof(int) );
|
||
Buffer = new char[ 15*NumApli ];
|
||
Registro -> WriteInteger( "NAppl-nC", NumApli );
|
||
for ( i=0; i<NumApli; i++ )
|
||
Socket->ReceiveBuf( (Buffer+15*i), sizeof(char)*15 );
|
||
Registro -> WriteBinaryData( "LAppl-nC", Buffer, sizeof(char)*15*NumApli+1 );
|
||
delete Buffer;
|
||
|
||
Socket->ReceiveBuf( &NumApli, sizeof(int) );
|
||
Buffer = new char[ 15*NumApli ];
|
||
Registro -> WriteInteger( "NAppl-snC", NumApli );
|
||
for ( i=0; i<NumApli; i++ )
|
||
Socket->ReceiveBuf( (Buffer+15*i), sizeof(char)*15 );
|
||
Registro -> WriteBinaryData( "LAppl-snC", Buffer, sizeof(char)*15*NumApli+1 );
|
||
delete Buffer;
|
||
|
||
Socket->ReceiveBuf( &NumApli, sizeof(int) );
|
||
Buffer = new char[ 15*NumApli ];
|
||
Registro -> WriteInteger( "NAppl-nA", NumApli );
|
||
for ( i=0; i<NumApli; i++ )
|
||
Socket->ReceiveBuf( (Buffer+15*i), sizeof(char)*15 );
|
||
Registro -> WriteBinaryData( "LAppl-nA", Buffer, sizeof(char)*15*NumApli+1 );
|
||
delete Buffer;
|
||
|
||
|
||
delete Registro;
|
||
}
|
||
CodOp = 54321;
|
||
Socket->SendBuf( &CodOp, sizeof(int) );
|
||
ObtenListaAplicaciones();
|
||
break;
|
||
default:
|
||
Memo1->Lines->Insert( 0, "Mensaje desconocido ::" + Socket->RemoteAddress );
|
||
CodOp = -1;
|
||
Socket->SendBuf( &CodOp, sizeof(int) );
|
||
}
|
||
Memo1->Lines->Insert( 0, "Tramites Finalizados ::" + Socket->RemoteAddress );
|
||
StatusBar1->SimpleText = "Escuchando nuevas ordenes...";
|
||
Memo1->Lines->SaveToFile( RECORDSYSTEM );
|
||
CanBeDisconect = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::ObtenListaAplicaciones(void)
|
||
{
|
||
int i, nListaS, nListaN, nListaSN, nListaA; char *Buffer;
|
||
TRegistry *Registro;
|
||
Registro = new TRegistry;
|
||
|
||
try {
|
||
Registro -> OpenKey( "\\Software\\JDsoft\\CtrlMstr", false );
|
||
|
||
nListaS = Registro -> ReadInteger( "NAppl-sC" );
|
||
Buffer = new char [ nListaS*15 + 1 ];
|
||
Registro -> ReadBinaryData( "LAppl-sC", (void *)Buffer, (sizeof(char)*15*nListaS +1) );
|
||
|
||
siMinimizar->Clear();
|
||
//ShowMessage( AnsiString(nListaS) );
|
||
for ( i=0; i < nListaS; i++ )
|
||
//{
|
||
siMinimizar->Add( AnsiString( (char *)(Buffer+i*15) ) );
|
||
//Memo1->Lines->Insert( 0, AnsiString( (char *)(Buffer+i*15) ) );
|
||
//}
|
||
delete Buffer;
|
||
|
||
nListaN = Registro -> ReadInteger( "NAppl-nC" );
|
||
Buffer = new char [ nListaN*15 ];
|
||
Registro -> ReadBinaryData( "LAppl-nC", (void *)Buffer, (sizeof(char)*15*nListaN +1) );
|
||
|
||
noMinimizar->Clear();
|
||
for ( i=0; i < nListaN; i++ )
|
||
//{
|
||
noMinimizar->Add( AnsiString( (char *)(Buffer+i*15) ) );
|
||
//Memo1->Lines->Insert( 0, (Buffer+i*15) );
|
||
//}
|
||
delete Buffer;
|
||
|
||
nListaSN = Registro -> ReadInteger( "NAppl-snC" );
|
||
Buffer = new char [ nListaSN*15 ];
|
||
Registro -> ReadBinaryData( "LAppl-snC", (void *)Buffer, (sizeof(char)*15*nListaSN +1) );
|
||
noMinimizar->Clear();
|
||
for ( i=0; i < nListaSN; i++ )
|
||
snMinimizar->Add( AnsiString( (char *)(Buffer+i*15) ) );
|
||
delete Buffer;
|
||
|
||
nListaA = Registro -> ReadInteger( "NAppl-nA" );
|
||
Buffer = new char [ nListaA*15 ];
|
||
Registro -> ReadBinaryData( "LAppl-nA", (void *)Buffer, (sizeof(char)*15*nListaA +1) );
|
||
noAbrir->Clear();
|
||
for ( i=0; i < nListaA; i++ )
|
||
noAbrir->Add( AnsiString( (char *)(Buffer+i*15) ) );
|
||
delete Buffer;
|
||
|
||
} catch(...) {
|
||
// nothing
|
||
}
|
||
Memo1->Lines->Insert( 0, Format( "Listas Cargadas: %02dS::%02dN", ARRAYOFCONST( ( siMinimizar->Count, noMinimizar->Count ) ) ) );
|
||
Memo1->Lines->Insert( 0, Format( "Listas Cargadas: %02dC::%02dA", ARRAYOFCONST( ( snMinimizar->Count, noAbrir->Count ) ) ) );
|
||
|
||
delete Registro;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TDog::ServerSocketClientConnect(TObject *Sender,
|
||
TCustomWinSocket *Socket)
|
||
{
|
||
StatusBar1->SimpleText = "Cliente Conectado ";
|
||
Memo1->Lines->Insert( 0, "Cliente Conectado " );
|
||
Memo1->Lines->SaveToFile( RECORDSYSTEM );
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::ServerSocketClientDisconnect(TObject *Sender,
|
||
TCustomWinSocket *Socket)
|
||
{
|
||
if ( ! CanBeDisconect )
|
||
Memo1->Lines->Insert( 0, "DESCONEXION FORZADA ::" + Socket->LocalAddress );
|
||
else
|
||
Memo1->Lines->Insert( 0, "Desconexi<EFBFBD>n en regla ::" );
|
||
Memo1->Lines->SaveToFile( RECORDSYSTEM );
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::ServerSocketClientError(TObject *Sender,
|
||
TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
|
||
{
|
||
Memo1->Lines->Insert( 0, (Now()).DateTimeString() + " :: Cliente <20> ERROR ! " + AnsiString( ErrorCode ) + "::" + Socket->LocalAddress );
|
||
Memo1->Lines->SaveToFile( RECORDSYSTEM );
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TDog::ServerSocketGetSocket(TObject *Sender, int Socket,
|
||
TServerClientWinSocket *&ClientSocket)
|
||
{
|
||
Memo1->Lines->Insert( 0, (Now()).DateTimeString() + " :: Obtuvimos un socket" );
|
||
Memo1->Lines->SaveToFile( RECORDSYSTEM );
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TDog::ServerSocketListen(TObject *Sender,
|
||
TCustomWinSocket *Socket)
|
||
{
|
||
Memo1->Lines->Insert( 0, (Now()).DateTimeString() + " /----->" + Socket->RemoteAddress );
|
||
Memo1->Lines->Insert( 0, (Now()).DateTimeString() + " :: Estoy escuchando ::" + Socket->LocalAddress );
|
||
Memo1->Lines->SaveToFile( RECORDSYSTEM );
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TDog::FormClose(TObject *Sender, TCloseAction &Action)
|
||
{
|
||
ServerSocket->Active = false;
|
||
if ( AllowClose )
|
||
{
|
||
delete siMinimizar;
|
||
delete noMinimizar;
|
||
delete snMinimizar;
|
||
delete noAbrir;
|
||
} else {
|
||
#ifndef ESTOY_PROBANDO
|
||
iLockSystem( true );
|
||
#endif
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::Timer1Timer(TObject *Sender)
|
||
{
|
||
SetState( false );
|
||
StatusBar1->SimpleText = "Sistema OFF --FORZADO--";
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TDog::FormCloseQuery(TObject *Sender, bool &CanClose)
|
||
{
|
||
Visible = false;
|
||
#ifndef ESTOY_PROBANDO
|
||
CanClose = AllowClose;
|
||
#else
|
||
iLockSystem( false );
|
||
#endif
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TDog::FormShow(TObject *Sender)
|
||
{
|
||
if ( Timer1->Enabled )
|
||
{
|
||
Reloj->Enabled=true;
|
||
RelojTimer(0);
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
|
||
void __fastcall TDog::RelojTimer(TObject *Sender)
|
||
{
|
||
// Actualizamos el tiempo que queda...
|
||
unsigned short hour, min, sec, msec;
|
||
|
||
(Tiempo - ( TDateTime::CurrentTime() - TiempoInicio )).DecodeTime( &hour, &min, &sec, &msec );
|
||
|
||
Dig1->Value = hour;
|
||
Dig2->Value = min;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TDog::Label1DblClick(TObject *Sender)
|
||
{
|
||
if ( Height == 354 ) Height = 126; else Height = 354;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
|
||
void __fastcall TDog::Tiemporestante1Click(TObject *Sender)
|
||
{
|
||
Visible = true;
|
||
Height = 126;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TDog::Status1Click(TObject *Sender)
|
||
{
|
||
Visible = true;
|
||
Height = 354;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TDog::CerrarWindows1Click(TObject *Sender)
|
||
{
|
||
// Shut down the system and force all applications to close.
|
||
AllowClose = true;
|
||
HookAutoStartProgram();
|
||
#ifndef SIN_BLOQUEOS
|
||
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE | EWX_POWEROFF, 0))
|
||
#endif
|
||
{
|
||
AllowClose = false;
|
||
Memo1->Lines->Insert( 0, (Now()).DateTimeString() + " Error durante el cierre" );
|
||
Memo1->Lines->SaveToFile( RECORDSYSTEM );
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::FormDestroy(TObject *Sender)
|
||
{
|
||
HookAutoStartProgram();
|
||
TrayMessage(NIM_DELETE);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::HookAutoStartProgram(void)
|
||
{
|
||
#ifndef SIN_BLOQUEOS
|
||
TRegistry *Registro;
|
||
Registro = new TRegistry;
|
||
|
||
try {
|
||
Registro -> OpenKey( "\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", true );
|
||
Registro -> WriteString( "WinPowerManager", Application->ExeName );
|
||
} catch(...) {
|
||
// Do nothing...
|
||
}
|
||
|
||
delete Registro;
|
||
#endif
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
bool MultimediaActive;
|
||
bool GetStyle( HWND hdl )
|
||
{
|
||
long style;
|
||
bool dev;
|
||
|
||
dev = false;
|
||
|
||
style = GetWindowLong(hdl,GWL_STYLE);
|
||
if(( style & WS_POPUP) == WS_POPUP)
|
||
{
|
||
if(((style & WS_GROUP) == WS_GROUP) && !
|
||
((style & WS_DISABLED) == WS_DISABLED) &&
|
||
((style & WS_SYSMENU) == WS_SYSMENU))
|
||
dev = true;
|
||
} else {
|
||
dev = true;
|
||
}
|
||
|
||
return dev;
|
||
};
|
||
//---------------------------------------------------------------------------
|
||
BOOL __stdcall MinimizeAllAplications( HWND hwnd, LPARAM lParam )
|
||
{
|
||
bool dev; int i;
|
||
char lpString[50];
|
||
AnsiString Text;
|
||
|
||
dev = true;
|
||
if ( hwnd != 0 )
|
||
{
|
||
GetWindowText( hwnd, lpString, 40 );
|
||
Text = AnsiString( lpString );
|
||
|
||
|
||
|
||
// Aplicaciones especiales que he de minimizar constantemente...
|
||
if ( Text.Pos("Episode I Racer" ) ||
|
||
Text.Pos("Quake" )
|
||
)
|
||
{
|
||
ShowWindow( hwnd, SW_MINIMIZE );
|
||
return dev;
|
||
}
|
||
|
||
// LISTA DINAMICA DE VENTANAS A MINIMIZAR
|
||
for ( i=0; i < siMinimizar->Count; i++ )
|
||
if ( Text.Pos( siMinimizar->Strings[i] ) )
|
||
{
|
||
ShowWindow( hwnd, SW_MINIMIZE );
|
||
return dev;
|
||
}
|
||
|
||
// Solo Ventanas visibles...
|
||
if ( IsWindowVisible( hwnd ) )
|
||
{
|
||
// ...y ademas ventanas PADRES
|
||
if ( GetWindow( hwnd, GW_OWNER) == 0 )
|
||
{
|
||
if ( ! GetStyle( hwnd ) )
|
||
{
|
||
if ( IsWindow( GetLastActivePopup( hwnd ) ) )
|
||
{
|
||
auto HWND hwPop;
|
||
hwPop = GetLastActivePopup( hwnd );
|
||
if ( !GetStyle(hwPop) ) return true;
|
||
} else return true;
|
||
}
|
||
|
||
// LA VENTANA ES TIPO -TASK-BAR- y ADEMAS ES VISIBLE
|
||
|
||
// Ventanas ante las cuales me oculto
|
||
if ( Text.Pos("Reproductor mul") != 0 ||
|
||
Text.Pos("Inform<EFBFBD>tica DJ")
|
||
)
|
||
{
|
||
MultimediaActive = true;
|
||
return true;
|
||
}
|
||
|
||
// LISTA DINAMICA DE VENTANAS A RESPETAR
|
||
for ( i=0; i < noMinimizar->Count; i++ )
|
||
if ( Text.Pos( noMinimizar->Strings[i] ) )
|
||
{
|
||
MultimediaActive = true;
|
||
return true;
|
||
}
|
||
|
||
// Ventanas que no he de minimizar (PERO QUEDO DE PRIMER PLANO)
|
||
if ( ! ( Text.Pos("Sistema de Control") ||
|
||
Text.Pos("Creditos ocultos")
|
||
)
|
||
)
|
||
{
|
||
ShowWindow( hwnd, SW_MINIMIZE );
|
||
}
|
||
|
||
}
|
||
}
|
||
} else {
|
||
dev = false;
|
||
}
|
||
|
||
return dev;
|
||
};
|
||
|
||
/*
|
||
procedure TForm1.TerminateProcess1Click(Sender: TObject);
|
||
const
|
||
PROCESS_TERMINATE = 1;
|
||
var
|
||
ProcHandle: THandle;
|
||
begin
|
||
if (ListBox1.Items.count < 1) OR (ListBox1.ItemIndex < 0) then exit;
|
||
if (MessageDlg('Process: --> ' + ListBox1.Items[ListBox1.itemIndex]+ #10#13#10#13+
|
||
'TerminateProcess may lead the system into an instable state! '+#10#13+
|
||
'You should use this function only if you are sure about doing so.'+#10#13+
|
||
'Are You sure?', mtConfirmation, [mbYes, mbNo], 0) = mrYes)
|
||
then begin
|
||
ProcHandle := OpenProcess(PROCESS_TERMINATE, FALSE, DWORD(WinList1.GetProcessID(ListBox1.ItemIndex)));
|
||
try
|
||
if ProcHandle <> 0 then begin
|
||
if TerminateProcess(ProcHandle, $FFFFFFFF) then
|
||
WaitForSingleObject(ProcHandle, INFINITE);
|
||
end else
|
||
MessageDlg('Can not find the handle of the selected prozess!', mtError, [mbOK], 0);
|
||
finally
|
||
CloseHandle(ProcHandle);
|
||
end;
|
||
Refresh1Click(Sender);
|
||
end;
|
||
end;
|
||
*/
|
||
|
||
|
||
//---------------------------------------------------------------------------
|
||
/*
|
||
BOOL __stdcall MyEnumDesktopProc( LPTSTR lpszDesktop, LPARAM lParam )
|
||
{
|
||
EnumDesktopWindows( lpszDesktop, ( WNDENUMPROC )MinimizeAllAplications, 0 );
|
||
return true;
|
||
};
|
||
*/
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::SystemLockTimer(TObject *Sender)
|
||
{
|
||
#ifndef SIN_BLOQUEOS
|
||
MultimediaActive = false;
|
||
|
||
EnumWindows( ( WNDENUMPROC )MinimizeAllAplications, 0 );
|
||
|
||
if ( MultimediaActive || TryClose )
|
||
{
|
||
Visible = false;
|
||
} else {
|
||
|
||
|
||
Top = ( Screen->Height / 2) - (Height / 2 );
|
||
Left = ( Screen->Width / 2 )- (Width / 2 );
|
||
|
||
if ( !Visible )Show();
|
||
// ShowWindow(this->Handle,SW_RESTORE);
|
||
SetForegroundWindow(this->Handle);
|
||
}
|
||
#endif
|
||
|
||
iLockSystem( true );
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::AppRestore(TObject *Sender)
|
||
{
|
||
Application->Restore();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::Shape2MouseDown(TObject *Sender,
|
||
TMouseButton Button, TShiftState Shift, int X, int Y)
|
||
{
|
||
if ( Shift.Contains(ssShift) && Shift.Contains(ssAlt) &&
|
||
Shift.Contains(ssCtrl) && Shift.Contains(ssDouble) )
|
||
{
|
||
TryClose = true;
|
||
|
||
TPasswordDlg *PasswordDlg;
|
||
PasswordDlg = new TPasswordDlg(this);
|
||
PasswordDlg->Password->Clear();
|
||
PasswordDlg -> ShowModal();
|
||
if ( PasswordDlg->Password->Text == "44959229170877" )
|
||
// if ( InputBox( "Creditos ocultos", "Donde estan:", "los creditos ocultos" ) == "44959229" )
|
||
{
|
||
TryClose = false;
|
||
AllowClose=true;
|
||
iLockSystem( false );
|
||
Close();
|
||
}
|
||
delete PasswordDlg;
|
||
TryClose = false;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::FormResize(TObject *Sender)
|
||
{
|
||
Top = ( Screen->Height / 2) - (Height / 2 );
|
||
Left = ( Screen->Width / 2 )- (Width / 2 );
|
||
#ifndef SIN_BLOQUEOS
|
||
if ( SystemLock->Enabled )
|
||
{
|
||
iLockSystem( true );
|
||
}
|
||
#endif
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::iLockSystem( bool status )
|
||
{
|
||
#ifdef SIN_BLOQUEOS
|
||
status = false;
|
||
#endif
|
||
if ( ! status ) // LIBRE DE BLOQUEOS
|
||
{
|
||
ClipCursor( NULL );
|
||
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, NULL,0);
|
||
// BorderIcons = (TBorderIcons()<< biSystemMenu);
|
||
} else { // INICIANDO BLOQUEOS
|
||
RECT ClipRect = { Left+2, Top+25, Left+Width-2, Top+120-20 };
|
||
ClipCursor( &ClipRect );
|
||
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1,NULL, 0);
|
||
// BorderIcons = BorderIcons - (TBorderIcons()<< biSystemMenu);
|
||
}
|
||
#define iTRAYBAR 0
|
||
#define iTRAYNOTIFY 1
|
||
#define iSTARTBUTTON 2
|
||
#define iAPPSWITCHBAR 3
|
||
#define iTRAYCLOCK 4
|
||
#define iDESKTOPICONS 5
|
||
|
||
|
||
HideOpt( iTRAYBAR, status );
|
||
HideOpt( iTRAYNOTIFY, status );
|
||
HideOpt( iSTARTBUTTON, status );
|
||
HideOpt( iAPPSWITCHBAR, status );
|
||
HideOpt( iTRAYCLOCK, status );
|
||
HideOpt( iDESKTOPICONS, status );
|
||
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TDog::HideOpt( int Option, bool Hide )
|
||
{
|
||
HWND Wnd;
|
||
|
||
switch( Option )
|
||
{
|
||
case iTRAYBAR :
|
||
Wnd = FindWindow("Shell_TrayWnd", NULL);
|
||
break;
|
||
case iTRAYNOTIFY :
|
||
Wnd = FindWindow("Shell_TrayWnd", NULL);
|
||
Wnd = FindWindowEx(Wnd, HWND(0), "TrayNotifyWnd", NULL);
|
||
break;
|
||
case iSTARTBUTTON :
|
||
Wnd = FindWindow("Shell_TrayWnd", NULL);
|
||
Wnd = FindWindowEx(Wnd, HWND(0), "Button", NULL);
|
||
break;
|
||
case iAPPSWITCHBAR :
|
||
Wnd = FindWindow("Shell_TrayWnd", NULL);
|
||
Wnd = FindWindowEx(Wnd, HWND(0), "ReBarWindow32", NULL);
|
||
break;
|
||
case iTRAYCLOCK :
|
||
Wnd = FindWindow("Shell_TrayWnd", NULL);
|
||
Wnd = FindWindowEx(Wnd, HWND(0), "TrayNotifyWnd", NULL);
|
||
Wnd = FindWindowEx(Wnd, HWND(0), "TrayClockWClass", NULL);
|
||
break;
|
||
case iDESKTOPICONS :
|
||
Wnd = FindWindow("Progman", NULL);
|
||
Wnd = FindWindowEx(Wnd, HWND(0), "ShellDll_DefView", NULL);
|
||
break;
|
||
}
|
||
|
||
if ( Wnd != 0 )
|
||
{
|
||
if ( Hide )
|
||
ShowWindow(Wnd, SW_HIDE);
|
||
else
|
||
ShowWindow(Wnd, SW_SHOW);
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
|
||
|
||
void __fastcall TDog::Shape1MouseUp(TObject *Sender, TMouseButton Button,
|
||
TShiftState Shift, int X, int Y)
|
||
{
|
||
#ifdef ESTOY_PROBANDO
|
||
static bool Rotate = true;
|
||
Tiempo = EncodeTime( 0, 1, 0, 0 );
|
||
if ( Rotate )
|
||
SetState( true );
|
||
else
|
||
SetState( false );
|
||
Rotate = !Rotate;
|
||
#endif
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TDog::FormClick(TObject *Sender)
|
||
{
|
||
if ( !SystemLock->Enabled )
|
||
Visible = false;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
|
||
void __fastcall TDog::Label2Click(TObject *Sender)
|
||
{
|
||
char zFileName[80], zParams[80], zDir[80];
|
||
if ( !SystemLock->Enabled )
|
||
ShellExecute(Application->MainForm->Handle, 0, StrPCopy(zFileName, "http:\\\\www.infdj.com"),
|
||
StrPCopy(zParams, ""), StrPCopy(zDir, ""), SW_SHOWNOACTIVATE > 32);
|
||
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|