1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296:
|
program TemplateScreenSaver;
{$R 'TemplateScreenSaver.RES' 'TemplateScreenSaver.RC'} {$DESCRIPTION 'tPs Template-Screensaver'} {$E scr}
uses Windows, Messages, CommCtrl;
const WndClassName = 'MyScrWndClass'; AppName = 'TemplateScreenSaver';
IDD_DLG = 100; IDC_BTN_OK = 101;
TimerElapse = 100;
type TScreenMode = (scrmStart, scrmPreview, scrmConfig);
var AppHWND: HWND = 0; WndClass: TWndClass; Msg: TMsg; ScreenMode: TScreenMode; WndRect: TRect; ParentWnd: HWND; StartupCursorPos:TPoint;
Counter: Integer = 0 ;
function _StrToInt(Value: String): Integer; var err: Integer; begin Val(Value, Result, err); end;
function _IntToStr(Value: Integer): String; begin Str(Value, Result); end;
procedure OnTimerEvent(hWnd: HWND); var DC: HDC; Pen, oldPen: HPen; OldBKMode: Integer; i : Byte; Txt: String; begin DC := GetDC(AppHWND); case Random(2) of
0: for i := 0 to 255 do begin SetPixel( DC, random(WndRect.Right), random(WndRect.Bottom), RGB(random(256), random(256), random(256))); end;
1: begin Pen := CreatePen(PS_SOLID, 1, RGB(random(256), random(256), random(256))); oldPen := SelectObject(DC, Pen);
MoveToEx( DC, random(WndRect.Right), random(WndRect.Bottom), nil); LineTo( DC, random(WndRect.Right), random(WndRect.Bottom));
SelectObject(DC, oldPen); DeleteObject(Pen); end; end;
Case ScreenMode of scrmStart: Txt := 'Normal'; scrmPreview: Txt := 'Preview'; end;
OldBKMode := SetBKMode(DC, TRANSPARENT); SetTextColor(DC, RGB(255, 0, 0)); TextOut(DC, 5, 5, PChar(Txt), Length(Txt)); SetBKMode(DC, OldBKMode);
ReleaseDC(hWnd, DC); end;
function DlgProc(hDlg: HWND; msg: UINT; wParam: WPARAM; lParam: LPARAM): lResult; stdcall; begin Result := 0; if wParam = SC_CLOSE then;
case msg of WM_INITDIALOG:; WM_COMMAND: begin case wParam of IDC_BTN_OK: EndDialog(hDlg, 1); end; end; end; end;
function ScreenSaverProc(hWnd: HWND; uMsg: UINT; wParam: wParam; lParam: LParam): lResult; stdcall; var CurrentPos:TPoint; begin Result := 0;
case uMsg of WM_CREATE: begin if ScreenMode = scrmStart then ShowCursor(FALSE); SetTimer(hWnd, 1, TimerElapse, nil); GetCursorPos(StartupCursorPos); end; WM_DESTROY: begin if ScreenMode = scrmStart then ShowCursor(TRUE); KillTimer(hWnd, 1); DestroyWindow(hWnd); PostQuitMessage(0); end; WM_ACTIVATE: if (wParam = Integer(FALSE)) then PostMessage(hWnd, WM_CLOSE, 0, 0); WM_LBUTTONDOWN, WM_MBUTTONDOWN, WM_RBUTTONDOWN, WM_KEYDOWN: begin if ScreenMode = scrmStart then PostMessage(hWnd, WM_CLOSE, 0, 0); end;
WM_MOUSEMOVE: begin if (ScreenMode = scrmStart) and (Counter >= 10) then begin GetCursorPos(CurrentPos);
If (CurrentPos.X-StartupCursorPos.X < -10) or (CurrentPos.X-StartupCursorPos.X > 10) or (CurrentPos.y-StartupCursorPos.Y < -10) or (CurrentPos.y-StartupCursorPos.Y > 10) then PostMessage(hWnd, WM_CLOSE, 0, 0); end; end;
WM_SYSCOMMAND: Case wParam of SC_MONITORPOWER: ; SC_SCREENSAVE, SC_CLOSE: Result := 0; end;
WM_TIMER: begin if Counter < (1000 div TimerElapse) then inc(Counter); OnTimerEvent(hWnd); end; else Result := DefWindowProc(hWnd, uMsg, wParam, lParam); end; end;
BEGIN InitCommonControls; if ParamCount = 0 then begin ScreenMode := scrmConfig; end else if ParamStr(1)[1] in ['-', '/'] then begin case ParamStr(1)[2] of 'S', 's': ScreenMode := scrmStart; 'P', 'p': ScreenMode := scrmPreview; 'C', 'c': ScreenMode := scrmConfig; end; end;
if System.HPrevInst = 0 then begin ZeroMemory(@WndClass, Sizeof(TWndClass));
with WndClass do begin Style := CS_VREDRAW or CS_HREDRAW or CS_SAVEBITS or CS_DBLCLKS; lpfnWndProc := @ScreenSaverProc; cbClsExtra := 0; cbWndExtra := 0; hbrBackground := GetStockObject(BLACK_BRUSH); lpszMenuName := nil; lpszClassName := WndClassName; hInstance := hInstance; hIcon := LoadIcon(0, IDI_APPLICATION); hCursor := LoadCursor(0, IDC_ARROW); end; RegisterClass(WndClass); end;
if ScreenMode = scrmStart then begin GetClientRect(GetDesktopWindow, WndRect); AppHWND := CreateWindowEx( WS_EX_TOPMOST, WndClassName, AppName, WS_VISIBLE or WS_POPUP , WndRect.Left, WndRect.Top, WndRect.Right, WndRect.Bottom, 0, 0, hInstance, nil); end else if ScreenMode = scrmPreview then begin ParentWnd := _StrToInt(ParamStr(2)); GetClientRect(ParentWnd, WndRect); AppHWND := CreateWindow( WndClassName, AppName, WS_CHILD or WS_VISIBLE, WndRect.Left, WndRect.Top, WndRect.Right, WndRect.Bottom, ParentWnd, 0, hInstance, nil); end else begin DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLG), AppHWND, @DlgProc); PostQuitMessage(0); end;
UpdateWindow(AppHWND);
while GetMessage(msg, 0, 0, 0) do begin TranslateMessage(msg); DispatchMessage(msg); end;
ExitCode := msg.wParam;
END. |