begin process at 2012 02 12 00:41:02
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

API

 > PROGRESS BAR COLOR

PROGRESS BAR COLOR


 Information sur la source

Note :
4,33 / 10 - par 3 personnes
4,33 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :API Niveau :Débutant Date de création :28/02/2004 Vu / téléchargé :6 035 / 571

Auteur : melkiorlenecrarque

Ecrire un message privé
Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

 Description

hello!

ben c'est programme qui utilise une progress bar avec un dégradé de couleur!
ne m'en demandez pas l'utilitée!
c'est egalement un exemple de création de thread

Source

  • #include <windows.h>
  • #include "resource.h"
  • #include <commctrl.h>
  • // variables globale
  • HWND hDlg;
  • HINSTANCE hinst;
  • HINSTANCE hinst2;
  • HANDLE SecondThread;
  • DWORD ThreadID;
  • HWND hProgress;
  • int val_choix_fix;
  • int vitesse;
  • HICON hIcon;
  • // prototype des fonctions
  • BOOL CALLBACK AppProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam);
  • BOOL CALLBACK AbtProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam);
  • DWORD WINAPI ThreadProc(LPVOID lpParameter);
  • void about();
  • void generer();
  • // fonction gérant les message concernant la boite de dialogue principale
  • BOOL CALLBACK AppProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
  • {
  • switch(msg)
  • {
  • case WM_INITDIALOG:
  • {
  • hDlg=hdlg;
  • hIcon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_ICON1)); // charge l'icone.....
  • SetClassLong(hdlg, GCL_HICON, (long)hIcon); // ... et l'affiche
  • hProgress = GetDlgItem(hDlg, IDC_PROGRESS);
  • vitesse = 50;
  • }
  • case WM_COMMAND:
  • switch(wParam)
  • {
  • case IDC_LANCER:
  • generer();
  • break;
  • case IDC_ABOUT:
  • about();
  • break;
  • case IDC_STOP:
  • TerminateThread(SecondThread,NULL);
  • break;
  • case IDCANCEL:
  • EndDialog(hDlg,0);
  • }
  • default:
  • break;
  • }
  • return 0;
  • }
  • // fonction gérant les messages concernant la fenetre a propos de...
  • BOOL CALLBACK AbtProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
  • {
  • switch(msg)
  • {
  • case WM_INITDIALOG:
  • break;
  • case WM_COMMAND:
  • switch(wParam)
  • {
  • case IDCANCEL:
  • EndDialog(hdlg,0);
  • }
  • default:
  • break;
  • }
  • return 0;
  • }
  • // fonction principale, c'est la premiere executée
  • int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
  • {
  • hinst = hInstance;
  • DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), hDlg, AppProc);
  • return 0;
  • }
  • // voici les fonctions!
  • void about()
  • {
  • DialogBox(hinst2, MAKEINTRESOURCE(IDD_DIALOG_2), hDlg, AbtProc);
  • }
  • void generer()
  • {
  • TerminateThread(SecondThread,NULL);
  • SecondThread = CreateThread(NULL,NULL,ThreadProc,NULL,NULL,&ThreadID);
  • }
  • DWORD WINAPI ThreadProc(LPVOID lpParameter) // fonction executée par le thread
  • {
  • int R;
  • int G;
  • val_choix_fix = 700;
  • SendMessage(hProgress, PBM_SETRANGE, 0, MAKELPARAM (0, val_choix_fix));
  • for(int a = 0;a<=val_choix_fix;a++)
  • {
  • R=255;
  • G=0;
  • if(a<(val_choix_fix/2))
  • {
  • R = 255;
  • G = (255*a)/(val_choix_fix/2);
  • }
  • if(a>=(val_choix_fix/2))
  • {
  • G = 255;
  • R = 2*(255-((255*a)/(val_choix_fix)));
  • R--;
  • if(R<0)
  • R=0;
  • }
  • SetDlgItemInt(hDlg,IDC_EDIT_R,R,FALSE);
  • SetDlgItemInt(hDlg,IDC_EDIT_G,G,FALSE);
  • SendMessage(hProgress, PBM_SETBARCOLOR , 0 , RGB(R,G,0));
  • SendMessage(hProgress, PBM_SETPOS, (WPARAM) a, 0);
  • SetDlgItemInt(hDlg,IDC_VALEUR,a,FALSE);
  • Sleep(vitesse);
  • }
  • return 0;
  • }
#include <windows.h>
#include "resource.h"
#include <commctrl.h>

