Ive been searching for a while but i cant seem to fix my problem. I want to be able to make my program detect the computer powering down. My code is always running in the background and when the computer is powering down i want it to save what its doing and then close. If anyone wants me to post my code i would be glad to do so.
If you mean the windowless like the black box then yes it is windowless. (I didn't want to deal with the black box all the time. ) If you mean windowless as in have a pop up come up then i don't want any pop ups or anything, i just want it to be unnoticed.
I mean: does your application main thread create any window (hidden or minimized) or it is just a console application?
If there is a window that it should receive the system messages like WM_QUERYENDSESSION, WM_ENDSESSION...
You'll need to write either a windowed app so you have a means to handle WM_QUERYENDSESSION etc like VictorN mentioned.
Or you will need to write this as a proper service. You can then handle service start/stop requests.
Note that the WM_QUERYENDSESSION messages are for logoff, not for reboot of the machine, this may or may not be relevant to your needs.
ok heres the code, try and see what you can do to make it log the keys when you turn off the computer. (just like the f8 key) also i dont really know what the hwnd "pie" part does, so feel free to fix that aswell. :
You can't "log" keys for anything other than your console app. Doing anything outside of the console window will not result in anything in your app.
while you can detect keys outside of your own app via a global hook (not the easiest of things)
that still doesn't cover mouse actions that cause a logoff. You can hook those as wel (not easiest of things). But that still won't help you to detect that a logoff is about to happen with any realistically useful accuracy.
looking at yoru code and what you're lookign at doing, I think you're way over year head trying to make something you're not even at all ready for. I'd suggest working some simpler , more straightforward projects first.