begin process at 2008 08 29 22:49:28
1 233 930 membres
450 nouveaux aujourd'hui
14 294 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

ECRAN VEILLE LE PLUS BASIC


Description

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

  • #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;
  • }
#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;
}

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

  • signaler à un administrateur
    Commentaire de gagah1 le 03/07/2008 16:23:42

    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;
    }

  • signaler à un administrateur
    Commentaire de f_l_a_s_h_b_a_c_k le 03/07/2008 19:31:05

    "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








  • signaler à un administrateur
    Commentaire de gagah1 le 03/07/2008 19:40:26

    M_PI est déjà défini dans math.h
    Je parle de symetrie, le positionnement des 2 effets par rapport à celui du centre.

Ajouter un commentaire

Discussions en rapport avec ce code source

SetPixel() ... par payen

GROS probleme :( par morgandetoi06

OpenGL & ScreenSaver ? par ParMesSoins

GetPixel / SetPixel par glipper

SetPixel et GetPixel par Adeon

SetPixel(hdc,i,j,RGB..) peut-on utiliser autre chose que RGB par izle

GetPixel par elflink

API Setpixel par Stephane

Gestion des couleurs par lilington

Setpixel par 69lion69

Pub



Appels d'offres

Recherche developpeur ...
Budget : 700€
SITE MARCHAND LOCATION...
Budget : 3 000€
SITE MARCHAND POUR HOTEL
Budget : 4 000€

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Boutique

Boutique de goodies CodeS-SourceS