begin process at 2008 07 06 00:59:26
1 205 425 membres
7 nouveaux aujourd'hui
14 119 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 !

CALCULER SES MOYENNES


Information sur la source

Catégorie :Application Classé sous : moyennes, graphe, graphique, win32, dialog Niveau : Débutant Date de création : 15/04/2008 Date de mise à jour : 15/04/2008 10:03:51 Vu / téléchargé: 2 247 / 131

Note :
Aucune note

Commentaire sur cette source (7)
Ajouter un commentaire et/ou une note

Description

Voila mon premier programme en C (je n'avais jamais touché à ce langage avant), il n'est pas vraiment révolutionnaire mais permet de calculer simplement ses moyennes (donc destiné aux étudiants) selon certains paramètres, et d'afficher les résultats dans un graphe.
Ce que je trouve assez sympa, c'est qu'il ne prend que 46Ko (ce qui est moins que le bloc note de 69Ko).

(Attention, j'ai utilisé win32 donc le programme tourne uniquement sous Windows)

Source

  • #include <windows.h>
  • #include <string.h>
  • #include <stdio.h>
  • #include <stdlib.h>
  • #define ID_OK 16
  • #define ID_ANNULER 5
  • #define ID_RECOMMENCER 6
  • #define ID_TEXTE 1
  • #define ID_TEXTE_BACKGROUND 137
  • #define ID_LIST 2
  • #define ID_EDIT 3
  • #define ID_COMBO 4
  • #define ID_BACKGROUND 44
  • #define ID_BOX 14
  • #define ID_GOBACK 100
  • #define ID_ENREGISTRER 134
  • #define ID_IMPRIMER 135
  • #define ID_CHECK 133
  • #define ID_COEFF05 7
  • #define ID_COEFF1 8
  • #define ID_COEFF2 9
  • #define ID_COEFFAUTRE 10
  • #define ID_NOTE 45
  • #define ID_COEFF 46
  • #define ID_BOX2 47
  • #define ID_ABOUT 48
  • #define ID_EXEMPLE 49
  • #define ID_LTEXT 101
  • #define ID_EDITTEXT 102
  • #define ID_SOK 103
  • //Variables globales et prototypes
  • HINSTANCE hinst;
  • void Refresh(HWND hwnd);
  • void Draw(HWND hwnd);
  • LRESULT CALLBACK MainWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
  • BOOL APIENTRY Dialog1Proc(HWND,UINT,WPARAM,LPARAM);
  • int nbritem=0;
  • char nbritem2[100];
  • float afficheMoy=0;
  • HWND hwnd;
  • //Déclaration de la fenêtre
  • int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {
  • //Variables
  • MSG msg;
  • hinst=hinstance;
  • static HWND texte,ok,edit,annuler,recommencer,texte_background,list,combo,background,box,box2,goback,enregistrer,imprimer,
  • check,coeff05,coeff1,coeff2,coeffautre,coeff,note,about;
  • //Paramètres de la fenêtre
  • WNDCLASS wc;
  • wc.style=0;
  • wc.lpfnWndProc=MainWndProc;
  • wc.cbClsExtra=0;
  • wc.cbWndExtra=0;
  • wc.hInstance=hinstance;
  • wc.hIcon=LoadIcon(hinstance,MAKEINTRESOURCE(1));
  • wc.hCursor=LoadCursor(NULL,IDC_ARROW);
  • wc.hbrBackground=(HBRUSH)(COLOR_3DFACE+1);
  • wc.lpszMenuName= NULL;
  • wc.lpszClassName="MaWinClass";
  • if(!RegisterClass(&wc)) return FALSE;
  • //Création de la fenêtre
  • hwnd=CreateWindowEx(WS_EX_WINDOWEDGE,"MaWinClass","Aucune valeur",WS_CAPTION|WS_MINIMIZEBOX|WS_SYSMENU,CW_USEDEFAULT,CW_USEDEFAULT,320,275,HWND_DESKTOP,NULL,hinstance,NULL);
  • //Mise en place des contrôles
  • box=CreateWindowEx(0,"BUTTON","Aucune valeur",SS_LEFT|WS_CHILD|WS_VISIBLE|BS_GROUPBOX,10,10,280,225,hwnd,ID_BOX,hinstance,NULL);
  • SendMessage(box,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • box2=CreateWindowEx(0,"BUTTON","Graphique :",SS_LEFT|WS_CHILD|WS_VISIBLE|BS_GROUPBOX,90,242,200,58,hwnd,ID_BOX2,hinstance,NULL);
  • SendMessage(box2,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • edit=CreateWindowEx(WS_EX_STATICEDGE|WS_EX_CLIENTEDGE,"EDIT","12.5",WS_CHILD|WS_VISIBLE|WS_EX_CLIENTEDGE|WS_EX_STATICEDGE,110,40,55,20,hwnd,ID_EDIT,hinstance,NULL);
  • SendMessage(edit,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • texte_background=CreateWindowEx(WS_EX_STATICEDGE,"STATIC","",SS_LEFT|WS_CHILD|WS_VISIBLE,110,150,170,74,hwnd,ID_TEXTE_BACKGROUND,hinstance,NULL);
  • SendMessage(texte_background,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • texte=CreateWindowEx(0,"STATIC","Astuce : Pensez à ramener vos notes sur 20 afin que les coefficients (s'ils sont activés) soient proportionnels.",WS_CHILD|WS_VISIBLE,120,160,150,60,hwnd,ID_TEXTE,hinstance,NULL);
  • SendMessage(texte,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • ok=CreateWindowEx(0,"BUTTON","OK",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,170,40,30,20,hwnd,ID_OK,hinstance,NULL);
  • SendMessage(ok,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • annuler=CreateWindowEx(0,"BUTTON","Annuler",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_DISABLED,110,70,90,20,hwnd,ID_ANNULER,hinstance,NULL);
  • SendMessage(annuler,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • recommencer=CreateWindowEx(0,"BUTTON","Recommencer",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_DISABLED,110,90,90,20,hwnd,ID_RECOMMENCER,hinstance,NULL);
  • SendMessage(recommencer,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • list=CreateWindowEx(WS_EX_STATICEDGE,"LISTBOX","",WS_CHILD|WS_VISIBLE|WS_VSCROLL,20,40,80,200,hwnd,ID_LIST,hinstance,NULL);
  • SendMessage(list,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • combo=CreateWindowEx(0,"COMBOBOX","",WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,110,120,170,0,hwnd,ID_COMBO,hinstance,NULL);
  • SendMessage(combo,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • goback=CreateWindowEx(WS_EX_STATICEDGE,"BUTTON",">",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,295,35,15,40,hwnd,ID_GOBACK,hinstance,NULL);
  • SendMessage(goback,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • enregistrer=CreateWindowEx(0,"BUTTON","Enregistrer",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_DISABLED,95,255,90,20,hwnd,ID_ENREGISTRER,hinstance,NULL);
  • SendMessage(enregistrer,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • imprimer=CreateWindowEx(0,"BUTTON","Imprimer",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_DISABLED,95,275,90,20,hwnd,ID_IMPRIMER,hinstance,NULL);
  • SendMessage(imprimer,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • check=CreateWindowEx(0,"BUTTON","Afficher la grille",WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,195,275,88,20,hwnd,ID_CHECK,hinstance,NULL);
  • SendMessage(check,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • background=CreateWindowEx(WS_EX_STATICEDGE,"STATIC","",SS_LEFT|WS_CHILD|WS_VISIBLE,205,40,75,70,hwnd,ID_BACKGROUND,hinstance,NULL);
  • SendMessage(background,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • coeff05=CreateWindowEx(0,"BUTTON","0.5",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,210,44,69,17,hwnd,ID_COEFF05,hinstance,NULL);
  • SendMessage(coeff05,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • coeff1=CreateWindowEx(0,"BUTTON","1",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,210,59,69,17,hwnd,ID_COEFF1,hinstance,NULL);
  • SendMessage(coeff1,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • coeff2=CreateWindowEx(0,"BUTTON","2",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,210,74,69,17,hwnd,ID_COEFF2,hinstance,NULL);
  • SendMessage(coeff2,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • coeffautre=CreateWindowEx(0,"BUTTON","autre...",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,210,89,69,17,hwnd,ID_COEFFAUTRE,hinstance,NULL);
  • SendMessage(coeffautre,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • note=CreateWindowEx(0,"STATIC","Note :",WS_CHILD|WS_VISIBLE,110,25,50,14,hwnd,ID_NOTE,hinstance,NULL);
  • SendMessage(note,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • coeff=CreateWindowEx(0,"STATIC","Coefficient :",WS_CHILD|WS_VISIBLE,205,25,60,14,hwnd,ID_COEFF,hinstance,NULL);
  • SendMessage(coeff,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • note=CreateWindowEx(0,"STATIC","Note (coefficient)",WS_CHILD|WS_VISIBLE,20,25,90,14,hwnd,ID_EXEMPLE,hinstance,NULL);
  • SendMessage(note,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • about=CreateWindowEx(WS_EX_STATICEDGE,"BUTTON","A propos...",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,10,274,70,22,hwnd,ID_ABOUT,hinstance,NULL);
  • SendMessage(about,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
  • SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_ADDSTRING,0,"Moyenne (avec coefficients)");
  • SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_ADDSTRING,0,"Moyenne (sans coefficients)");
  • SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_ADDSTRING,0,"Nombre de notes >= 10");
  • SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_ADDSTRING,0,"Nombre de notes < 10");
  • SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_ADDSTRING,0,"Etendue (différence max - min)");
  • SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_SELECTSTRING,0,"Moyenne (avec coefficients)");
  • CheckDlgButton(hwnd,ID_COEFF1,BST_CHECKED);
  • if (!hwnd) return FALSE;
  • ShowWindow(hwnd,nCmdShow);
  • while (GetMessage(&msg,NULL,0,0)) {
  • TranslateMessage(&msg);
  • DispatchMessage(&msg);
  • }
  • return msg.wParam;
  • }
  • //Traitement des messages Client-Machine
  • LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  • switch (uMsg) {
  • case WM_COMMAND:
  • switch (LOWORD(wParam)) {
  • case ID_COEFFAUTRE:
  • DialogBox(hinst,"DIALOG1",hwnd,(DLGPROC)Dialog1Proc);
  • break;
  • case ID_GOBACK:
  • {
  • RECT area;
  • GetWindowRect(hwnd,&area);
  • int width=area.right-area.left;
  • if (width == 320) {
  • SetWindowPos(hwnd,0,area.left,area.top,800,350,0);
  • SetDlgItemText(hwnd,ID_GOBACK,"<");
  • }
  • else {
  • SetWindowPos(hwnd,0,area.left,area.top,320,275,0);
  • SetDlgItemText(hwnd,ID_GOBACK,">");
  • }
  • break;
  • }
  • case ID_COMBO:
  • nbritem=SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETCOUNT,0,0);
  • if (nbritem > 0) Refresh(hwnd);
  • break;
  • case ID_ANNULER:
  • nbritem=SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETCOUNT,0,0)-1;
  • SendMessage(GetDlgItem(hwnd,ID_LIST),LB_DELETESTRING,nbritem,NULL);
  • Refresh(hwnd);
  • break;
  • case ID_RECOMMENCER:
  • while (SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETCOUNT,0,0)*2) {
  • SendMessage(GetDlgItem(hwnd,ID_LIST),LB_DELETESTRING,0,NULL);
  • }
  • SetDlgItemText(hwnd,ID_EDIT,"");
  • SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_SELECTSTRING,0,"Moyenne (avec coefficients)");
  • CheckDlgButton(hwnd,ID_COEFF05,BST_UNCHECKED);
  • CheckDlgButton(hwnd,ID_COEFF1,BST_UNCHECKED);
  • CheckDlgButton(hwnd,ID_COEFF2,BST_UNCHECKED);
  • CheckDlgButton(hwnd,ID_COEFFAUTRE,BST_UNCHECKED);
  • CheckDlgButton(hwnd,ID_COEFF1,BST_CHECKED);
  • SetDlgItemText(hwnd,ID_COEFFAUTRE,"autre...");
  • Refresh(hwnd);
  • break;
  • case ID_CHECK:
  • Refresh(hwnd);
  • InvalidateRect(hwnd,NULL,FALSE);
  • UpdateWindow(hwnd);
  • break;
  • case ID_OK:
  • {
  • char text[10];
  • GetWindowText(GetDlgItem(hwnd,ID_EDIT),text,10);
  • int text2=atoi(text),a=1;
  • while (a<=20) {
  • if (text2 == a) {
  • int b=7;
  • while (b<=10) {
  • if (IsDlgButtonChecked(hwnd,b)) {
  • char textcoeff[5];
  • double verif=1.5;
  • GetWindowText(GetDlgItem(hwnd,b),textcoeff,10);
  • if (strchr(textcoeff,'a') != NULL) {
  • sscanf(textcoeff,"autre: %lf",&verif);
  • sprintf(textcoeff,"%lf",verif);
  • }
  • char par1[]=" (";
  • char par2[]=")";
  • strcat(par1,textcoeff);
  • strcat(par1,par2);
  • SendMessage(GetDlgItem(hwnd,ID_LIST),LB_ADDSTRING,0,strcat(text,par1));
  • EnableWindow(GetDlgItem(hwnd,ID_ANNULER),TRUE);
  • EnableWindow(GetDlgItem(hwnd,ID_RECOMMENCER),TRUE);
  • Refresh(hwnd);
  • break;
  • }
  • b++;
  • }
  • }
  • a++;
  • }
  • break;
  • }
  • case ID_ABOUT:
  • MessageBox(hwnd,"- Moyennes -\nLogiciel pour calculer ses moyennes\n(copyrights © WINKEL Vincent)","A propos...",MB_OK|MB_ICONASTERISK);
  • break;
  • }
  • case WM_PAINT:
  • Draw(hwnd);
  • break;
  • case WM_DESTROY:
  • PostQuitMessage(0);
  • break;
  • default:
  • return DefWindowProc(hwnd,uMsg,wParam,lParam);
  • }
  • }
  • //Aliases de raccourci (traitement du graphique)
  • void Refresh(HWND hwnd) {
  • nbritem=SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETCOUNT,0,0);
  • if (nbritem > 0) {
  • char textitem[100];
  • GetDlgItemText(hwnd,ID_COMBO,textitem,100);
  • char item1[]="Moyenne (avec coefficients)";
  • char item2[]="Moyenne (sans coefficients)";
  • char item3[]="Nombre de notes >= 10";
  • char item4[]="Nombre de notes < 10";
  • char item5[]="Etendue (différence max - min)";
  • int a=0;
  • double nbr=0,nbr2=0,note=0,coeff=0;
  • char text[20],texttitle[200];
  • if (strcmp(textitem,item1) == 0) {
  • while (a<nbritem) {
  • SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
  • sscanf(text,"%lf (%lf)",&note,&coeff);
  • nbr+=note*coeff;
  • nbr2+=coeff;
  • a++;
  • }
  • afficheMoy=nbr/nbr2;
  • sprintf(texttitle,"Moyenne (avec coefficients): %.2f",afficheMoy);
  • SetDlgItemText(hwnd,ID_BOX,texttitle);
  • SetWindowText(hwnd,texttitle);
  • }
  • else if (strcmp(textitem,item2) == 0) {
  • while (a<nbritem) {
  • SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
  • sscanf(text,"%lf (%lf)",&note,&coeff);
  • nbr+=note;
  • a++;
  • }
  • afficheMoy=nbr/nbritem;
  • sprintf(texttitle,"Moyenne (sans coefficients): %.2f",afficheMoy);
  • SetDlgItemText(hwnd,ID_BOX,texttitle);
  • SetWindowText(hwnd,texttitle);
  • }
  • if (strcmp(textitem,item3) == 0) {
  • while (a<nbritem) {
  • SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
  • sscanf(text,"%lf (%lf)",&note,&coeff);
  • if (note >= 10) nbr++;
  • nbr2++;
  • a++;
  • }
  • coeff=(nbr*100)/nbr2;
  • sprintf(texttitle,"Notes >= 10: %.0f/%.0f (%.1f %%)",nbr,nbr2,coeff);
  • SetDlgItemText(hwnd,ID_BOX,texttitle);
  • SetWindowText(hwnd,texttitle);
  • }
  • else if (strcmp(textitem,item4) == 0) {
  • while (a<nbritem) {
  • SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
  • sscanf(text,"%lf (%lf)",&note,&coeff);
  • if (note < 10) nbr++;
  • nbr2++;
  • a++;
  • }
  • coeff=(nbr*100)/nbr2;
  • sprintf(texttitle,"Notes < 10: %.0f/%.0f (%.1f %%)",nbr,nbr2,coeff);
  • SetDlgItemText(hwnd,ID_BOX,texttitle);
  • SetWindowText(hwnd,texttitle);
  • }
  • else if (strcmp(textitem,item5) == 0) {
  • if (nbritem <= 2) {
  • SetDlgItemText(hwnd,ID_BOX,"2 valeurs minimum sont requises");
  • SetWindowText(hwnd,"2 valeurs minimum sont requises");
  • }
  • else {
  • nbr=0,nbr2=20;
  • while (a<nbritem) {
  • SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
  • sscanf(text,"%lf (%lf)",&note,&coeff);
  • if (note > nbr) nbr=note;
  • else if (note < nbr2) nbr2=note;
  • a++;
  • }
  • nbr-=nbr2;
  • sprintf(texttitle,"Etendue des notes: %.2f",nbr);
  • SetDlgItemText(hwnd,ID_BOX,texttitle);
  • SetWindowText(hwnd,texttitle);
  • }
  • }
  • }
  • else {
  • SetDlgItemText(hwnd,ID_BOX,"Aucune valeur");
  • SetWindowText(hwnd,"Aucune valeur");
  • }
  • Draw(hwnd);
  • InvalidateRect(hwnd,NULL,FALSE);
  • UpdateWindow(hwnd);
  • }
  • void Draw(HWND hwnd) {
  • PAINTSTRUCT ps;
  • HDC hdc=BeginPaint(hwnd,&ps);
  • HPEN hp2px,hpOld;
  • HBRUSH brush;
  • HFONT NewFont,OldFont;
  • LOGFONT lf;
  • ZeroMemory(&lf,sizeof(LOGFONT));
  • lstrcpy(lf.lfFaceName,"Arial");
  • lf.lfHeight=12;
  • NewFont=CreateFontIndirect(&lf);
  • OldFont=SelectObject(hdc,NewFont);
  • //Initialisation du graphique
  • Rectangle(hdc,330,10,780,300);
  • MoveToEx(hdc,360,20,NULL);
  • LineTo(hdc,360,270);
  • MoveToEx(hdc,350,260,NULL);
  • LineTo(hdc,745,260);
  • //Ajout des graduations
  • int a=20,b=360,d=20;
  • char c[3];
  • while (a<=250) {
  • sprintf(c,"%d",d);
  • MoveToEx(hdc,358,a,NULL);
  • LineTo(hdc,360,a);
  • int l=strlen(c);
  • if (l == 2) TextOut(hdc,345,a-5,c,lstrlen(c));
  • else TextOut(hdc,350,a-5,c,lstrlen(c));
  • a+=12;
  • d--;
  • }
  • while (b<=750) {
  • MoveToEx(hdc,b,261,NULL);
  • LineTo(hdc,b,263);
  • b+=12;
  • }
  • //Ajout de texte
  • sprintf(nbritem2,"%d",nbritem);
  • char e[]="Total des notes: ";
  • char e2[]=" / 32";
  • strcat(e,nbritem2);
  • strcat(e,e2);
  • lf.lfHeight=15;
  • NewFont=CreateFontIndirect(&lf);
  • OldFont=SelectObject(hdc,NewFont);
  • TextOut(hdc,480,275,e,lstrlen(e));
  • //Traçage du graphique
  • hp2px=CreatePen(PS_SOLID,1,RGB(150,150,250));
  • hpOld=SelectObject(hdc,hp2px);
  • a=0,b=362;
  • char text[20];
  • while (a<=nbritem-1) {
  • if (a > 31) break;
  • SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
  • float nbr=atof(text);
  • SelectObject(hdc,GetStockObject(LTGRAY_BRUSH));
  • Rectangle(hdc,b,260-12*nbr,b+9,260);
  • a++;
  • b+=12;
  • }
  • //Affichage (ou non) de la grille
  • if (IsDlgButtonChecked(hwnd,ID_CHECK)) {
  • hp2px=CreatePen(PS_SOLID,1,RGB(200,200,200));
  • hpOld=SelectObject(hdc,hp2px);
  • int a=20,b=372;
  • while (a<=250) {
  • MoveToEx(hdc,361,a,NULL);
  • LineTo(hdc,745,a);
  • a+=12;
  • }
  • while (b<=750) {
  • MoveToEx(hdc,b,20,NULL);
  • LineTo(hdc,b,260);
  • b+=12;
  • }
  • }
  • //Affichage de la moyenne
  • if (nbritem > 0) {
  • hp2px=CreatePen(PS_SOLID,1,RGB(50,150,170));
  • hpOld=SelectObject(hdc,hp2px);
  • float nbr=260-12*afficheMoy;
  • MoveToEx(hdc,360,nbr,NULL);
  • LineTo(hdc,745,nbr);
  • lf.lfHeight=13;
  • NewFont=CreateFontIndirect(&lf);
  • OldFont=SelectObject(hdc,NewFont);
  • TextOut(hdc,700,nbr-13,"Moyenne",lstrlen("Moyenne"));
  • }
  • }
  • BOOL APIENTRY Dialog1Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
  • switch (uMsg) {
  • case WM_INITDIALOG:
  • return TRUE;
  • case WM_COMMAND:
  • if (LOWORD(wParam) == ID_SOK) {
  • char textedit[100]="";
  • GetDlgItemText(hDlg,ID_EDITTEXT,textedit,100);
  • int verif=atoi(textedit);
  • if (verif <= 0 || verif > 99)
  • if (MessageBox(hwnd,"Le coefficient doit être un nombre !","Erreur de syntaxe",MB_OKCANCEL|MB_ICONERROR) == IDCANCEL) EndDialog(hDlg,0);
  • else return FALSE;
  • else {
  • char textedit2[]="autre: ";
  • strcat(textedit2,textedit);
  • SetDlgItemText(hwnd,ID_COEFFAUTRE,textedit2);
  • EndDialog(hDlg,0);
  • return TRUE;
  • }
  • return FALSE;
  • }
  • break;
  • default:
  • return FALSE;
  • }
  • }
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#define ID_OK 16
#define ID_ANNULER 5
#define ID_RECOMMENCER 6
#define ID_TEXTE 1
#define ID_TEXTE_BACKGROUND 137
#define ID_LIST 2
#define ID_EDIT 3
#define ID_COMBO 4
#define ID_BACKGROUND 44
#define ID_BOX 14
#define ID_GOBACK 100
#define ID_ENREGISTRER 134
#define ID_IMPRIMER 135
#define ID_CHECK 133
#define ID_COEFF05 7
#define ID_COEFF1 8
#define ID_COEFF2 9
#define ID_COEFFAUTRE 10
#define ID_NOTE 45
#define ID_COEFF 46
#define ID_BOX2 47

#define ID_ABOUT 48
#define ID_EXEMPLE 49
#define ID_LTEXT 101
#define ID_EDITTEXT 102
#define ID_SOK 103
//Variables globales et prototypes
HINSTANCE hinst;
void Refresh(HWND hwnd);
void Draw(HWND hwnd);
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
BOOL APIENTRY Dialog1Proc(HWND,UINT,WPARAM,LPARAM);
int nbritem=0;
char nbritem2[100];
float afficheMoy=0;
HWND hwnd;
//Déclaration de la fenêtre
int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {
    //Variables
    MSG msg;
    hinst=hinstance;
    static HWND texte,ok,edit,annuler,recommencer,texte_background,list,combo,background,box,box2,goback,enregistrer,imprimer,
        check,coeff05,coeff1,coeff2,coeffautre,coeff,note,about;
    //Paramètres de la fenêtre
    WNDCLASS wc;
    wc.style=0;
    wc.lpfnWndProc=MainWndProc;
    wc.cbClsExtra=0;
    wc.cbWndExtra=0;
    wc.hInstance=hinstance;
    wc.hIcon=LoadIcon(hinstance,MAKEINTRESOURCE(1));
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    wc.hbrBackground=(HBRUSH)(COLOR_3DFACE+1);
    wc.lpszMenuName= NULL;
    wc.lpszClassName="MaWinClass";
    if(!RegisterClass(&wc)) return FALSE;
    //Création de la fenêtre
    hwnd=CreateWindowEx(WS_EX_WINDOWEDGE,"MaWinClass","Aucune valeur",WS_CAPTION|WS_MINIMIZEBOX|WS_SYSMENU,CW_USEDEFAULT,CW_USEDEFAULT,320,275,HWND_DESKTOP,NULL,hinstance,NULL);
    //Mise en place des contrôles
    box=CreateWindowEx(0,"BUTTON","Aucune valeur",SS_LEFT|WS_CHILD|WS_VISIBLE|BS_GROUPBOX,10,10,280,225,hwnd,ID_BOX,hinstance,NULL);
    SendMessage(box,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    box2=CreateWindowEx(0,"BUTTON","Graphique :",SS_LEFT|WS_CHILD|WS_VISIBLE|BS_GROUPBOX,90,242,200,58,hwnd,ID_BOX2,hinstance,NULL);
    SendMessage(box2,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    edit=CreateWindowEx(WS_EX_STATICEDGE|WS_EX_CLIENTEDGE,"EDIT","12.5",WS_CHILD|WS_VISIBLE|WS_EX_CLIENTEDGE|WS_EX_STATICEDGE,110,40,55,20,hwnd,ID_EDIT,hinstance,NULL);
    SendMessage(edit,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    texte_background=CreateWindowEx(WS_EX_STATICEDGE,"STATIC","",SS_LEFT|WS_CHILD|WS_VISIBLE,110,150,170,74,hwnd,ID_TEXTE_BACKGROUND,hinstance,NULL);
    SendMessage(texte_background,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    texte=CreateWindowEx(0,"STATIC","Astuce : Pensez à ramener vos notes sur 20 afin que les coefficients (s'ils sont activés) soient proportionnels.",WS_CHILD|WS_VISIBLE,120,160,150,60,hwnd,ID_TEXTE,hinstance,NULL);
    SendMessage(texte,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    ok=CreateWindowEx(0,"BUTTON","OK",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,170,40,30,20,hwnd,ID_OK,hinstance,NULL);
    SendMessage(ok,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    annuler=CreateWindowEx(0,"BUTTON","Annuler",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_DISABLED,110,70,90,20,hwnd,ID_ANNULER,hinstance,NULL);
    SendMessage(annuler,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    recommencer=CreateWindowEx(0,"BUTTON","Recommencer",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_DISABLED,110,90,90,20,hwnd,ID_RECOMMENCER,hinstance,NULL);
    SendMessage(recommencer,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    list=CreateWindowEx(WS_EX_STATICEDGE,"LISTBOX","",WS_CHILD|WS_VISIBLE|WS_VSCROLL,20,40,80,200,hwnd,ID_LIST,hinstance,NULL);
    SendMessage(list,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    combo=CreateWindowEx(0,"COMBOBOX","",WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,110,120,170,0,hwnd,ID_COMBO,hinstance,NULL);
    SendMessage(combo,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    goback=CreateWindowEx(WS_EX_STATICEDGE,"BUTTON",">",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,295,35,15,40,hwnd,ID_GOBACK,hinstance,NULL);
    SendMessage(goback,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    enregistrer=CreateWindowEx(0,"BUTTON","Enregistrer",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_DISABLED,95,255,90,20,hwnd,ID_ENREGISTRER,hinstance,NULL);
    SendMessage(enregistrer,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    imprimer=CreateWindowEx(0,"BUTTON","Imprimer",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_DISABLED,95,275,90,20,hwnd,ID_IMPRIMER,hinstance,NULL);
    SendMessage(imprimer,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    check=CreateWindowEx(0,"BUTTON","Afficher la grille",WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,195,275,88,20,hwnd,ID_CHECK,hinstance,NULL);
    SendMessage(check,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    background=CreateWindowEx(WS_EX_STATICEDGE,"STATIC","",SS_LEFT|WS_CHILD|WS_VISIBLE,205,40,75,70,hwnd,ID_BACKGROUND,hinstance,NULL);
    SendMessage(background,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    coeff05=CreateWindowEx(0,"BUTTON","0.5",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,210,44,69,17,hwnd,ID_COEFF05,hinstance,NULL);
    SendMessage(coeff05,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    coeff1=CreateWindowEx(0,"BUTTON","1",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,210,59,69,17,hwnd,ID_COEFF1,hinstance,NULL);
    SendMessage(coeff1,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    coeff2=CreateWindowEx(0,"BUTTON","2",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,210,74,69,17,hwnd,ID_COEFF2,hinstance,NULL);
    SendMessage(coeff2,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    coeffautre=CreateWindowEx(0,"BUTTON","autre...",WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,210,89,69,17,hwnd,ID_COEFFAUTRE,hinstance,NULL);
    SendMessage(coeffautre,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    note=CreateWindowEx(0,"STATIC","Note :",WS_CHILD|WS_VISIBLE,110,25,50,14,hwnd,ID_NOTE,hinstance,NULL);
    SendMessage(note,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    coeff=CreateWindowEx(0,"STATIC","Coefficient :",WS_CHILD|WS_VISIBLE,205,25,60,14,hwnd,ID_COEFF,hinstance,NULL);
    SendMessage(coeff,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    note=CreateWindowEx(0,"STATIC","Note (coefficient)",WS_CHILD|WS_VISIBLE,20,25,90,14,hwnd,ID_EXEMPLE,hinstance,NULL);
    SendMessage(note,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    about=CreateWindowEx(WS_EX_STATICEDGE,"BUTTON","A propos...",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,10,274,70,22,hwnd,ID_ABOUT,hinstance,NULL);
    SendMessage(about,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
    SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_ADDSTRING,0,"Moyenne (avec coefficients)");
    SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_ADDSTRING,0,"Moyenne (sans coefficients)");
    SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_ADDSTRING,0,"Nombre de notes >= 10");
    SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_ADDSTRING,0,"Nombre de notes < 10");
    SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_ADDSTRING,0,"Etendue (différence max - min)");

    SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_SELECTSTRING,0,"Moyenne (avec coefficients)");
    CheckDlgButton(hwnd,ID_COEFF1,BST_CHECKED);
    if (!hwnd) return FALSE;
    ShowWindow(hwnd,nCmdShow);
    while (GetMessage(&msg,NULL,0,0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}
//Traitement des messages Client-Machine
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch (uMsg) {
        case WM_COMMAND:
            switch (LOWORD(wParam)) {
                case ID_COEFFAUTRE:
                    DialogBox(hinst,"DIALOG1",hwnd,(DLGPROC)Dialog1Proc);
                    break;
                case ID_GOBACK:
                {
                    RECT area;
                    GetWindowRect(hwnd,&area);
                    int width=area.right-area.left;
                    if (width == 320) {
                        SetWindowPos(hwnd,0,area.left,area.top,800,350,0);
                        SetDlgItemText(hwnd,ID_GOBACK,"<");
                    }
                    else {
                        SetWindowPos(hwnd,0,area.left,area.top,320,275,0);
                        SetDlgItemText(hwnd,ID_GOBACK,">");
                    }
                    break;
                }
                case ID_COMBO:
                    nbritem=SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETCOUNT,0,0);
                    if (nbritem > 0) Refresh(hwnd);
                    break;
                case ID_ANNULER:
                    nbritem=SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETCOUNT,0,0)-1;
                    SendMessage(GetDlgItem(hwnd,ID_LIST),LB_DELETESTRING,nbritem,NULL);
                    Refresh(hwnd);
                    break;
                case ID_RECOMMENCER:
                    while (SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETCOUNT,0,0)*2) {
                        SendMessage(GetDlgItem(hwnd,ID_LIST),LB_DELETESTRING,0,NULL);
                    }
                    SetDlgItemText(hwnd,ID_EDIT,"");
                    SendMessage(GetDlgItem(hwnd,ID_COMBO),CB_SELECTSTRING,0,"Moyenne (avec coefficients)");
                    CheckDlgButton(hwnd,ID_COEFF05,BST_UNCHECKED);
                    CheckDlgButton(hwnd,ID_COEFF1,BST_UNCHECKED);
                    CheckDlgButton(hwnd,ID_COEFF2,BST_UNCHECKED);
                    CheckDlgButton(hwnd,ID_COEFFAUTRE,BST_UNCHECKED);
                    CheckDlgButton(hwnd,ID_COEFF1,BST_CHECKED);
                    SetDlgItemText(hwnd,ID_COEFFAUTRE,"autre...");
                    Refresh(hwnd);
                    break;
                case ID_CHECK:
                    Refresh(hwnd);
                    InvalidateRect(hwnd,NULL,FALSE);
                    UpdateWindow(hwnd);
                    break;
                case ID_OK:
                {
                    char text[10];
                    GetWindowText(GetDlgItem(hwnd,ID_EDIT),text,10);
                    int text2=atoi(text),a=1;
                    while (a<=20) {
                        if (text2 == a) {
                            int b=7;
                            while (b<=10) {
                                if (IsDlgButtonChecked(hwnd,b)) {
                                    char textcoeff[5];
                                    double verif=1.5;
                                    GetWindowText(GetDlgItem(hwnd,b),textcoeff,10);
                                    if (strchr(textcoeff,'a') != NULL) {
                                        sscanf(textcoeff,"autre: %lf",&verif);
                                        sprintf(textcoeff,"%lf",verif);
                                    }
                                    char par1[]="  (";
                                    char par2[]=")";
                                    strcat(par1,textcoeff);
                                    strcat(par1,par2);
                                    SendMessage(GetDlgItem(hwnd,ID_LIST),LB_ADDSTRING,0,strcat(text,par1));
                                    EnableWindow(GetDlgItem(hwnd,ID_ANNULER),TRUE);
                                    EnableWindow(GetDlgItem(hwnd,ID_RECOMMENCER),TRUE);
                                    Refresh(hwnd);
                                    break;
                                }
                                b++;
                            }
                        }
                        a++;
                    }
                    break;
                }
                case ID_ABOUT:
                    MessageBox(hwnd,"- Moyennes -\nLogiciel pour calculer ses moyennes\n(copyrights © WINKEL Vincent)","A propos...",MB_OK|MB_ICONASTERISK);
                    break;
            }
        case WM_PAINT:
            Draw(hwnd);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
}
//Aliases de raccourci (traitement du graphique)
void Refresh(HWND hwnd) {
    nbritem=SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETCOUNT,0,0);
    if (nbritem > 0) {
        char textitem[100];
        GetDlgItemText(hwnd,ID_COMBO,textitem,100);
        char item1[]="Moyenne (avec coefficients)";
        char item2[]="Moyenne (sans coefficients)";
        char item3[]="Nombre de notes >= 10";
        char item4[]="Nombre de notes < 10";
        char item5[]="Etendue (différence max - min)";
        int a=0;
        double nbr=0,nbr2=0,note=0,coeff=0;
        char text[20],texttitle[200];
        if (strcmp(textitem,item1) == 0) {
            while (a<nbritem) {
                SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
                sscanf(text,"%lf  (%lf)",&note,&coeff);
                nbr+=note*coeff;
                nbr2+=coeff;
                a++;
            }
            afficheMoy=nbr/nbr2;
            sprintf(texttitle,"Moyenne (avec coefficients): %.2f",afficheMoy);
            SetDlgItemText(hwnd,ID_BOX,texttitle);
            SetWindowText(hwnd,texttitle);
        }
        else if (strcmp(textitem,item2) == 0) {
            while (a<nbritem) {
                SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
                sscanf(text,"%lf  (%lf)",&note,&coeff);
                nbr+=note;
                a++;
            }
            afficheMoy=nbr/nbritem;
            sprintf(texttitle,"Moyenne (sans coefficients): %.2f",afficheMoy);
            SetDlgItemText(hwnd,ID_BOX,texttitle);
            SetWindowText(hwnd,texttitle);
        }
        if (strcmp(textitem,item3) == 0) {
            while (a<nbritem) {
                SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
                sscanf(text,"%lf  (%lf)",&note,&coeff);
                if (note >= 10) nbr++;
                nbr2++;
                a++;
            }
            coeff=(nbr*100)/nbr2;
            sprintf(texttitle,"Notes >= 10: %.0f/%.0f (%.1f %%)",nbr,nbr2,coeff);
            SetDlgItemText(hwnd,ID_BOX,texttitle);
            SetWindowText(hwnd,texttitle);
        }
        else if (strcmp(textitem,item4) == 0) {
            while (a<nbritem) {
                SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
                sscanf(text,"%lf  (%lf)",&note,&coeff);
                if (note < 10) nbr++;
                nbr2++;
                a++;
            }
            coeff=(nbr*100)/nbr2;
            sprintf(texttitle,"Notes < 10: %.0f/%.0f (%.1f %%)",nbr,nbr2,coeff);
            SetDlgItemText(hwnd,ID_BOX,texttitle);
            SetWindowText(hwnd,texttitle);
        }
        else if (strcmp(textitem,item5) == 0) {
            if (nbritem <= 2) {
                SetDlgItemText(hwnd,ID_BOX,"2 valeurs minimum sont requises");
                SetWindowText(hwnd,"2 valeurs minimum sont requises");
            }
            else {
                nbr=0,nbr2=20;
                while (a<nbritem) {
                    SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
                    sscanf(text,"%lf  (%lf)",&note,&coeff);
                    if (note > nbr) nbr=note;
                    else if (note < nbr2) nbr2=note;
                    a++;
                }
                nbr-=nbr2;
                sprintf(texttitle,"Etendue des notes: %.2f",nbr);
                SetDlgItemText(hwnd,ID_BOX,texttitle);
                SetWindowText(hwnd,texttitle);
            }
        }
    }
    else {
        SetDlgItemText(hwnd,ID_BOX,"Aucune valeur");
        SetWindowText(hwnd,"Aucune valeur");
    }
    Draw(hwnd);
    InvalidateRect(hwnd,NULL,FALSE);
    UpdateWindow(hwnd);
}
void Draw(HWND hwnd) {
    PAINTSTRUCT ps;
    HDC hdc=BeginPaint(hwnd,&ps);
    HPEN hp2px,hpOld;
    HBRUSH brush;
    HFONT NewFont,OldFont;
    LOGFONT lf;
    ZeroMemory(&lf,sizeof(LOGFONT));
    lstrcpy(lf.lfFaceName,"Arial");
    lf.lfHeight=12;
    NewFont=CreateFontIndirect(&lf);
    OldFont=SelectObject(hdc,NewFont);
    //Initialisation du graphique
    Rectangle(hdc,330,10,780,300);
    MoveToEx(hdc,360,20,NULL);
    LineTo(hdc,360,270);
    MoveToEx(hdc,350,260,NULL);
    LineTo(hdc,745,260);
    //Ajout des graduations
    int a=20,b=360,d=20;
    char c[3];
    while (a<=250) {
        sprintf(c,"%d",d);
        MoveToEx(hdc,358,a,NULL);
        LineTo(hdc,360,a);
        int l=strlen(c);
        if (l == 2) TextOut(hdc,345,a-5,c,lstrlen(c));
        else TextOut(hdc,350,a-5,c,lstrlen(c));
        a+=12;
        d--;
    }
    while (b<=750) {
        MoveToEx(hdc,b,261,NULL);
        LineTo(hdc,b,263);
        b+=12;
    }
    //Ajout de texte
    sprintf(nbritem2,"%d",nbritem);
    char e[]="Total des notes: ";
    char e2[]=" / 32";
    strcat(e,nbritem2);
    strcat(e,e2);
    lf.lfHeight=15;
    NewFont=CreateFontIndirect(&lf);
    OldFont=SelectObject(hdc,NewFont);
    TextOut(hdc,480,275,e,lstrlen(e));
    //Traçage du graphique
    hp2px=CreatePen(PS_SOLID,1,RGB(150,150,250));
    hpOld=SelectObject(hdc,hp2px);
    a=0,b=362;
    char text[20];
    while (a<=nbritem-1) {
        if (a > 31) break;
        SendMessage(GetDlgItem(hwnd,ID_LIST),LB_GETTEXT,a,text);
        float nbr=atof(text);
        SelectObject(hdc,GetStockObject(LTGRAY_BRUSH));
        Rectangle(hdc,b,260-12*nbr,b+9,260);
        a++;
        b+=12;
    }
    //Affichage (ou non) de la grille
    if (IsDlgButtonChecked(hwnd,ID_CHECK)) {
        hp2px=CreatePen(PS_SOLID,1,RGB(200,200,200));
        hpOld=SelectObject(hdc,hp2px);
        int a=20,b=372;
        while (a<=250) {
            MoveToEx(hdc,361,a,NULL);
            LineTo(hdc,745,a);
            a+=12;
        }
        while (b<=750) {
            MoveToEx(hdc,b,20,NULL);
            LineTo(hdc,b,260);
            b+=12;
        }
    }
    //Affichage de la moyenne
    if (nbritem > 0) {
        hp2px=CreatePen(PS_SOLID,1,RGB(50,150,170));
        hpOld=SelectObject(hdc,hp2px);
        float nbr=260-12*afficheMoy;
        MoveToEx(hdc,360,nbr,NULL);
        LineTo(hdc,745,nbr);
        lf.lfHeight=13;
        NewFont=CreateFontIndirect(&lf);
        OldFont=SelectObject(hdc,NewFont);
        TextOut(hdc,700,nbr-13,"Moyenne",lstrlen("Moyenne"));
    }
}
BOOL APIENTRY Dialog1Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
    switch (uMsg) {
        case WM_INITDIALOG:
            return TRUE;
        case WM_COMMAND:
            if (LOWORD(wParam) == ID_SOK) {
                char textedit[100]="";
                GetDlgItemText(hDlg,ID_EDITTEXT,textedit,100);
                int verif=atoi(textedit);
                if (verif <= 0 || verif > 99)
                    if (MessageBox(hwnd,"Le coefficient doit être un nombre !","Erreur de syntaxe",MB_OKCANCEL|MB_ICONERROR) == IDCANCEL) EndDialog(hDlg,0);
                    else return FALSE;
                else {
                    char textedit2[]="autre: ";
                    strcat(textedit2,textedit);
                    SetDlgItemText(hwnd,ID_COEFFAUTRE,textedit2);
                    EndDialog(hDlg,0);
                    return TRUE;
                }
                return FALSE;
            }
            break;
        default:
            return FALSE;
    }
}

Conclusion

C'est étonnant que ce programme marche, car j'ai appris (après) que j'avais oublié plusieurs paramètres pour les déclarations de variables, etc...
J'attends vos conseils/remarques pour optimiser ce code
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   release
    • moyennes.exe.manifestTélécharger ce fichier [Réservé aux membres club]643 octets
    • moyennes.exe_Télécharger ce fichier [Réservé aux membres club]46 451 octets
  • appli.cTélécharger ce fichier [Réservé aux membres club]Voir ce fichier20 364 octets
  • resource.rcTélécharger ce fichier [Réservé aux membres club]Voir ce fichier466 octets

Télécharger le zip

15 avril 2008 10:02:54 :
problème avec le zip
15 avril 2008 10:03:51 :
problème avec le zip
  • signaler à un administrateur
    Commentaire de omnia le 16/04/2008 12:41:17

    salut,

    sympa comme prog :p

    sa me donne envie de faire des graphs :)

  • signaler à un administrateur
    Commentaire de bibiyainfo le 19/04/2008 01:38:53

    PAS MAL DU TOUS POUR UN DEBUT ,SOF IL M'ANQUE DE VERIFICATION AU NIVEAU DES CHAINE DE CARACTERES PAR EXEMPLE:ON PEUX TAPEZ DES NOMBRE OU DES LETRES C LA MEME CHOSE IL YA PAS DE MESAGE D'ERREUR
    SINON TRES BIEN .
    ps:qu'elle est la biblioteque ki regroupe les fonctions d'utilisation de graphs sur dev c++

  • signaler à un administrateur
    Commentaire de omnia le 19/04/2008 10:12:38

    salut, ici dans le contexte

    il n'utilise que les fonctions standards Win32.

    donc pas de libs externes,


    il y a un problème avec l'exe (enfin chez moi) j'ai été obliger de le recompiler pour qu'il fonctionne, je ne sais pas pourquoi.

    et puis pas de projet, que le fichier c sources.

  • signaler à un administrateur
    Commentaire de uaip le 19/04/2008 12:17:24

    hum... oui exact, je vais refaire le zip (en fait j'ai eu des soucis de fichiers qui se sont dispatchés un peu partout).

    - pour le problème de l'editbox qui accepte des caractères alpha, en effet au début j'avais précisé l'option 'numérique', mais du coup on ne pouvait plus mettre de virgule. Ensuite j'ai voulu vérifier la syntaxe quand on appuie sur "valider" avec une petite regexp, mais j'ai remarqué que c'était le bordel pour faire une regexp en c/c++, du coup j'ai dû oublier...

    - et oui j'ai choisi win32 car, comme je l'ai dit, je n'avais jamais fait de C, puis je suis tombé sur un petit tuto sur le net (très bien expliqué) pour faire des fenêtres avec cette API, et ça mélangé à msdn, ça m'a aidé ^^

  • signaler à un administrateur
    Commentaire de bibiyainfo le 20/04/2008 20:27:03

    BONSOIR je voudrai avoire
    1_le prototype de la fonction clear screen sur le dev c++
    2_et une introduction sur la compilation séparé .
    merci d'avance a ts

  • signaler à un administrateur
    Commentaire de uaip le 21/04/2008 11:21:42

    Salut,
    1_tu cherches sur google ou msdn
    2_tu cherches sur google ou msdn

    Ensuite, si tu ne trouves pas, il ya un forum ici prévu pour ça...

  • signaler à un administrateur
    Commentaire de bibiyainfo le 21/04/2008 21:28:48

    merci coméme

Ajouter un commentaire

Pub



Appels d'offres

Plugin Dialer outlook
Budget : 2 000€
Travail graphique- ill...
Budget : 1 000€
creation de marque et ...
Budget : 1 000€

Snippets en rapport

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Boutique

Boutique de goodies CodeS-SourceS