NeEd HeLp

This is a discussion on NeEd HeLp within the Windows Programming forums, part of the Platform Specific Boards category; hey..im trying to make a message box that pops up when the user clicks on the X in the top ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    55

    Question NeEd HeLp

    hey..im trying to make a message box that pops up when the user clicks on the X in the top right hand corner of the screen in the consol window....how would i write this?
    D4050
    Glorified C++ Programmer
    Console, DOS, HTML, Javascript, Visual Basics Compatible

  2. #2
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    Put your messagebox in your WM_CLOSE
    like this :
    case WM_CLOSE:
    MessageBox(hwnd,....);


    Hope this helps.
    bye

  3. #3
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    If you mean a using a console app rahter than creating the window yourself, then you can create a HanderRoutine that captures the request to exit -

    Code:
    #include <windows.h>
    
    BOOL g_quit;
    
    BOOL WINAPI HandlerRoutine( DWORD dwCtrlType)
    {
    	if(dwCtrlType==CTRL_CLOSE_EVENT)
    	{
    		MessageBox(NULL,"bye","Exit",MB_SYSTEMMODAL);
    		g_quit=1;
    	}
    	return 1;
    }
    
    int main()
    {
    	 SetConsoleCtrlHandler(HandlerRoutine,TRUE);
    		while(!g_quit);
    
    	return 0;
    }
    zen

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    55
    k thx..where in the code would i make the message box appear.then when they press ok...it disapears but there still in the program...so basicly they CANT exit..(I aint evil.dont worry )
    D4050
    Glorified C++ Programmer
    Console, DOS, HTML, Javascript, Visual Basics Compatible

  5. #5
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    If you're making a win api
    do not put PostQuitMessage (0); after your messagbox
    like this:
    case WM_CLOSE:
    MessageBox(hwnd,"Text","Caption",MB_OK);
    return 0;

    If you are using ZEN's code, remove g_quit=1;

    now you won't be able to exit your program (exept CTRL-ALT-DEL)


    bye

  6. #6
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    If you are using ZEN's code, remove g_quit=1;

    now you won't be able to exit your program (exept CTRL-ALT-DEL)
    I think this must depend on the o/s. On win2k it still gives me the option of closing the program.

    If you want to be annoying and prevent somebody from exiting a console program without using CTRL-ALT-DEL/Task Manager then you can disable the close button and the close option in the system menu -

    Code:
    #include <windows.h>
    
    
    int main()
    {
    	
        SetConsoleTitle ( "test" );
    	HWND hwnd = NULL;
    
        while ( NULL == hwnd )
            {
            hwnd = FindWindowEx ( NULL, NULL, NULL, "test" );
            }
    
    	HMENU hmenu = GetSystemMenu ( hwnd, FALSE );
        DeleteMenu ( hmenu, SC_CLOSE, MF_BYCOMMAND );
    	while(1);
    
    	return 0;
    }
    zen

  7. #7
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    >>I think this must depend on the o/s. On win2k it still gives me the option of closing the program

    I also use win2k and it asked me if I wanted to end the program.
    But this didn't work in debug mode.I could not end the program. I should have used the exe to test it. sorry for the wrong info

Popular pages Recent additions subscribe to a feed

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