MessageBox

This is a discussion on MessageBox within the Game Programming forums, part of the General Programming Boards category; In my little Tic Tac Toe game, I'm making a message box pop up and say when the player wins, ...

  1. #1
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109

    MessageBox

    In my little Tic Tac Toe game, I'm making a message box pop up and say when the player wins, the computer wins, or if there is a draw. I specified SetDialogBoxMode(true) on initialization so my Direct3D application would allow dialog boxes, and then call my message box like so:

    Code:
    MessageBox(hWnd, "Player wins!", "Congratulations!", MB_ICONEXCLAMATION | MB_TOPMOST | MB_SETFOREGROUND | MB_OK);
    This starts out working fine, it comes up like it should and everything looks good. Then, the next time it should come up, it pops up but gets put behind my window. It still has keyboard focus, and when I move my mouse over it I see the standard windows mouse instead of my custom cursor, and it allows me to push the ok button, but I can't see the message box. This happens with all my message boxes that I call in game, all of which are like the one above with caption and body message changes.

    Is there any reason that my message boxes aren't showing up? The amount of times they work before I can no longer see them varies, ranging from 1 time to about 10.

    I'm using DirectX 9.0 with Dev-C++.
    Sic vis pacum para bellum. If you want peace, prepare for war.

  2. #2
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Ok, I need to ask you. How did you get DirectX 9.0 to work with Dev-C++?!?! I have been trying to get those two to work for a while. As for your question, post the code you have relating to the MessageBox(like the code surrounding it,etc).
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  3. #3
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    You have to get the right libraries, which I got a while ago from a site which I don't think is around anymore. The libraries I have are not the current ones for DirectX 9.0, some of the functions use older definitions. However, it works perfectly fine for me. If anyone is able to find current versions of the necessary .a libraries for DirectX, I'd love to hear about it.

    I don't know how much code to post, becuase there is little else that could be relevant to it.

    First call:
    Code:
    if(CheckWon(team)) {
            MessageBox(hWnd, "Player wins!", "Congratulations!", MB_ICONEXCLAMATION | MB_TOPMOST | MB_SETFOREGROUND | MB_OK);
            started = false;
            menu = !menu;
            g_pd3dDevice->ShowCursor(false);
            g_pd3dDevice->SetCursorProperties(0, 0, g_pCursorMenu);
            g_pd3dDevice->ShowCursor(true);
            started = false;
            Cleanup();
            PostQuitMessage(0);
            return;
        }
    Second call:
    Code:
    if(CheckWon(aiteam)) {
            MessageBox(hWnd, "Computer wins!", "You Suck!", MB_ICONEXCLAMATION | MB_TOPMOST | MB_SETFOREGROUND | MB_OK);
            started = false;
            menu = !menu;
            g_pd3dDevice->ShowCursor(false);
            g_pd3dDevice->SetCursorProperties(0, 0, g_pCursorMenu);
            g_pd3dDevice->ShowCursor(true);
            return;
        }
    Third call:
    Code:
    if(squares[0][0] != 0 && squares[0][1] != 0 && squares[0][2] != 0 && squares[1][0] != 0 && squares[1][1] != 0 &&
           squares[1][2] != 0 && squares[2][0] != 0 && squares[2][1] != 0 && squares[2][2] != 0) {
            MessageBox(hWnd, "Draw!", "No One Wins!", MB_ICONEXCLAMATION | MB_TOPMOST | MB_SETFOREGROUND | MB_OK);
            started = false;
            menu = !menu;
            g_pd3dDevice->ShowCursor(false);
            g_pd3dDevice->SetCursorProperties(0, 0, g_pCursorMenu);
            g_pd3dDevice->ShowCursor(true);
        }
    I don't see anything wrong with any of my code, however perhaps it is something I don't know about.
    Sic vis pacum para bellum. If you want peace, prepare for war.

  4. #4
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Well, I usually don't pass my window's handle to the MessageBox function. I don't know if that would affect this or not but try calling the MessageBox function with a NULL instead of the hWnd.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  5. #5
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    I hadn't been, however that makes the message box not part of the application so it appears behind the window. When I call it with the window handle, it should appear in front since I have SetDialogBoxMode set to true. However, this does not seem to work very well, hence my problem.


    Edit: I tried it with NULL and it refuses to take input and eventually the program crashes.
    Last edited by Morgul; 12-04-2005 at 05:09 PM.
    Sic vis pacum para bellum. If you want peace, prepare for war.

  6. #6
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    No one has any ideas on why this could be happening ?
    Sic vis pacum para bellum. If you want peace, prepare for war.

  7. #7
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    Never mind everyone, the error wasn't in the message box function, it was an error elsewhere that caused the same code to be called over and over again, screwing up the message box. I fixed it I believe. Thanks for the attempted help .
    Sic vis pacum para bellum. If you want peace, prepare for war.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Delete files that are used
    By Yuri in forum C++ Programming
    Replies: 8
    Last Post: 10-18-2005, 02:48 PM
  2. problem with A simple modeless messagebox
    By hanhao in forum C++ Programming
    Replies: 8
    Last Post: 07-06-2005, 12:18 AM
  3. Forcing MessageBox to be non-concurrent?
    By JasonD in forum Windows Programming
    Replies: 17
    Last Post: 12-10-2003, 03:16 PM
  4. EnterCriticalSection and MessageBox
    By novacain in forum Windows Programming
    Replies: 13
    Last Post: 01-30-2003, 08:48 AM
  5. double in a MessageBox
    By Robert602 in forum Windows Programming
    Replies: 3
    Last Post: 12-17-2001, 03:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21