Let's break it into smaller pieces:
void hide();
int main()
{
hide();
MSG Msg;
//IO::MKDir(IO::GetOurPath(true));
//InstallHook();
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
The above loop is what's called a message pump. As windows GUI programs are event-driven, such a loop is the pattern to handle incoming windows messages for your windows process. As your program will be receiving the WM_QUIT
message, GetMessage()
will return FALSE
and the loop will exit. TranslateMessage()
is just there to translates virtual-key messages to character messages, for further handling down the pipeline in case you need that. DispatchMessage()
is there to make sure messages being sent to specific windows will find their way to that window's WindowProc callback.
//MailTimer.Stop();
return 0;
}
void hide()
{
HWND stealth;
AllocConsole();
The last line above is allocating a new console for the process.. In case your process already has a console this call fails, indicated by returning zero.
stealth = FindWindowA("ConsoleWindowClass", NULL);
What FindWindowA()
does is return a window handle (HWND
) to the window that has the specified class name and window name. Here it is used while omitting the name (second argument) and specifying only the class, for which only a single window could exist in this case of a console window, the class of which is "ConsoleWindowClass"
.
ShowWindow(stealth, 0);
}
All this line does is hiding the window identified by the handle being passed, which is our console window, as we already know by this point in the snippet. The second argument 0
in this case is the enumerator value of SW_HIDE
, hence after this line the console window is being hidden.