begin process at 2008 07 06 00:19:16
1 205 401 membres
368 nouveaux aujourd'hui
14 119 membres club

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 !

Sujet : Winbgim pitié de l'aide [ Divers / Débutant(e) ] (jimmy30)

Winbgim pitié de l'aide le 10/05/2008 16:06:38

jimmy30
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 <iostream>

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 */
);

ShowWindow (hwndMain, nShow);
UpdateWindow (hwndMain);

while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}


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 !!!

Re : Winbgim pitié de l'aide le 10/05/2008 17:48:54

juju12
Réponse acceptée !

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...


Re : Winbgim pitié de l'aide le 10/05/2008 18:31:06

jimmy30
Réponse acceptée !
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 ^^

Re : Winbgim pitié de l'aide le 10/05/2008 19:25:47

jimmy30
Réponse acceptée !
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 <iostream>

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 */
);

ShowWindow (hwndMain, nShow);
UpdateWindow (hwndMain);

while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}


Re : Winbgim pitié de l'aide le 11/05/2008 10:35:08

juju12
Réponse acceptée !
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.

case WM_CREATE:
   hwndButton1=CreateWindow("button","quitter",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, cx, cy,hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance, NULL);
  hwndButton2=CreateWindow("button","jouer",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 100 cx, cy,hwnd,(HMENU) 2,((LPCREATESTRUCT) lParam)->hInstance, NULL);
 return 0;

les paramètres importants à changer entre les deux sont : le nom, la position, l'index du contrôle pour l'identifier.

Re : Winbgim pitié de l'aide le 11/05/2008 12:42:21

jimmy30
Réponse acceptée !
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 ???

Re : Winbgim pitié de l'aide le 11/05/2008 20:20:59

juju12
Réponse acceptée !
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.


Classé sous : class, hwnd, window, rc, wndclass

Participer à cet échange

Pub



Appels d'offres

Plugin Dialer outlook
Budget : 2 000€
Travail graphique- ill...
Budget : 1 000€
creation de marque et ...
Budget : 1 000€

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Boutique

Boutique de goodies CodeS-SourceS