//	variables globale
HWND hDlg;
HINSTANCE hinst;
HINSTANCE hinst2;
HANDLE SecondThread;
DWORD ThreadID;
HWND hProgress;
int val_choix_fix;
int vitesse;
HICON hIcon;

//	prototype des fonctions
BOOL CALLBACK AppProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK AbtProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam);
DWORD WINAPI ThreadProc(LPVOID lpParameter);
void about();
void generer();

//	fonction gérant les message concernant la boite de dialogue principale
BOOL CALLBACK AppProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
  switch(msg) 
  {
     case WM_INITDIALOG:
		 {
		 hDlg=hdlg;
		 hIcon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_ICON1));     //   charge l'icone.....
		 SetClassLong(hdlg, GCL_HICON, (long)hIcon);			 //   ... et l'affiche
		 hProgress = GetDlgItem(hDlg, IDC_PROGRESS);
		 vitesse = 50;
		 }
     case WM_COMMAND:
      switch(wParam) 
	  {
	  case IDC_LANCER:
		  generer();
		  break;
	  case IDC_ABOUT:
		  about();
		  break;
	  case IDC_STOP:
		  TerminateThread(SecondThread,NULL);
		  break;
	  case IDCANCEL:
		  EndDialog(hDlg,0);
              }
	  default:
		  break;
  }
  return 0;
}

//	fonction gérant les messages concernant la fenetre a propos de...	
BOOL CALLBACK AbtProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
  switch(msg) 
  {
  case WM_INITDIALOG:
	  break;
  case WM_COMMAND:
      switch(wParam) 
	  {
	     case IDCANCEL: 
			EndDialog(hdlg,0);
                }
	  default:
		  break;
  }
  return 0;
}

//	fonction principale, c'est la premiere executée
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
{
	hinst = hInstance;
	DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), hDlg, AppProc);
    return 0;
}

//	voici les fonctions!
void about()
{
	DialogBox(hinst2, MAKEINTRESOURCE(IDD_DIALOG_2), hDlg, AbtProc);
}

void generer()
{
	TerminateThread(SecondThread,NULL);
	SecondThread = CreateThread(NULL,NULL,ThreadProc,NULL,NULL,&ThreadID);
}

DWORD WINAPI ThreadProc(LPVOID lpParameter)     //   fonction executée par le thread
{
	int R;
	int G;
	val_choix_fix = 700;
	SendMessage(hProgress, PBM_SETRANGE, 0, MAKELPARAM (0, val_choix_fix));
	for(int a = 0;a<=val_choix_fix;a++)
	{
		R=255;
		G=0;
		if(a<(val_choix_fix/2))
	{
		R = 255;
		G = (255*a)/(val_choix_fix/2);
	}
	if(a>=(val_choix_fix/2))
	{
		G = 255;
		R = 2*(255-((255*a)/(val_choix_fix)));
		R--;
		if(R<0)
			R=0;
		
	}
		SetDlgItemInt(hDlg,IDC_EDIT_R,R,FALSE);
		SetDlgItemInt(hDlg,IDC_EDIT_G,G,FALSE);
		SendMessage(hProgress, PBM_SETBARCOLOR , 0 , RGB(R,G,0));
		SendMessage(hProgress, PBM_SETPOS, (WPARAM) a, 0);
		SetDlgItemInt(hDlg,IDC_VALEUR,a,FALSE);
		Sleep(vitesse);
	}
	return 0;
}

 Conclusion

je vais ajouter un slider pour modifier la vitesee, mais je ne sais pas encore l'utiliser!

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture GESTION DES SERVICES
Source avec Zip Source avec une capture DÉ VIRTUEL POUR WINDOWS
Source avec Zip RESOLUTION DE COMBAT WARHAMMER V1.3

 Sources de la même categorie

Source avec Zip WIN32 TLS LENT par dguilmain
Source avec Zip VIDER ELEMENTS DE CORBEILLE WINDOWS7 (WIN64) par BruNews
Source avec Zip Source avec une capture FIND TEXT (WIN64) par BruNews
Source avec Zip DELETE DIRECTORY (WIN64) par BruNews
Source avec Zip ENUM DIRECTORY (WIN64) par BruNews

Commentaires et avis

Commentaire de wxccxw le 22/05/2006 12:47:00

un sleep dans une API WINDOWS ? heu Oo Ta pas quelque bug ?

Commentaire de hakim0 le 24/06/2006 13:52:21

salut,
ca marche pas sur visual c++ 6,
il n ya pas des erreurs de syntax..
je crois qu'on doit initializer les controls avec InitCommonControls();
mais aussi ca marche pas.??

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 2,512 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales