Click to See Complete Forum and Search --> : trap user hitting exit box on console app


bbly
September 22nd, 2005, 12:17 PM
How can I trap the user hitting exit box on Win32 console app, so that my program can exit gracefully?

BB

bbly
September 22nd, 2005, 06:06 PM
Any answers?

golanshahar
September 23rd, 2005, 05:10 AM
well i am sure its the solution ( i never used it my self) but maybe it can help you out:

MMCN_REMOVE_CHILDREN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mmc/mmc/mmcn_remove_children.asp)
IComponentData::Notify (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mmc/mmc/icomponentdata_notify.asp)


Cheers

Marc G
September 23rd, 2005, 05:17 AM
well i am sure its the solution ( i never used it my self) but maybe it can help you out:

MMCN_REMOVE_CHILDREN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mmc/mmc/mmcn_remove_children.asp)
IComponentData::Notify (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mmc/mmc/icomponentdata_notify.asp)

That is specific for MMC snapins, while the OP was talking about a DOS console box.

You should be able to catch the close command with SetConsoleCtrlHandler (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolectrlhandler.asp)

humptydumpty
September 23rd, 2005, 05:20 AM
How can I trap the user hitting exit box on Win32 console app, so that my program can exit gracefully?

BB
handle WM_NCHITTEST Notification
and check for HTCLOSE
that's all you have to do

Marc G
September 23rd, 2005, 05:25 AM
handle WM_NCHITTEST Notification
and check for HTCLOSE
that's all you have to do
I doubt this will work with a console window.

Marc G
September 23rd, 2005, 05:58 AM
it
will work
ON_WM_NCHITTEST() Implement this macro

write the function in MyFrame.h

UINT OnNcHitTest(CPoint pt);

and implement in your cpp
You do know that we are talking about a console application in this thread? It's like a DOS box. The correct way is to use SetConsoleCtrlHandler (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolectrlhandler.asp) .

humptydumpty
September 23rd, 2005, 06:07 AM
Sorry Marc G i had consider Win32 Application here.anyway i made changes in my program.because on console i never checked this

bbly
September 23rd, 2005, 09:50 AM
That is specific for MMC snapins, while the OP was talking about a DOS console box.

You should be able to catch the close command with SetConsoleCtrlHandler (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolectrlhandler.asp)


Thanks Marc!

-- These other guys .. jees, try reading the question.

Marc G
September 23rd, 2005, 09:59 AM
Thanks Marc!
You are welcome :)

-- These other guys .. jees, try reading the question.
Don't be so rude. They only wanted to help but made a mistake or misread the question. It can happen to everyone :wave: