Thread: help figuring out a problem

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    44

    help figuring out a problem

    can somebody tell me what is wrong with this code
    Code:
    #include "stdafx.h"
    
    void popup();
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    	switch(msg){
     case WM_DESTROY:{
    	 popup();
    	 break;
     }
     case WM_CLOSE:{
    	 popup();
    	 break;
    }
    }
    	MessageBox(NULL,"josh you idiot i told you not to open this","you dumb kid!"
    		,MB_OKCANCEL);
    	switch(msg){
    	case WM_DESTROY:{
    		popup();
    		break;
    					}
    	case WM_CLOSE:{
    		popup();
    		break;
    				  }
    	case MB_OK:{
    		popup();
    		break;
    			   }
    	case MB_CANCEL:{
    		popup();
    		break;
    				   }
    	default:{
    		
    			}
    	}
    
    
    	return 0;
    }
    
    void popup(){
    	MessageBox(NULL,"sorry that didnt work either","nice try",MB_OKCANCEL);
    	switch(msg){
    	case WM_DESTROY:{
    		popup();
    		break;
    					}
    	case WM_CLOSE:{
    	popup();
    	break;
    				  }
    	case MB_OK:{
    		popup();
    		break;
    			   }
    	case MB_CANCEL:{
    		popup();
    		break;
    				   }
    	default:{
    	
    			}
    	}
    }
    the compiler gives me this error but i dont understand

    Compiling...
    dontopen.cpp
    C:\Programs\dontopen\dontopen.cpp(13) : error C2065: 'msg' : undeclared identifier
    C:\Programs\dontopen\dontopen.cpp(38) : error C2065: 'MB_CANCEL' : undeclared identifier
    C:\Programs\dontopen\dontopen.cpp(38) : error C2051: case expression not constant
    C:\Programs\dontopen\dontopen.cpp(66) : error C2051: case expression not constant
    Error executing cl.exe.

  2. #2
    You need to declare msg..

    MSG msg;

    Also, there is no MB_CANCEL, I guess you either want MB_OKCANCEL or MB_YESNOCANCEL

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    try

    including Windows.h if you have not.

    Code:
    int iReturn=0;
    
    iReturn = MessageBox(NULL,"sorry that didnt work either","nice try",MB_OKCANCEL|MB_ICONEXCLAMATION);
    
    //the return is the button selected, use ID then the name of the button in capitals ie IDNO
    
    if(iReturn==IDCANCEL)
    {
         //watch calling 'popup' as that would be recursive
    }
    else if(iReturn==IDOK)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM