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
| #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 AffFenetre(HINSTANCE cetteInstance, HINSTANCE precedenteInstance, LPSTR lignesDeCommande, int modeDAffichage)
{
HWND fenetrePrincipale,fenetreHeberge;
MSG message;
WNDCLASS classeFenetre;
classeFenetre.style = 0;
classeFenetre.style = CS_HREDRAW|CS_VREDRAW;
classeFenetre.lpfnWndProc = procedureFenetrePrincipale;
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", "Jeu multijoueur lan", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 270, 342, NULL, NULL, cetteInstance, NULL);
if (!fenetrePrincipale) return FALSE;
fenetreHeberge = CreateWindow("classeF", "Heberger une partie", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 200, 342, NULL, NULL, cetteInstance, NULL);
if (!fenetreHeberge) return FALSE;
ShowWindow(fenetrePrincipale, modeDAffichage);
UpdateWindow(fenetrePrincipale);
while (GetMessage(&message, NULL, 0, 0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
void RemplieFenetrePrincipale(HWND fenetrePrincipale)
{
// Premier groupe: le push button
// HWND hGroup=CreateWindow(
// "BUTTON",
// "Le push button",
// WS_CHILD|WS_VISIBLE|BS_GROUPBOX,
// 10,10,
// 120,150,
// fenetrePrincipale,
// NULL,
// instance,
// NULL);
// {
HWND hControle;
hControle=CreateWindow(
"BUTTON",
"Héberger une partie",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
50,110,
170,27,
fenetrePrincipale,
(HMENU)ID_PUSHBUTTON_1,
instance,
NULL);
hControle=CreateWindow(
"BUTTON",
"Rejoindre une partie",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
50,110+40,
170,27,
fenetrePrincipale,
(HMENU)ID_PUSHBUTTON_2,
instance,
NULL);
hControle=CreateWindow(
"BUTTON",
"Règles du jeu ...",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
50,110+100,
170,25,
fenetrePrincipale,
(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,
fenetrePrincipale,
(HMENU)ID_PUSHBUTTON_4,
instance,
NULL);
HANDLE hIcon=LoadIcon(NULL,IDI_ERROR);
SendMessage(hControle,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcon);
// }
}
void NotificationControle(HWND fenetrePrincipale,UINT message, WPARAM wParam, LPARAM lParam)
{
unsigned int idBouton=LOWORD(wParam); // Quand btn enfoncé, wParam vaut Id du bouton => recup avec LOWORD()
switch(idBouton)
{
case ID_PUSHBUTTON_1:
ShowWindow(fenetreHeberge, modeDAffichage);
break;
case ID_PUSHBUTTON_2:
MessageBox(fenetrePrincipale,"Vous avez appuyé sur le second bouton","",MB_OK);
break;
case ID_PUSHBUTTON_3:
MessageBox(fenetrePrincipale,"Vous avez appuyé sur le troisième bouton","",MB_OK);
break;
case ID_PUSHBUTTON_4:
MessageBox(fenetrePrincipale,"Vous avez appuyé sur le 4e bouton","",MB_OK);
break;
}
}
LRESULT CALLBACK procedureFenetrePrincipale(HWND fenetrePrincipale, 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(fenetrePrincipale, &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 (fenetrePrincipale, &ps);
break;
}
case WM_CREATE: // Initialisation de la fenetre
RemplieFenetrePrincipale(fenetrePrincipale);
return 0;
case WM_COMMAND: // Quand un bouton est enfoncé message = WM_COMMAND
NotificationControle(fenetrePrincipale,message,wParam,lParam);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(fenetrePrincipale,message,wParam,lParam);
}
} |
Partager