Probleme de compilation (débutant)

Résolu
cddvdcopy Messages postés 8 Date d'inscription samedi 11 décembre 2004 Statut Membre Dernière intervention 26 mai 2005 - 23 mai 2005 à 19:00
DeAtHCrAsH Messages postés 2670 Date d'inscription vendredi 25 janvier 2002 Statut Membre Dernière intervention 6 février 2013 - 23 mai 2005 à 20:02
je suis débutant, merci de m'éclairer !!



ce code marche :



#include <windows.h>

#define ID_SFC 100


#define ID_RECHERCHE 200
#define ID_EXIT 300
#define ID_PROPOS 400


/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);


/* Make the class name into a global variable */
char szClassName[ ] = "Windows App";


int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)


{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */


/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);


/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;


/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;


/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"RepairWinXP", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
600, /* The programs width */
400, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

HWND sfc;
HWND recherche;
HWND quitter;
HWND propos;
sfc = CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD , 10,10,
350, 30, hwnd, (HMENU)ID_SFC, hThisInstance, NULL);
recherche = CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD, 370, 10,
210, 30, hwnd, (HMENU)ID_RECHERCHE, hThisInstance, NULL);
propos = CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD , 10, 330,
70, 30,hwnd, (HMENU) ID_PROPOS, hThisInstance, NULL);
quitter= CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD ,90 ,330,
150,30,hwnd, (HMENU) ID_EXIT, hThisInstance , NULL);


SetWindowText(sfc,"Restaurer Les fichiers système et les fichiers d'aide");
SetWindowText(recherche,"Retablir la fonction Rechercher");
SetWindowText(propos, "A propos");
SetWindowText(quitter, "Quitter RepairWinXP");

/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
UpdateWindow(sfc);
UpdateWindow(recherche);
UpdateWindow(propos);
UpdateWindow(quitter);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}


/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}



/* This function is called by the Windows function DispatchMessage() */


LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
case WM_COMMAND :
switch (LOWORD(wParam))
{
case ID_EXIT :
PostQuitMessage (0);
break;
case ID_PROPOS :
MessageBox(NULL, " Merci d'utiliser RepairWinXP . \n
Programme créé par griffin dans le but de vous faciliter WinXp" ,
"RepairWinXP", MB_OK);
break;
case ID_SFC :
int box1 = MessageBox(NULL, " Voulez-vous vraiment rétablir
\n les fichiers systèmes et les fichiers d'aide ? \n Veuillez inserer
le CD de Windows XP pour continuer." , "RepairWinXP", MB_YESNO |
MB_ICONINFORMATION );
if( box1 == IDYES )
{
ShellExecute(NULL,NULL,"sfc","/scannow",NULL,SW_SHOWNORMAL);
}
break;
}
}
return 0;
}


mais des que je rajoute quelque chose et donc le code devient ca:


#include <windows.h>
#define ID_SFC 100
#define ID_RECHERCHE 200
#define ID_EXIT 300
#define ID_PROPOS 400


/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);


/* Make the class name into a global variable */
char szClassName[ ] = "Windows App";


int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)


{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */


/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);


/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;


/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;


/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"RepairWinXP", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
600, /* The programs width */
400, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);



HWND sfc;
HWND recherche;
HWND quitter;
HWND propos;
sfc = CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD , 10,10,
350, 30, hwnd, (HMENU)ID_SFC, hThisInstance, NULL);
recherche = CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD, 370, 10,
210, 30, hwnd, (HMENU)ID_RECHERCHE, hThisInstance, NULL);
propos = CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD , 10, 330,
70, 30,hwnd, (HMENU) ID_PROPOS, hThisInstance, NULL);
quitter= CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD ,90 ,330,
150,30,hwnd, (HMENU) ID_EXIT, hThisInstance , NULL);





SetWindowText(sfc,"Restaurer Les fichiers système et les fichiers d'aide");
SetWindowText(recherche,"Retablir la fonction Rechercher");
SetWindowText(propos, "A propos");
SetWindowText(quitter, "Quitter RepairWinXP");



/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
UpdateWindow(sfc);
UpdateWindow(recherche);
UpdateWindow(propos);
UpdateWindow(quitter);



/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}


/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}



/* This function is called by the Windows function DispatchMessage() */


LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
case WM_COMMAND :
switch (LOWORD(wParam))
{
case ID_EXIT :
PostQuitMessage (0);
break;
case ID_PROPOS :
MessageBox(NULL, " Merci d'utiliser RepairWinXP . \n
Programme créé par griffin dans le but de vous faciliter WinXp" ,
"RepairWinXP", MB_OK);
break;
case ID_SFC :
int box1 = MessageBox(NULL, " Voulez-vous vraiment rétablir
\n les fichiers systèmes et les fichiers d'aide ? \n Veuillez inserer
le CD de Windows XP pour continuer." , "RepairWinXP", MB_YESNO |
MB_ICONINFORMATION );
if( box1 == IDYES )
{
ShellExecute(NULL,NULL,"sfc","/scannow",NULL,SW_SHOWNORMAL);
}
break;
case ID_RECHERCHE :
int box = MessageBox(NULL, " Voulez-vous vraiment rétablir la
fonction Rechercher ?" , "RepairWinXP", MB_YESNO | MB_ICONINFORMATION
);
if( box == IDYES )
{
ShellExecute(NULL,NULL,"regsvr32","%systemroot%\\srchasst\\srchui.dll",NULL,SW_SHOWNORMAL);
}
break;
}
}
return 0;
}





merci de vous pencher dessus

6 réponses

DeAtHCrAsH Messages postés 2670 Date d'inscription vendredi 25 janvier 2002 Statut Membre Dernière intervention 6 février 2013
23 mai 2005 à 19:48
Yep,
Bon je t'explique tes erreurs:
box1 et box ne doivent pas être déclarées dans les case.
Mets les soit en globales, soit au debut de ta fonction, juste avant le premier switch.

Sinon voila le code corrigé et indenté correctement:


#include <windows.h>


#define ID_SFC 100


#define ID_RECHERCHE 200


#define ID_EXIT 300


#define ID_PROPOS 400


/* Declare Windows procedure */


LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);


/* Make the class name into a global variable */


char szClassName[ ] = "Windows App";


int WINAPI WinMain (HINSTANCE hThisInstance,


HINSTANCE hPrevInstance,


LPSTR lpszArgument,



int nFunsterStil)


{


HWND hwnd;
/* This is the handle for our window */


MSG messages;
/* Here messages to the application are saved */


WNDCLASSEX wincl;
/* Data structure for the windowclass */



/* The Window structure */


wincl.hInstance = hThisInstance;


wincl.lpszClassName = szClassName;


wincl.lpfnWndProc = WindowProcedure;
/* This function is called by windows */


wincl.style = CS_DBLCLKS;
/* Catch double-clicks */


wincl.cbSize =
sizeof (WNDCLASSEX);



/* Use default icon and mouse-pointer */


wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);


wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);


wincl.hCursor = LoadCursor (NULL, IDC_ARROW);


wincl.lpszMenuName = NULL;
/* No menu */


wincl.cbClsExtra = 0;
/* No extra bytes after the window class */


wincl.cbWndExtra = 0;
/* structure or the window instance */



/* Use Windows's default color as the background of the window */


wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;



/* Register the window class, and if it fails quit the program */



if (!RegisterClassEx (&wincl))



return 0;



/* The class is registered, let's create the program*/


hwnd = CreateWindowEx ( 0,
/* Extended possibilites for variation */


szClassName,
/* Classname */


"RepairWinXP",
/* Title Text */


WS_OVERLAPPEDWINDOW,
/* default window */


CW_USEDEFAULT,
/* Windows decides the position */


CW_USEDEFAULT,
/* where the window ends up on the screen */


600,
/* The programs width */


400,
/* and height in pixels */


HWND_DESKTOP,
/* The window is a child-window to desktop */


NULL,
/* No menu */


hThisInstance,
/* Program Instance handler */


NULL
/* No Window Creation data */


);


HWND sfc;


HWND recherche;


HWND quitter;


HWND propos;


sfc = CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD , 10,10,


350, 30, hwnd, (HMENU)ID_SFC, hThisInstance, NULL);


recherche = CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD, 370, 10,


210, 30, hwnd, (HMENU)ID_RECHERCHE, hThisInstance, NULL);


propos = CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD , 10, 330,


70, 30,hwnd, (HMENU) ID_PROPOS, hThisInstance, NULL);


quitter= CreateWindowEx(0, "BUTTON", NULL, WS_VISIBLE|WS_CHILD ,90 ,330,


150,30,hwnd, (HMENU) ID_EXIT, hThisInstance , NULL);


SetWindowText(sfc,"Restaurer Les fichiers système et les fichiers d'aide");


SetWindowText(recherche,"Retablir la fonction Rechercher");


