Trouver une ressource (Nouvelle version du moteur, plus rapide & pertinent, essayez le !)
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
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)",¬e,&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)",¬e,&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)",¬e,&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)",¬e,&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)",¬e,&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)",¬e,&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)",¬e,&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)",¬e,&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)",¬e,&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)",¬e,&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
Fichier Zip
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
Historique
- 15 avril 2008 10:02:54 :
- problème avec le zip
- 15 avril 2008 10:03:51 :
- problème avec le zip
Sources de la même categorie
Commentaires
Discussions en rapport avec ce code source
|
CalendriCode
| | | L | M | M | J | V | S | D |
| | 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | | | |
|
Téléchargements
Logiciels à télécharger sur le même thème :
|