le plus court et le plus simple screensaver!!!!
utilise la lib scrnsave.lib de windows
fait des ronds sur l ecran vielle bouge la sourit pour changer
forme
utilise ScreenSaverProc pour demarer l application
et non int APIENTRY WinMain()
Source / Exemple :
#include <windows.h>
#include <scrnsave.h>
#include <math.h>
#include <commctrl.h>
#pragma comment(lib,"scrnsave.lib")
#pragma comment(lib,"comctl32.lib")
int delay=8;
const double Pi=3.1415926;
int Rand(int);
int Rand(int nMax)
{
static long seed=GetTickCount();
seed=(25173*seed+13849)%65535;
return abs(seed%nMax);
}
BOOL WINAPI ScreenSaverConfigureDialog(HWND hwnd,UINT message,
WPARAM wParam,LPARAM lParam)
{
return 0;
}
BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
{
return 1;
}
LRESULT WINAPI ScreenSaverProc(HWND hwnd,UINT message,
WPARAM wParam,LPARAM lParam)
{
static HDC hdc;
static RECT scr_dim;
static SIZE size;
static HBRUSH hBlk_Brush;
static int d=1,c=1,q=3,center_x,center_y,hs,vs;
static long red,green,blue;
int i,x,y;
double xs,ys,temp,k=0.2;
switch(message)
{
case WM_CREATE:
SetTimer(hwnd,1,delay,NULL);
hBlk_Brush=(HBRUSH)GetStockObject(BLACK_BRUSH);//Background Black
red=Rand(256);
green=Rand(256);
blue=Rand(256);
hs=GetSystemMetrics(SM_CXSCREEN)/30;
vs=GetSystemMetrics(SM_CYSCREEN)/30;
//hs=GetSystemMetrics(SM_CXVIRTUALSCREEN)/30;
//vs=GetSystemMetrics(SM_CYVIRTUALSCREEN)/30;
break;
case WM_ERASEBKGND:
hdc=GetDC(hwnd);
GetClientRect(hwnd,&scr_dim);
center_x=(scr_dim.right-scr_dim.left)/2;
center_y=(scr_dim.bottom-scr_dim.top)/2;
SelectObject(hdc,hBlk_Brush);
PatBlt(hdc,0,0,scr_dim.right,scr_dim.bottom,PATCOPY);
ReleaseDC(hwnd,hdc);
break;
case WM_MOUSEMOVE:
c = 25;
case WM_TIMER:
hdc=GetDC(hwnd);
///ys=d/3.0;
//xs=c/3.0;
ys=d/3.5;
xs=c/3.5;
for(i=0;i<1000;i++)
{
temp=(xs+k*sin(ys))*cos(2*Pi/q)+ys*sin(2*Pi/q);
ys=-(xs+k*sin(ys))*sin(2*Pi/q)+ys*cos(2*Pi/q);
xs=temp;
x=(int)(xs*hs);
y=(int)(ys*vs);
if(i>10) {
SetPixel(hdc,x+center_x,center_y-y,RGB(red,green,blue));
SetPixel(hdc,x+80,center_y-y,RGB(green,blue,red));
//SetPixel(hdc,x+80,center_y-y,RGB(i,i,i));
SetPixel(hdc,GetSystemMetrics(SM_CXSCREEN)-x,center_y-y,RGB(blue,red,green));
}
}
c++;
if(c>24)
{
c=1;
d++;
if(d>24)
{
d=1;
q++;
SelectObject(hdc,hBlk_Brush);
PatBlt(hdc,0,0,scr_dim.right,scr_dim.bottom,PATCOPY);
red=Rand(256);
green=Rand(256);
blue=Rand(256);
if(q>12)
{
q=3;
c=1;
d=1;
}
}
}
ReleaseDC(hwnd,hdc);
break;
case WM_DESTROY:
KillTimer(hwnd,1);
break;
default:
return DefScreenSaverProc(hwnd,message,wParam,lParam);
}
return 0;
}
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.