//*********************************************************
// relojbin.c
// Protector de pantalla que muestra un reloj binario
// (c)1999, Jaime Virgilio Gómez Negrete
//*********************************************************
#include <windows.h>
#include <time.h>
LRESULT CALLBACK ScreenSaverProc (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK ConfiguraProc (HWND, UINT, WPARAM, LPARAM);
void password (HWND hwnd);
BOOL verifica_password(HWND hwnd);
enum TScrMode {smNone,smConfig,smPassword,smPreview,smSaver};
TScrMode, ScrMode = smNone;
struct tm *datetime;
time_t lTime;
div_t horas, minutos, segundos;
char szAppName[] = "relojbin";
HINSTANCE hInstance;
HWND hwnd, hScrWindow;
// Rutina para vista previa
HWND CheckForScrprev()
{
BOOL cres;
DWORD wres;
STARTUPINFO arranque;
PROCESS_INFORMATION informe;
hwnd = FindWindow("Scrprev", NULL); // Localiza la clase Scrprev
if(hwnd == NULL) // Trata de cargarla
{
ZeroMemory(&arranque, sizeof(arranque));
ZeroMemory(&informe, sizeof(informe));
arranque.cb = sizeof(arranque);
arranque.lpReserved = NULL;
arranque.lpTitle = NULL;
arranque.dwFlags = 0;
arranque.cbReserved2 = 0;
arranque.lpReserved2 = 0;
arranque.lpDesktop = 0;
cres = CreateProcess(NULL, "Scrprev", 0, 0, FALSE,
CREATE_NEW_PROCESS_GROUP | CREATE_DEFAULT_ERROR_MODE,
0, 0, &arranque, &informe);
wres = WaitForInputIdle(informe.hProcess, 2000);
hwnd = FindWindow("Scrprev", NULL);
}
SetForegroundWindow(hwnd);
hwnd = GetWindow(hwnd, GW_CHILD);
return hwnd;
}
// Establece o cambia el password
void password(HWND hwnd)
{
HINSTANCE hpassword;
typedef VOID (WINAPI *PWDCHANGEPASSWORD)(LPCSTR lpcRegkeyname,
HWND hwnd, UINT uiReserved1, UINT uiReserved2);
PWDCHANGEPASSWORD PwdChangePassword;
hpassword = LoadLibrary("MPR.DLL");
PwdChangePassword = (PWDCHANGEPASSWORD)GetProcAddress(hpassword,
"PwdChangePasswordA");
if(PwdChangePassword == NULL)
{
FreeLibrary(hpassword);
return;
}
PwdChangePassword("SCRSAVE", hwnd, 0, 0);
FreeLibrary(hpassword);
}
// Verifica el password
BOOL verifica_password(HWND hwnd)
{
OSVERSIONINFO osv;
HINSTANCE hpwdcpl;
typedef BOOL (WINAPI *VERIFYSCREENSAVEPWD)(HWND hwnd);
VERIFYSCREENSAVEPWD VerifyScreenSavePwd;
BOOL bres;
osv.dwOSVersionInfoSize = sizeof(osv);
GetVersionEx(&osv);
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT)
return TRUE;
hpwdcpl = LoadLibrary("PASSWORD.CPL");
if (hpwdcpl==NULL)
return TRUE;
VerifyScreenSavePwd = (VERIFYSCREENSAVEPWD)GetProcAddress(hpwdcpl,
"VerifyScreenSavePwd");
if (VerifyScreenSavePwd == NULL)
{
FreeLibrary(hpwdcpl);
return TRUE;
}
bres = VerifyScreenSavePwd(hwnd);
FreeLibrary(hpwdcpl);
return bres;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MSG msg;
WNDCLASSEX wndclass;
RECT rc;
UINT valorant;
char *letra;
letra = GetCommandLine();
if (*letra == '\"')
{
letra++;
while(*letra != 0 && *letra != '\"')
letra++;
}
else
{
while (*letra != 0 && *letra != ' ')
letra++;
}
if(*letra != 0)
letra++;
while(*letra == ' ')
letra++;
hwnd = NULL;
if(*letra == 0)
{
ScrMode = smConfig;
hwnd = NULL;
}
else
{
if(*letra == '-' || *letra == '/')
letra++;
if(*letra == 'p' || *letra == 'P' || *letra == 'l'
|| *letra == 'L')
{
letra++;
while(*letra == ' ' || *letra == ':')
letra++;
if((strcmp(letra, "scrprev") == 0)
|| (strcmp(letra, "ScrPrev") == 0)
|| (strcmp(letra, "SCRPREV") == 0))
hwnd = CheckForScrprev();
else
hwnd = (HWND)atoi(letra);
ScrMode = smPreview;
}
else
if(*letra == 's' || *letra == 'S')
ScrMode = smSaver;
else
if(*letra == 'c' || *letra == 'C')
{
letra++;
while
(*letra == ' ' || *letra == ':')
letra++;
if(*letra == 0)
hwnd = GetForegroundWindow();
else
hwnd = (HWND)atoi(letra);
ScrMode = smConfig;
}
else
if(*letra == 'a' || *letra == 'A')
{
letra++;
while(*letra == ' ' || *letra == ':')
letra++;
hwnd = (HWND)atoi(letra);
ScrMode = smPassword;
}
}
if (ScrMode == smPassword)
password(hwnd);
if (ScrMode == smConfig)
{
DialogBox(hInstance, "Configura", hwnd, ConfiguraProc);
return 0;
}
if (ScrMode == smSaver || ScrMode == smPreview)
{
wndclass.cbSize = sizeof (wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = ScreenSaverProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, szAppName);
wndclass.hCursor = LoadCursor (hInstance, szAppName);
wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon (hInstance, szAppName);
RegisterClassEx (&wndclass);
if (ScrMode == smPreview)
{
GetWindowRect(hwnd, &rc);
hScrWindow = CreateWindowEx(0, szAppName, "SaverPreview",
WS_CHILD|WS_VISIBLE,
0, 0, rc.right-rc.left, rc.bottom-rc.top,
hwnd, NULL, hInstance, NULL);
}
else
{
hScrWindow = CreateWindowEx(WS_EX_TOPMOST, szAppName,
"SaverWindow", WS_POPUP|WS_VISIBLE,
0, 0, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
NULL, NULL, hInstance, NULL);
}
if (hScrWindow == NULL)
return 0;
if(ScrMode == smSaver)
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, &valorant, 0);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(ScrMode == smSaver)
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, &valorant, 0);
}
return 0;
}
LRESULT CALLBACK ScreenSaverProc (HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
HBRUSH hBrush;
static int cxCliente, cyCliente, mensaje;
switch (iMsg)
{
case WM_CREATE:
SetTimer(hwnd, 1, 100, NULL);
return 0;
case WM_TIMER:
time(&lTime);
datetime = localtime(&lTime);
horas = div(datetime->tm_hour, 10);
minutos = div(datetime->tm_min, 10);
segundos = div(datetime->tm_sec, 10);
InvalidateRect(hwnd, NULL, FALSE);
if(mensaje<1000)
mensaje++;
else
mensaje = 0;
return 0;
case WM_SIZE:
cxCliente = LOWORD(lParam)/19;
cyCliente = HIWORD(lParam)/13;
return 0;
case WM_MOUSEMOVE:
hdc = GetDC(hwnd);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(0, 255, 255));
TextOut(hdc, cxCliente, (cyCliente*9)+10,
"e-mail: virgiliotech@yahoo.com", 30);
ReleaseDC(hwnd, hdc);
return 0;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_KEYDOWN:
if(verifica_password(hwnd))
SendMessage(hwnd, WM_CLOSE, 0, 0);
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(0, 0, 0));
TextOut(hdc, cxCliente, (cyCliente*9)+10,
"e-mail: virgiliotech@yahoo.com", 30);
if(mensaje<120)
{
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(0, 255, 0));
TextOut(hdc, cxCliente, (cyCliente*12)+10,
"http://www.GeoCities.com/SiliconValley/Garage/8211", 50);
}
else
{
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(0, 0, 0));
TextOut(hdc, cxCliente, (cyCliente*12)+10,
"http://www.GeoCities.com/SiliconValley/Garage/8211", 50);
}
// Decenas de hora
if(horas.quot&2)
{
SetRect(&rect, cxCliente, cyCliente*7, cxCliente*3,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente, cyCliente*7, cxCliente*3,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(horas.quot&1)
{
SetRect(&rect, cxCliente, cyCliente*10, cxCliente*3,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente, cyCliente*10, cxCliente*3,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
// Unidades de hora
if(horas.rem&8)
{
SetRect(&rect, cxCliente*4, cyCliente, cxCliente*6,
cyCliente*3);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*4, cyCliente, cxCliente*6,
cyCliente*3);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(horas.rem&4)
{
SetRect(&rect, cxCliente*4, cyCliente*4, cxCliente*6,
cyCliente*6);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*4, cyCliente*4, cxCliente*6,
cyCliente*6);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(horas.rem&2)
{
SetRect(&rect, cxCliente*4, cyCliente*7, cxCliente*6,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*4, cyCliente*7, cxCliente*6,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(horas.rem&1)
{
SetRect(&rect, cxCliente*4, cyCliente*10, cxCliente*6,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*4, cyCliente*10, cxCliente*6,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
// Decenas de minuto
if(minutos.quot&4)
{
SetRect(&rect, cxCliente*7, cyCliente*4, cxCliente*9,
cyCliente*6);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*7, cyCliente*4, cxCliente*9,
cyCliente*6);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(minutos.quot&2)
{
SetRect(&rect, cxCliente*7, cyCliente*7, cxCliente*9,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*7, cyCliente*7, cxCliente*9,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(minutos.quot&1)
{
SetRect(&rect, cxCliente*7, cyCliente*10, cxCliente*9,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*7, cyCliente*10, cxCliente*9,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
// Unidades de minuto
if(minutos.rem&8)
{
SetRect(&rect, cxCliente*10, cyCliente, cxCliente*12,
cyCliente*3);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*10, cyCliente, cxCliente*12,
cyCliente*3);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(minutos.rem&4)
{
SetRect(&rect, cxCliente*10, cyCliente*4, cxCliente*12,
cyCliente*6);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*10, cyCliente*4, cxCliente*12,
cyCliente*6);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(minutos.rem&2)
{
SetRect(&rect, cxCliente*10, cyCliente*7, cxCliente*12,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*10, cyCliente*7, cxCliente*12,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(minutos.rem&1)
{
SetRect(&rect, cxCliente*10, cyCliente*10, cxCliente*12,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*10, cyCliente*10, cxCliente*12,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
// Decenas de segundo
if(segundos.quot&4)
{
SetRect(&rect, cxCliente*13, cyCliente*4, cxCliente*15,
cyCliente*6);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*13, cyCliente*4, cxCliente*15,
cyCliente*6);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(segundos.quot&2)
{
SetRect(&rect, cxCliente*13, cyCliente*7, cxCliente*15,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*13, cyCliente*7, cxCliente*15,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(segundos.quot&1)
{
SetRect(&rect, cxCliente*13, cyCliente*10, cxCliente*15,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*13, cyCliente*10, cxCliente*15,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
// Unidades de segundo
if(segundos.rem&8)
{
SetRect(&rect, cxCliente*16, cyCliente, cxCliente*18,
cyCliente*3);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*16, cyCliente, cxCliente*18,
cyCliente*3);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(segundos.rem&4)
{
SetRect(&rect, cxCliente*16, cyCliente*4, cxCliente*18,
cyCliente*6);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*16, cyCliente*4, cxCliente*18,
cyCliente*6);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(segundos.rem&2)
{
SetRect(&rect, cxCliente*16, cyCliente*7, cxCliente*18,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*16, cyCliente*7, cxCliente*18,
cyCliente*9);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
if(segundos.rem&1)
{
SetRect(&rect, cxCliente*16, cyCliente*10, cxCliente*18,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
else
{
SetRect(&rect, cxCliente*16, cyCliente*10, cxCliente*18,
cyCliente*12);
hBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
}
EndPaint (hwnd, &ps);
return 0;
case WM_DESTROY:
KillTimer(hwnd, 1);
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}
BOOL CALLBACK ConfiguraProc(HWND hDlg, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
switch(iMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
EndDialog(hDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}
|