I make the bakcground running program. this program is just simple [05:00 - reboot]..
I want hide the console windows..
Start from the beginning to background the console window
help.
#include "stdafx.h"
#include "stdio.h"
#include "windows.h"
#include "time.h"
#include "shellapi.h"
using namespace std;
int main()
{
while (true) {
time_t timer = time(NULL);
struct tm t;
localtime_s(&t, &timer);
int count_1 = 0;
if (t.tm_hour == 5) {
if (t.tm_min == 00) {
if (count_1 == 0) {
count_1 = 1;
WCHAR path[260];
GetModuleFileName(NULL, path, 260);
HWND console = FindWindow(L"ConsoleWindowClass", path);
if (IsWindow(console))
ShowWindow(console, SW_HIDE); // hides the window
system("shutdown -r");
if (IsWindow(console))
ShowWindow(console, SW_SHOW); // shows the window
}
}
}
}
}
Usually you would use the WinMain
entry point instead of main
.
But you need to tell your compiler that you're using WinMain
which is compiler dependent.
By the way, there is a simpler way to hide the console window.
ShowWindow(GetConsoleWindow(), SW_HIDE);
But be aware that using this method the console is still being created and you might see it for a fraction of a second.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.