/* mingwscr.c */ #include #include #include #include #include #define ID_TIMER 101 void DrawScreenSaver(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { HDC hdc; RECT rc; HPEN hPen; int i, x, y, l, r, g, b; /* Draw circles at random sizes and locations */ hdc = GetDC(hWnd); GetClientRect(hWnd, &rc); x = rand() % rc.right; y = rand() % rc.bottom; l = rand() % rc.right / 6; r = rand() % 256; g = rand() % 256; b = rand() % 256; /* set large pen size */ hPen = CreatePen(PS_SOLID, l, RGB(r, g, b)); SelectObject(hdc, hPen); /* draw point. pen size is large */ MoveToEx(hdc, x, y, NULL); LineTo(hdc, x, y); ReleaseDC(hWnd, hdc); } /* screensaver main processing */ LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: /* initialize */ SetTimer(hWnd, ID_TIMER, 33, NULL); /* create timer */ srand((unsigned)time(NULL)); break; case WM_TIMER: /* main loop */ DrawScreenSaver(hWnd, msg, wParam, lParam); break; case WM_DESTROY: KillTimer(hWnd, ID_TIMER); /* kill timer */ PostQuitMessage(0); break; default: break; } return DefScreenSaverProc(hWnd, msg, wParam, lParam); } /* Processing of dialog boxes for configuration */ BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: MessageBox( hDlg, _T("This screen saver has no configuration options."), _T("Sample Screensaver by using MinGW"), MB_OK | MB_ICONWARNING); EndDialog(hDlg, IDOK); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; } return FALSE; } return FALSE; } /* Register non-standard window classes required by dialog boxes for configuration */ BOOL WINAPI RegisterDialogClasses(HANDLE hInst) { return TRUE; }