2

I want a C++ program to execute a function when I close manually the console.
I made a C++ program that test a password and if it isn't correct make the windows to log off. But if I close the console from the "X" button nothing happens and I want to make windows to log off too if the console is closed from "X" button?
I tried _onexit_t oe() function but it doesn't help me.
So there is a method to do that or to hide the bar which contains the "Minimize", "Maximize" and "Close" buttons?

Useless
  • 64,155
  • 6
  • 88
  • 132
Victor Laurentiu
  • 145
  • 1
  • 2
  • 9
  • See http://stackoverflow.com/questions/9788662/how-do-i-repurpose-a-windows-close-button-without-affecting-altf4-or-closing-i, specifically WM_CLOSE – Jono Nov 20 '12 at 21:02
  • You probably want to handle WM_CLOSE event in the window procedure. – jaho Nov 20 '12 at 21:03
  • Also see http://stackoverflow.com/questions/10101742/difference-between-wm-close-and-sc-close, http://stackoverflow.com/questions/3155782/what-is-the-difference-between-wm-quit-wm-close-and-wm-destroy-in-a-windows-pr – Jono Nov 20 '12 at 21:04

1 Answers1

2

Assuming you mean the normal textual console window, you can register your own event handler via SetConsoleCtrlHandler and watch for the events CTRL_C_EVENT, CTRL_BREAK_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT, etc.

mark
  • 5,269
  • 2
  • 21
  • 34