MINESWEEPER

Hey guys, I'm new to windows programming and I have a problem! I am making a MineSweeper and at the end of the game(when the player hits a mine), i want to ask him whether he wants to play again or not... So, if he says no, then i use the PostQuitMessagefunction to close the windows but if he presses the Yes button, the game should restary!!! Please, can anyone tell me how to do that?!
Here is the part of the programm that creates the message box!


int msgboxID = MessageBox(hwnd, "Sorry, you lost! Play again?",
"Minesweeper", MB_YESNO | MB_SYSTEMMODAL | MB_APPLMODAL | MB_ICONQUESTION);

switch (msgboxID)
{
case IDYES:
{
//here is the yes case!
break;
}

case IDNO:
{
PostQuitMessage (0);
break;
}
}
closed account (z1CpDjzh)
Hered of the
1
2
code tags [code] which is followed by [code/] to close it.... well it uts your code in a box like
//this and makes it easer to read.... it also adds colours to it :P 



your new code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int msgboxID = MessageBox(hwnd, "Sorry, you lost! Play again?",
"Minesweeper", MB_YESNO | MB_SYSTEMMODAL | MB_APPLMODAL | MB_ICONQUESTION);

switch (msgboxID)
{
case IDYES:
{

char szProcessName[MAX_PATH] = "<unknown>";
::GetModuleFileName(NULL, szProcessName, sizeof szProcessName);
ShellExecute(NULL, "Open", szProcessName, NULL, NULL, SW_SHOWNORMAL);
PostQuitMessage (0);
//here is the yes case!
break;
} 

case IDNO:
{
PostQuitMessage (0);
break;
}
}



what that does is open your program again and then close the current one.

simple right.... and no security wholes that are 2 km deep :p
Thank you so much!!! This is very helpful!! :)
Topic archived. No new replies allowed.