jimmy30
Messages postés7Date d'inscriptionvendredi 2 mai 2008StatutMembreDernière intervention12 mai 2008
-
10 mai 2008 à 16:06
cs_juju12
Messages postés966Date d'inscriptionsamedi 3 avril 2004StatutMembreDernière intervention 4 mars 2010
-
11 mai 2008 à 20:20
Voila bonjour en tous :D . j'ai UN gros probleme qui se dresse devant moi alors que je commencez a maitriser la sdl mes profs me demande d'utiliser winbgim et je ne comprend rien pas de tuto rien le chaos !!!
Je me retourne vers vous pour avoir un petit coup de main voici a quoi ressemble mon code actuellement sachant qu'il n'est pas terminé
#include <windows.h>
#include <string.h>
#include
LRESULT CALLBACK
MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
/* The window handle for the "Click Me" button. */
static HWND hwndButton = 0;
static int cx, cy;//Hauteur et largueur de notre boutton.
HDC hdc;/* A device context used for drawing */
PAINTSTRUCT ps;/* Also used during window drawing */
RECT rc;/* A rectangle used during drawing */
//Perform processing based on what kind of message we got.
switch (nMsg)
{
case WM_CREATE:
{
// La fenêtre est crée. Maintenant notre boutton
TEXTMETRIC tm;
hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 15;// Choix de longueur du boutton
cy = (tm.tmHeight + tm.tmExternalLeading) * 2; //Choix de largueur du bouton. Les données cx et cy sont des appels a ces valeurs
ReleaseDC (hwnd, hdc);
hwndButton = CreateWindow (
"button",/* Builtin button class */
"Quitter",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, cx, cy,
hwnd,/* Parent is this window. */
(HMENU) 1,/* Control ID: 1 */
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
return 0;
break;
}
case WM_DESTROY://Commande la fermeture de la fenêtre lorsque l'on clique sur le boutton quitter
PostQuitMessage (0);
return 0;
break;
case WM_PAINT:
/* The window needs to be painted (redrawn). */
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rc);
rc.bottom = rc.bottom / 2;//Emplacement du titre sur la fenêtre
DrawText (hdc, "Tetri-pong", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint (hwnd, &ps);
return 0;
break;
case WM_SIZE:
/* The window size is changing. If the button exists
* then place it in the center of the bottom half of
* the window. */
if (hwndButton &&
(wParam == SIZEFULLSCREEN ||
wParam == SIZENORMAL)
)
{
rc.left = (LOWORD(lParam) - cx) / 1.2;//Permet de régler les paramètre de position sur l'axe des abscisses
rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;//Permet de régler les paramètre de position sur l'axe des ordonnés
MoveWindow (
hwndButton,
rc.left, rc.top, cx, cy, TRUE);
}
break;
case WM_COMMAND:
/* Check the control ID, notification code and
* control handle to see if this is a button click
* message from our child button. */
if (LOWORD(wParam) == 1 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndButton)
{
/* Our button was clicked. Close the window. */
DestroyWindow (hwnd);
}
return 0;
break;
}
/* If we don't handle a message completely we hand it to the system
* provided default window function. */
return DefWindowProc (hwnd, nMsg, wParam, lParam);
}
int STDCALL
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
HWND hwndMain;/* Handle for the main window. */
MSG msg;/* A Win32 message structure. */
WNDCLASSEX wndclass;/* A window class structure. */
char*szMainWndClass = "WinTestWin";
/* The name of the main window class */
/*
* First we create a window class for our main window.
*/
/* Initialize the entire structure to zero. */
memset (&wndclass, 0, sizeof(WNDCLASSEX));
/* This class is called WinTestWin */
wndclass.lpszClassName = szMainWndClass;
/* cbSize gives the size of the structure for extensibility. */
wndclass.cbSize = sizeof(WNDCLASSEX);
/* All windows of this class redraw when resized. */
wndclass.style = CS_HREDRAW | CS_VREDRAW;
/* All windows of this class use the MainWndProc window function. */
wndclass.lpfnWndProc = MainWndProc;
/* This class is used with the current program instance. */
wndclass.hInstance = hInst;
/* Use standard application icon and arrow cursor provided by the OS */
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
/* Color the background white */
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
/*
* Now register the window class for use.
*/
RegisterClassEx (&wndclass);
/*
* Create our main window using that window class.
*/
hwndMain = CreateWindow (
szMainWndClass,/* Class name */
"Projet Programmation",//Titre de la fenêtre
WS_OVERLAPPEDWINDOW,/* Style */
CW_USEDEFAULT,/* Initial x (use default) */
CW_USEDEFAULT,/* Initial y (use default) */
CW_USEDEFAULT,/* Initial x size (use default) */
CW_USEDEFAULT,/* Initial y size (use default) */
NULL,/* No parent window */
NULL,/* No menu */
hInst,/* This program instance */
NULL/* Creation parameters */
);
Quelqu'un peut il me venir en aide plz
C'est le fichier wintest que je cherche a comprendre et qui est utiliser par devcpp en tant qu'exemple.
Ma question est la suivante si vous executer ce programme vous obtenez une fenetre simple avec un bouton quitter qui quitte la fenetre (logique non ^^)
Mais je voudrais rajouter un bouton jouer et un instruction qui seraient relier chacun a des void independant .
Dans un premiers pouvez vous m'expliquer comment inserer de nouveau bouton .
Je vous remercie par avance
Personne ne semble pouvoir ou peut etre vouloir me repondre cela est à vrai assez embettant etant donné que ce trvail doit être terminée d'ici lundi je vous en pris aidez moi !!!
cs_juju12
Messages postés966Date d'inscriptionsamedi 3 avril 2004StatutMembreDernière intervention 4 mars 20104 10 mai 2008 à 17:48
pour insérer des boutons suffit de faire comme pour le premier :
dans la fonction MainWndProc sous WM_CREATE tu as un :
hwndButton=CreateWIndow(...);
tu procèdes de la même manière, regarde les paramètres de CreateWindow() pour plus d'infos.
Pour traiter les événements tu procèdes le message WM_COMMAND :
tu as ceci déjà
if (LOWORD(wParam) == 1 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndButton) ...
ben suffit de mettre le code correspondant à ton deuxième bouton etc...
jimmy30
Messages postés7Date d'inscriptionvendredi 2 mai 2008StatutMembreDernière intervention12 mai 2008 10 mai 2008 à 18:31
Oki ou puis je trouver le paramètre de createwindows car pour etre franc je ne connais strictement rien a cette bibliothèque et je suis dans une galère de fou ^^
jimmy30
Messages postés7Date d'inscriptionvendredi 2 mai 2008StatutMembreDernière intervention12 mai 2008 10 mai 2008 à 19:25
Car la ca ne fait rien j'ai touours le même problème
J'ai pas compris comment on fait la différence entre deux boutton
#include <windows.h>
#include <string.h>
#include
LRESULT CALLBACK
MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hwndButton = 0;
static int cx, cy;//Hauteur et largueur de notre bouton.
HDC hdc;/* A device context used for drawing */
PAINTSTRUCT ps;/* Also used during window drawing */
RECT rc;/* A rectangle used during drawing */
//Perform processing based on what kind of message we got.
switch (nMsg)
{
case WM_CREATE:
{
// La fenêtre est crée. Maintenant notre boutton
TEXTMETRIC tm;
hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 15;// Choix de longueur du bouton
cy = (tm.tmHeight + tm.tmExternalLeading) * 2; //Choix de largueur du bouton. Les données cx et cy sont des appels a ces valeurs
ReleaseDC (hwnd, hdc);
hwndButton = CreateWindow (
"button",/* Builtin button class */
"Quitter",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, cx, cy,
hwnd,/* Parent is this window. */
(HMENU) 1,/* Control ID: 1 */
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
return 0;
break;
}
{
// La fenêtre est crée. Maintenant notre boutton
TEXTMETRIC tm;
hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 15;// Choix de longueur du bouton
cy = (tm.tmHeight + tm.tmExternalLeading) * 2; //Choix de largueur du bouton. Les données cx et cy sont des appels a ces valeurs
ReleaseDC (hwnd, hdc);
hwndButton = CreateWindow (
"bouton",/* Builtin button class */
"Jouer",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, cx, cy,
hwnd,/* Parent is this window. */
(HMENU) 1,/* Control ID: 1 */
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
return 0;
break;
}
case WM_DESTROY://Commande la fermeture de la fenêtre lorsque l'on clique sur le boutton quitter
PostQuitMessage (0);
return 0;
break;
case WM_PAINT:
/* The window needs to be painted (redrawn). */
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rc);
rc.bottom = rc.bottom / 2;//Emplacement du titre sur la fenêtre
DrawText (hdc, "Tetri-pong", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint (hwnd, &ps);
return 0;
break;
case WM_SIZE:
/* The window size is changing. If the button exists
* then place it in the center of the bottom half of
* the window. */
if (hwndButton &&
(wParam == SIZEFULLSCREEN ||
wParam == SIZENORMAL)
)
{
rc.left = (LOWORD(lParam) - cx) / 1.2;//Permet de régler les paramètre de position sur l'axe des abscisses
rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;//Permet de régler les paramètre de position sur l'axe des ordonnés
MoveWindow (
hwndButton,
rc.left, rc.top, cx, cy, TRUE);
}
if (hwndButton &&
(wParam == SIZEFULLSCREEN ||
wParam == SIZENORMAL)
)
{
rc.left = (LOWORD(lParam) - cx) / 1.2;//Permet de régler les paramètre de position sur l'axe des abscisses
rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;//Permet de régler les paramètre de position sur l'axe des ordonnés
MoveWindow (
hwndButton,
rc.left, rc.top, cx, cy, TRUE);
}
break;
case WM_COMMAND:
/* Check the control ID, notification code and
* control handle to see if this is a button click
* message from our child button. */
if (LOWORD(wParam) == 1 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndButton)
{
/* Our button was clicked. Close the window. */
DestroyWindow (hwnd);
}
return 0;
break;
}
/* If we don't handle a message completely we hand it to the system
* provided default window function. */
return DefWindowProc (hwnd, nMsg, wParam, lParam);
}
int STDCALL
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
HWND hwndMain;/* Handle for the main window. */
MSG msg;/* A Win32 message structure. */
WNDCLASSEX wndclass;/* A window class structure. */
char*szMainWndClass = "WinTestWin";
/* The name of the main window class */
/*
* First we create a window class for our main window.
*/
/* Initialize the entire structure to zero. */
memset (&wndclass, 0, sizeof(WNDCLASSEX));
/* This class is called WinTestWin */
wndclass.lpszClassName = szMainWndClass;
/* cbSize gives the size of the structure for extensibility. */
wndclass.cbSize = sizeof(WNDCLASSEX);
/* All windows of this class redraw when resized. */
wndclass.style = CS_HREDRAW | CS_VREDRAW;
/* All windows of this class use the MainWndProc window function. */
wndclass.lpfnWndProc = MainWndProc;
/* This class is used with the current program instance. */
wndclass.hInstance = hInst;
/* Use standard application icon and arrow cursor provided by the OS */
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
/* Color the background white */
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);//Choix de la couleur de fond de la fenêtre
/*
* Now register the window class for use.
*/
RegisterClassEx (&wndclass);
/*
* Create our main window using that window class.
*/
hwndMain = CreateWindow (
szMainWndClass,/* Class name */
"Projet Programmation",//Titre de la fenêtre
WS_OVERLAPPEDWINDOW,/* Style */
CW_USEDEFAULT,/* Initial x (use default) */
CW_USEDEFAULT,/* Initial y (use default) */
CW_USEDEFAULT,/* Initial x size (use default) */
CW_USEDEFAULT,/* Initial y size (use default) */
NULL,/* No parent window */
NULL,/* No menu */
hInst,/* This program instance */
NULL/* Creation parameters */
);
cs_juju12
Messages postés966Date d'inscriptionsamedi 3 avril 2004StatutMembreDernière intervention 4 mars 20104 11 mai 2008 à 10:35
Les paramètres de CreateWindow sont sur MSDN, cherche sur Google.
Pour ce qui est de la création du deuxième bouton, je t'ai pas dit de recopier bêtement le code mais de "procéder de la même façon". En plus tu n'as pas enlevé le 'return 0' après la création du premier donc il quitte avant de créer le deuxième.
jimmy30
Messages postés7Date d'inscriptionvendredi 2 mai 2008StatutMembreDernière intervention12 mai 2008 11 mai 2008 à 12:42
Merci pour ton aide qui m'as été très précieuse étant donné que désormais j'ai trois bouton qui execute quasiment ce que je souhaite
Pourquoi quasiment
Car le bouton jouer et le bouton instructions doivent à ala fois commander la fermeture de la page minbgim (partie que j'ai reussit à faire) mais je veux également qu'il ouvre un fenêtre SDL comment fait t'on stp ???
cs_juju12
Messages postés966Date d'inscriptionsamedi 3 avril 2004StatutMembreDernière intervention 4 mars 20104 11 mai 2008 à 20:20
Alors là désolé je connais pas SDL. S'il y a une fonction spéciale (dans SDL) pour créer des fenêtres je suppose qu'il suffira de l'appeler depuis WinMain() après la fermeture de la première fenêtre.
Dans le cas contraire, si c'est à toi de créer la fenêtre, ben tu procèdes comme pour la première avec CreateWindow.