Thread: messagebox loop

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    messagebox loop

    Code:
                          bool close = false;
                        while(close == false)
                        {              
                        if(MessageBox(NULL,"ONLY THE LUBEMAN CAN CLOSE THIS!!!!", "So Are You The LUBEMAN???",
                           MB_YESNO | MB_ICONERROR == IDYES))
                           {
                           close = true; 
                           }
                           else if(MessageBox(NULL,"ONLY THE LUBEMAN CAN CLOSE THIS!!!!", "So Are You The LUBEMAN???",
                           MB_YESNO | MB_ICONERROR == IDNO))
                           {
                           close = false;   
                           }
    ok when i click close it just closes after asking the question it doesnt loop if i say no or anything? its like it just reads it and completely ignores the fact that IF then do this is there a reason it does this or what am i missing?

    it completely skips the else if only asking the question once i just cant get the question to ask and if it says no then loop back if it says yes then exit and go destroy the window. i have no clue why its like the messagebox if's seem immune to the fact that { } normally ment follow these instructions only if ID_YES is done and its just done regardless.

    any reason for this??? thanks

    ive fiddled with this for a while and this is just the curent result im running with
    hooch

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You only want to call MessageBox once, and check its return value:
    Code:
      bool close = false;
      while(close == false)
      {              
      if (MessageBox(NULL,"ONLY THE LUBEMAN CAN CLOSE THIS!!!!", "So Are You The LUBEMAN???", MB_YESNO | MB_ICONERROR ) == IDYES) 
      {
        close = true; 
      }
      else 
      {
         close = false;   
      }
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    ah well that explains that though thought i tried that guess not lol thanks anyway

    oh well one other thing how would you kill the dos window in the background it has the window that i made but the dos window is still in the background??? is there like a hide dos window command?
    hooch

  4. #4
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Well if your not using the console window in the background why not tell your compiler to compile for Win32 Application, thus not even showing the console box.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    so rather than select empty project select that win32 application???? or will a windows application work? and last time i did that i couldnt seem to link the resource files in at all?
    hooch

  6. #6
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Here is my little and very simple MessageBox loop:
    Code:
    #include <windows.h>
    
    char Name[100] = "Uncloseable";
    
    int main()
    {
        for(int i; i;)
        {
        SetConsoleTitle( Name );
        HWND hwnd = FindWindow( NULL, Name );
        ShowWindow(hwnd, SW_HIDE);
        ::MessageBox(0,"You can't close this!","Uncloseable",MB_ICONWARNING);
        }
    }
    Last edited by Yuri; 08-21-2005 at 10:22 AM.

  7. #7
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Ok I'm just going to guess your using Dev-C++, if your not it will probably be similar. Open up Dev and go to Options>>Compiler Options>>Linker(the tab)>>Check the box that says Compile for Win32 Application.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM
  4. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM
  5. EnterCriticalSection and MessageBox
    By novacain in forum Windows Programming
    Replies: 13
    Last Post: 01-30-2003, 08:48 AM