0% ont trouvé ce document utile (0 vote)
13 vues6 pages

Interfaces Grphique

Le document présente un programme en C pour une application de gestion d'étudiants utilisant l'API Windows. Il permet d'ajouter, afficher et supprimer des étudiants via une interface graphique simple. Les étudiants sont stockés dans une structure et un tableau, avec des fonctions dédiées pour chaque opération.

Transféré par

azararomba24
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
13 vues6 pages

Interfaces Grphique

Le document présente un programme en C pour une application de gestion d'étudiants utilisant l'API Windows. Il permet d'ajouter, afficher et supprimer des étudiants via une interface graphique simple. Les étudiants sont stockés dans une structure et un tableau, avec des fonctions dédiées pour chaque opération.

Transféré par

azararomba24
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd

#include <windows.

h>

#include <stdio.h>

#include <string.h>

// Déclaration de la structure pour un étudiant

typedef struct {

int id;

char nom[50];

int age;

} Etudiant;

#define MAX_ETUDIANTS 100

Etudiant etudiants[MAX_ETUDIANTS];

int nombreEtudiants = 0;

// Déclaration des fonctions

void ajouterEtudiant();

void afficherEtudiants();

void supprimerEtudiant();

// Fonction de gestion des messages pour la fenêtre

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

static HWND btnAjouter, btnAfficher, btnSupprimer, lblAffichage;

switch (uMsg) {

case WM_CREATE:
// Créer les boutons

btnAjouter = CreateWindow("BUTTON", "Ajouter un étudiant",

WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,

50, 50, 200, 30, hwnd, (HMENU)1, GetModuleHandle(NULL), NULL);

btnAfficher = CreateWindow("BUTTON", "Afficher les étudiants",

WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,

50, 100, 200, 30, hwnd, (HMENU)2, GetModuleHandle(NULL), NULL);

btnSupprimer = CreateWindow("BUTTON", "Supprimer un étudiant",

WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,

50, 150, 200, 30, hwnd, (HMENU)3, GetModuleHandle(NULL), NULL);

lblAffichage = CreateWindow("STATIC", "",

WS_VISIBLE | WS_CHILD | SS_LEFT,

50, 200, 400, 300, hwnd, NULL, GetModuleHandle(NULL), NULL);

break;

case WM_COMMAND:

switch (LOWORD(wParam)) {

case 1: // Ajouter un étudiant

ajouterEtudiant();

break;

case 2: // Afficher les étudiants

afficherEtudiants(hwnd, lblAffichage);

break;

case 3: // Supprimer un étudiant

supprimerEtudiant();

break;
}

break;

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

return DefWindowProc(hwnd, uMsg, wParam, lParam);

return 0;

// Fonction pour ajouter un étudiant

void ajouterEtudiant() {

if (nombreEtudiants >= MAX_ETUDIANTS) {

MessageBox(NULL, "La liste des étudiants est pleine !", "Erreur", MB_OK | MB_ICONERROR);

return;

Etudiant e;

e.id = nombreEtudiants + 1;

strcpy(e.nom, "John Doe"); // Exemple de nom, dans une vraie application, il faudrait un champ de
texte pour entrer un nom

e.age = 20; // Exemple d'âge, il faudrait un champ de texte pour entrer un âge

etudiants[nombreEtudiants++] = e;

MessageBox(NULL, "Étudiant ajouté avec succès !", "Succès", MB_OK | MB_ICONINFORMATION);


}

// Fonction pour afficher tous les étudiants

void afficherEtudiants(HWND hwnd, HWND lblAffichage) {

if (nombreEtudiants == 0) {

SetWindowText(lblAffichage, "Aucun étudiant à afficher.");

return;

char buffer[1024] = "=== Liste des étudiants ===\n";

for (int i = 0; i < nombreEtudiants; i++) {

char tmp[100];

sprintf(tmp, "ID: %d, Nom: %s, Âge: %d\n", etudiants[i].id, etudiants[i].nom, etudiants[i].age);

strcat(buffer, tmp);

SetWindowText(lblAffichage, buffer);

// Fonction pour supprimer un étudiant

void supprimerEtudiant() {

if (nombreEtudiants == 0) {

MessageBox(NULL, "Aucun étudiant à supprimer.", "Erreur", MB_OK | MB_ICONERROR);

return;

}
// Exemple simple pour supprimer le dernier étudiant ajouté

nombreEtudiants--;

MessageBox(NULL, "Dernier étudiant supprimé avec succès !", "Succès", MB_OK |


MB_ICONINFORMATION);

// Point d'entrée principal du programme

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int


nCmdShow) {

const char CLASS_NAME[] = "EtudiantAppClass";

WNDCLASS wc = { };

wc.lpfnWndProc = WindowProc;

wc.hInstance = hInstance;

wc.lpszClassName = CLASS_NAME;

RegisterClass(&wc);

HWND hwnd = CreateWindowEx(

0, CLASS_NAME, "Gestion des étudiants",

WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, CW_USEDEFAULT, 500, 400,

NULL, NULL, hInstance, NULL

);
if (hwnd == NULL) {

return 0;

ShowWindow(hwnd, nCmdShow);

UpdateWindow(hwnd);

MSG msg = { };

while (GetMessage(&msg, NULL, 0, 0)) {

TranslateMessage(&msg);

DispatchMessage(&msg);

return (int) msg.wParam;

Vous aimerez peut-être aussi