C + + lets Win32 Console application program run in the background

Source: Internet
Author: User

Method One: (no flash) Add #pragma comment (linker, "/subsystem:\" windows\ "/entry:\" Maincrtstartup\ "") Method two: (This will have flashes)

#include "Windows.h"

void Main ()

{

HWND hwnd;

if (Hwnd=::findwindow ("Consolewindowclass", NULL))//Locate the console handle
{
:: ShowWindow (Hwnd,sw_hide); Hide Console window
}

Add your code. After the program runs, the window is automatically hidden and can only be seen in the process in Task Manager.

}

With the above code, the effect of hiding the current console window can be achieved. However, if the program is loaded automatically when the system is powered on, you will find that the console window is not automatically hidden, and if you close this window, double-click the console program to see that the window is hidden. To resolve this issue, you can use the following code:

#include "Windows.h"

void Main ()

{
Boot Auto Hide window
HWND hwnd;
Hwnd=findwindow ("Consolewindowclass", NULL);//Find the current window handle
if (HWND)
{
Showownedpopups (hwnd,sw_hide);//Show or hide all pop-up windows from the specified window
ShowWindow (hwnd,sw_hide);//control the visibility of the window
winexec function: Control window display Form
If the boot automatically run: C:\\windows\\system32\\keyboardrec.exe
WinExec ("C:\\windows\\system32\\keyboardrec.exe", sw_hide);
}

Your other code

}

Note: Hide the Code of the window, be sure to put it in front of the main function, otherwise the console window may not be hidden.

C + + lets Win32 Console application program run in the background

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.