A sample program demonstrates some tips on the console:
L hide the console window
L disable the console window close button
L minimize Console window startup
L console programs are automatically started upon startup
L prevent the console window from being closed through Ctrl + C (this function is cross-platform)
L add icons for console programs
/** <Br/> * @ file main. CPP <br/> * @ brief demonstrate how to hide the console window, disable the close button, minimize the startup of the console window, and change the console icon. <Br/> * @ author Hao liming <br/> * @ date 9:11:51 <br/> * @ version 0.1 <br/> * <PRE> <B> copyright: </B> </PRE> <br/> * <PRE> <B> Email: </B> hao.limin@gmail.com </PRE> <br/> * <PRE> <B> company: </B> http://blog.csdn.net/donhao </PRE> <br/> * <PRE> <B> All Rights Reserved. </B> </PRE> <br/> * <PRE> <B> modification: </B> </PRE> <br/> * <PRE> write modifications here. </PRE> <br/> */</P> <p>/** <br/> * @ brief <br/> *. hidden Control The console window, the disabled button, the minimized Console window startup, and the self-starting console program are implemented in the main function. <br/> * B. The implementation of changing the console program icon is described here. In vs2008, you can directly create icons and bind them to resource files. Only vc6 is described here. <Br/> * 1. Create an icon file. "File"-> "new"-> "icon file"-> If the input file name is pic, the icon file name is pic. ICO <br/> * 2. create a resource file. "File"-> "new"-> "resource script"-> enter a resource name with the same name as the project. In this example, It is lelemanamengent. RC <br/> * 3. modify the resource file. Use NotePad to open lelemanamengent. RC in the project directory and add idi_icon1 icon discardable "pic. ICO" <br/> * 4. Save the resource file and recompile it. <Br/> * 5. Note. The icons in this example are 16 and 32*32. <Br/> * 6. prevent the console window from being closed through Ctrl + C (this function is cross-platform) <br/> */</P> <p>/** @ the header file required by brief */<br/> # include <windows. h> <br/> # include <signal. h> <br/> # include <stdio. h> </P> <p> void breakdeal (INT nsig); </P> <p>/** @ Brief 1. hide Console window */<br/> # pragma comment (linker, "/subsystem:/" Windows/"/entry:/" maincrtstartup /"") </P> <p> int main (INT argc, char * argv []) <br/> {<br/>/** @ brief 6. prevent the console window from being closed through Ctrl + C (this function is cross-platform) */<br/> signal (SIGINT, Breakdeal); </P> <p> char Buf [max_path]; <br/> getconsoletitle (BUF, max_path); <br/> hwnd = :: findwindow (null, Buf); <br/> hmenu =: getsystemmenu (hwnd, false); <br/> If (hwnd) <br/> {<br/>/** @ brief 2. disable the close button of the console window */<br/>: removemenu (hmenu, SC _close, mf_bycommand); </P> <p>/** @ Brief 3. minimum window size when the console program starts */<br/>: sendmessage (hwnd, wm_syscommand, SC _minimize, 0 ); <br/>}</P> <p>/** @ Brie F 4. obtain the current path of the server startup program and add it to the Registry for Automatic startup */<br/> tchar workingpath [max_path]; <br/> zeromemory (workingpath, max_path ); </P> <p> If (getmodulefilename (null, workingpath, max_path)> 0) <br/>{< br/>/** sets the job path of the EXE program, set the path where the EXE file is located as the working path */<br/> char path [3000]; <br/> memset (path, 0, 3000 ); <br/> for (INT I = strlen (workingpath)-1; I> = 0; -- I) <br/>{< br/> If (workingpath [I] = '//') <br/>{< br/> strncpy (path, Workingpath, I + 1); <br/> break; <br/>}< br/> setcurrentdirectory (PATH ); </P> <p>/** succeeded in obtaining the current working path */<br/> hkey; <br/> If (regcreatekey (HKEY_LOCAL_MACHINE, "Software // Microsoft // windows // CurrentVersion // run", & hkey )! = Error_success) <br/>{< br/>/** registry created successfully */<br/>}< br/> else <br/>{< br/> If (regsetvalueex (hkey, "CASCO log sever", 0, REG_SZ, (const byte *) (lpctstr) workingpath, strlen (workingpath ))! = Error_success) <br/>{< br/>/** An error occurred while setting the registry, disabled */<br/>}< br/> else <br/> {<br/>/** the registry is successfully set, startup setting successful */<br/>}< br/> regclosekey (hkey ); <br/>}< br/> else <br/> {<br/>/** An error occurred while obtaining the current working path, not self-starting */<br/>}< br/> return 0; <br/>}</P> <p> void breakdeal (INT nsig) <br/> {<br/> printf ("You can not exit the program by Ctrl + C. /n "); <br/> signal (nsig, breakdeal); <br/>}