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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h> // Librairie SDL
#include <windows.h> // Pour les fonctions de l'API
#include "client.h" // Header connection ET recherche SRV
#include "serveur.h" // Header ecoute serveur
int GestionFenetres(HINSTANCE cetteInstance, HINSTANCE precedenteInstance, LPSTR lignesDeCommande, int modeAffichage)
{
HWND fenetrePrincipale,fenetreHebergePartie;
MSG message;
WNDCLASS classeFenetre;
classeFenetre.style = 0;
classeFenetre.style = CS_HREDRAW|CS_VREDRAW;
classeFenetre.lpfnWndProc = procedureFenetre;
classeFenetre.cbClsExtra = 0;
classeFenetre.cbWndExtra = 0;
classeFenetre.hInstance = NULL;
classeFenetre.hIcon = LoadIcon(NULL, IDI_APPLICATION);
classeFenetre.hCursor = LoadCursor(NULL, IDC_ARROW);
classeFenetre.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
classeFenetre.lpszMenuName = NULL;
classeFenetre.lpszClassName = "classeF";
if(!RegisterClass(&classeFenetre)) return FALSE;
fenetrePrincipale = CreateWindow("classeF", "Mon jeu", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 280, 350, NULL, NULL, cetteInstance, NULL);
if (!fenetrePrincipale) return FALSE;
SetWindowLong(fenetrePrincipale, DWL_USER, 1);
fenetreHebergePartie = CreateWindow("classeF", "Heberger une partie ...", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 280, 350, NULL, NULL, cetteInstance, NULL);
if (!fenetreHebergePartie) return FALSE;
SetWindowLong(fenetreHebergePartie, DWL_USER, 2);
ShowWindow(fenetrePrincipale, modeAffichage);
UpdateWindow(fenetrePrincipale);
while (GetMessage(&message, NULL, 0, 0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
void RemplirFenetrePrincipale(HWND fenetre)
{
HWND hControle;
hControle=CreateWindow(
"BUTTON",
"Héberger une partie",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
50,110,
170,27,
fenetre,
(HMENU)ID_PUSHBUTTON_1,
instance,
NULL);
hControle=CreateWindow(
"BUTTON",
"Rejoindre une partie",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
50,110+40,
170,27,
fenetre,
(HMENU)ID_PUSHBUTTON_2,
instance,
NULL);
hControle=CreateWindow(
"BUTTON",
"Règles du jeu ...",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
50,110+100,
170,25,
fenetre,
(HMENU)ID_PUSHBUTTON_3,
instance,
NULL);
hControle=CreateWindow(
"BUTTON",
"A propos de ...",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_FLAT,
140,110+170,
115,22,
fenetre,
(HMENU)ID_PUSHBUTTON_4,
instance,
NULL);
}
void GestBoutonsFPrincipale(HWND fenetre,UINT message, WPARAM wParam, LPARAM lParam)
{
switch(LOWORD(wParam)) // Quand btn enfoncé, une partie de wParam vaut Id du bouton => recup avec LOWORD()
{
case ID_PUSHBUTTON_1:
// ici !!!!!!!!!
break;
case ID_PUSHBUTTON_2:
MessageBox(fenetre,"Vous avez appuyé sur le second bouton","",MB_OK);
break;
case ID_PUSHBUTTON_3:
MessageBox(fenetre,"Vous avez appuyé sur le troisième bouton","",MB_OK);
break;
case ID_PUSHBUTTON_4:
MessageBox(fenetre,"Vous avez appuyé sur le 4e bouton","",MB_OK);
break;
}
}
LRESULT CALLBACK procedureFenetre(HWND fenetre, UINT message, WPARAM wParam, LPARAM lParam)
{
if (fenetre != NULL)
{
int idFenetre = GetWindowLong(fenetre, DWL_USER);
switch(idFenetre)
{
case 1:
return procedureFenetrePrincipale(fenetre, message, wParam, lParam);
case 2:
return procedureFenetreHebergerPartie(fenetre, message, wParam, lParam);
}
}
/* Tous les autres cas ici. */
return procedureFenetrePrincipale(fenetre, message, wParam, lParam);
}
LRESULT procedureFenetrePrincipale(HWND fenetre, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
{
HDC hdc;
POINT pt;
HBITMAP hBitmap;
HDC hMemDC;
PAINTSTRUCT ps;
BITMAP bm;
hdc = BeginPaint(fenetre, &ps);
hBitmap = (HBITMAP) LoadImage(NULL, "images/fond.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
hMemDC = CreateCompatibleDC (hdc);
SelectObject (hMemDC, hBitmap);
GetObject (hBitmap, sizeof (BITMAP), &bm) ;
pt.x = bm.bmWidth;
pt.y = bm.bmHeight;
BitBlt (hdc, 0, 0, pt.x, pt.y, hMemDC, 0, 0, SRCCOPY) ;
EndPaint (fenetre, &ps);
break;
}
case WM_CREATE: // Initialisation de la fenetre
RemplirFenetrePrincipale(fenetre);
return 0;
case WM_COMMAND: // Quand un bouton est enfoncé message = WM_COMMAND
GestBoutonsFPrincipale(fenetre,message,wParam,lParam);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(fenetre,message,wParam,lParam);
}
}
LRESULT procedureFenetreHebergerPartie(HWND fenetre, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE: // Initialisation de la fenetre
RemplirFenetrePrincipale(fenetre);
return 0;
case WM_COMMAND: // Quand un bouton est enfoncé message = WM_COMMAND
GestBoutonsFPrincipale(fenetre,message,wParam,lParam);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(fenetre,message,wParam,lParam);
}
} |
Partager