SetWindowText(propos, "A propos");


SetWindowText(quitter, "Quitter RepairWinXP");



/* Make the window visible on the screen */


ShowWindow (hwnd, nFunsterStil);


UpdateWindow(sfc);


UpdateWindow(recherche);


UpdateWindow(propos);


UpdateWindow(quitter);



/* Run the message loop. It will run until GetMessage() returns 0 */



while (GetMessage (&messages, NULL, 0, 0))


{



/* Translate virtual-key messages into character messages */


TranslateMessage(&messages);



/* Send message to WindowProcedure */


DispatchMessage(&messages);


}



/* The program return-value is 0 - The value that PostQuitMessage() gave */



return messages.wParam;


}


/* This function is called by the Windows function DispatchMessage() */


LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)


{



int box, box1;



switch (message)
/* handle the messages */


{



case WM_DESTROY:


PostQuitMessage (0);
/* send a WM_QUIT to the message queue */



break;



default:
/* for messages that we don't deal with */



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



case WM_COMMAND :



switch (LOWORD(wParam))


{



case ID_EXIT :


PostQuitMessage (0);



break;



case ID_PROPOS :


MessageBox(NULL, " Merci d'utiliser RepairWinXP . \n Programme créé par griffin dans le but de vous faciliter WinXp" , "RepairWinXP", MB_OK);



break;



case ID_SFC :


box1 = MessageBox(NULL, " Voulez-vous vraiment rétablir \n les fichiers systèmes et les fichiers d'aide ? \n Veuillez inserer le CD de Windows XP pour continuer." , "RepairWinXP", MB_YESNO | MB_ICONINFORMATION );



if( box1 == IDYES )


{


ShellExecute(NULL,NULL,"sfc","/scannow",NULL,SW_SHOWNORMAL);


}



break;



case ID_RECHERCHE :


box = MessageBox(NULL, " Voulez-vous vraiment rétablir la fonction Rechercher ?" , "RepairWinXP", MB_YESNO | MB_ICONINFORMATION );



if( box == IDYES )


{


ShellExecute(NULL,NULL,"regsvr32","%systemroot%\\srchasst\\srchui.dll",NULL,SW_SHOWNORMAL);


}



break;


}



break;


}



return 0;


}

Shell
3
cddvdcopy Messages postés 8 Date d'inscription samedi 11 décembre 2004 Statut Membre Dernière intervention 26 mai 2005
23 mai 2005 à 19:04
excusez moi mais j'ai oublier de préciser que le 2eme code ne voulait pas se compiler
0
DeAtHCrAsH Messages postés 2670 Date d'inscription vendredi 25 janvier 2002 Statut Membre Dernière intervention 6 février 2013
23 mai 2005 à 19:12
Dis nous exactement qu'elle est le bout de code que tu as ajouté ca sera plus simple parceque la ca fait beaucoup a lire.

Shell
0
cddvdcopy Messages postés 8 Date d'inscription samedi 11 décembre 2004 Statut Membre Dernière intervention 26 mai 2005
23 mai 2005 à 19:20
voila le code que jai rajouté



case ID_RECHERCHE :

int box =
MessageBox(NULL, " Voulez-vous vraiment rétablir la fonction Rechercher
?" , "RepairWinXP", MB_YESNO | MB_ICONINFORMATION );

if( box == IDYES )

{

ShellExecute(NULL,NULL,"regsvr32","%systemroot%\\srchasst\\srchui.dll",NULL,SW_SHOWNORMAL);

}

break;






juste apres :



case ID_SFC :

int box1 =
MessageBox(NULL, " Voulez-vous vraiment rétablir \n les fichiers
systèmes et les fichiers d'aide ? \n Veuillez inserer le CD de Windows
XP pour continuer." , "RepairWinXP", MB_YESNO | MB_ICONINFORMATION );

if( box1 == IDYES )

{

ShellExecute(NULL,NULL,"sfc","/scannow",NULL,SW_SHOWNORMAL);

}

break;
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cddvdcopy Messages postés 8 Date d'inscription samedi 11 décembre 2004 Statut Membre Dernière intervention 26 mai 2005
23 mai 2005 à 19:59
encore merci pour ta réponse qui marche et pour ta rapidité
0
DeAtHCrAsH Messages postés 2670 Date d'inscription vendredi 25 janvier 2002 Statut Membre Dernière intervention 6 février 2013
23 mai 2005 à 20:02
No souci

Shell
0
Rejoignez-nous