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?
Printable View
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?
Put your messagebox in your WM_CLOSE
like this :
case WM_CLOSE:
MessageBox(hwnd,....);
Hope this helps.
bye
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;
}
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;) )
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
I think this must depend on the o/s. On win2k it still gives me the option of closing the program.Quote:
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)
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;
}
>>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