ECRAN VEILLE LE PLUS BASIC

gagah1 Messages postés 509 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 3 août 2010 - 3 juil. 2008 à 16:23
gagah1 Messages postés 509 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 3 août 2010 - 3 juil. 2008 à 19:40
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/47173-ecran-veille-le-plus-basic

gagah1 Messages postés 509 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 3 août 2010
3 juil. 2008 à 19:40
M_PI est déjà défini dans math.h
Je parle de symetrie, le positionnement des 2 effets par rapport à celui du centre.
f_l_a_s_h_b_a_c_k Messages postés 56 Date d'inscription vendredi 14 avril 2006 Statut Membre Dernière intervention 1 février 2009
3 juil. 2008 à 19:31
"3 effets ne sont pas symetriques"

moi mon ordi a 2 ecran et il marche ok,
je l ai pas tester sur 1 ecran...

jái tester t a source ses cool!
ses different je vois plus l ecran en noir :)

il a fallu que je modifie

int Rand(int nMax)
{
return rand()%nMax;
}

et que je rajoute #define M_PI 3.14159
gagah1 Messages postés 509 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 3 août 2010
3 juil. 2008 à 16:23
Pas mal pour une source basic.
J'ai modifié la source pour mettre la capture d'écran en image de fond. Et comme les 3 effets ne sont pas symetriques, je ne retient que celui du centre, j'ai remplacé pi par le macro M_PI:


#include <windows.h>
#include <scrnsave.h>
#include <math.h>
#include <commctrl.h>

int delay = 8;
int Rand(int);

int Rand(int nMax)
{
rand()%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 HBITMAP hbmp;
static RECT scr_dim;
static SIZE size;
static int d=1, c=1, q=3, center_x, center_y, hs, vs;
static int screenWidth, screenHeight;
static long red,green,blue;
HDC hdc, hdcMem;
int i,x,y;
double xs, ys, temp, k=0.2;

switch(message)
{
case WM_CREATE:
srand(GetTickCount());
SetTimer(hwnd,1,delay,NULL);
red=Rand(256);
green=Rand(256);
blue=Rand(256);
hs = GetSystemMetrics(SM_CXSCREEN)/30;
vs = GetSystemMetrics(SM_CYSCREEN)/30;

screenWidth = GetSystemMetrics(SM_CXSCREEN);
screenHeight = GetSystemMetrics(SM_CYSCREEN);
hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
hdcMem = CreateCompatibleDC(hdc);

hbmp = CreateCompatibleBitmap(hdc, screenWidth, screenHeight );
SelectObject (hdcMem, hbmp);
BitBlt(hdcMem, 0, 0, screenWidth, screenHeight, hdc, 0, 0, SRCCOPY);

DeleteDC(hdc);
DeleteDC(hdcMem);

break;
case WM_ERASEBKGND:
hdc = GetDC(hwnd);
hdcMem = CreateCompatibleDC(hdc);
GetClientRect(hwnd, &scr_dim);
center_x = (scr_dim.right - scr_dim.left)/2;
center_y = (scr_dim.bottom - scr_dim.top)/2;
SelectObject(hdcMem, hbmp);
BitBlt(hdc, 0, 0, screenWidth, screenHeight, hdcMem, 0, 0, SRCCOPY);

DeleteDC(hdcMem);
ReleaseDC(hwnd, hdc);
break;

case WM_TIMER:
hdc = GetDC(hwnd);
hdcMem = CreateCompatibleDC(hdc);

ys = d/3.0;
xs = c/3.0;

for(i=0; i<1000; i++)
{
temp =(xs + k*sin(ys))*cos(2*M_PI/q) + ys*sin(2*M_PI/q);
ys = -(xs + k*sin(ys))*sin(2*M_PI/q) + ys*cos(2*M_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));
}
c++;
if(c>24)
{
c=1;
d++;
if(d>24)
{
d=1;
q++;
SelectObject(hdcMem, hbmp);
BitBlt(hdc, 0, 0, screenWidth, screenHeight, hdcMem, 0, 0, SRCCOPY);
red=Rand(256);
green=Rand(256);
blue=Rand(256);
if(q>12)
{
q=3;
c=1;
d=1;
}
}
}
DeleteDC(hdcMem);
ReleaseDC(hwnd,hdc);
break;

case WM_DESTROY:
KillTimer(hwnd,1);
DeleteObject(hbmp);
break;

default:
return DefScreenSaverProc(hwnd,message,wParam,lParam);
}
return 0;
}
Rejoignez-nous