Windows hides the system function pop-up window

Source: Internet
Author: User

Overview

The following program is a window popup issue that resolves when you call the system () function under Windows

Header file
#include <windows.h>
Source
/** * @brief ordinary character-width character * * @param lpcszstr Ordinary character * @param lpwszstr wide character after conversion * @param dwsize the size of the buffer that stores the wide character * * @return*/BOOL Mbytetowchar (LPCSTR lpcszstr, LPWStr lpwszstr, DWORD dwsize) {//Get The required size of the buffer that receives the Unicode//string.DWORD dwminsize;dwminsize= MultiByteToWideChar (CP_ACP,0, Lpcszstr,-1Null0);if(Dwsize <dwminsize) {returnFALSE;}//Convert headers from ASCII to Unicode.MultiByteToWideChar (CP_ACP,0, Lpcszstr,-1, Lpwszstr, dwminsize); returnTRUE;}
/** * @brief wide character to normal character * * @param lpcwszstr wide character * @param lpszstr normal character after conversion * @param dwsize stores the buffer size of ordinary characters * * @return*/BOOL wchartombyte (lpcwstr lpcwszstr, LPSTR Lpszstr, DWORD dwsize) {DWORD Dwminsize;dwminsize= WideCharToMultiByte (CP_OEMCP,0, lpcwszstr,-1Null0, null,false);if(Dwsize <dwminsize) {returnFALSE;} WideCharToMultiByte (CP_OEMCP,0, lpcwszstr,-1, lpszstr,dwsize,null,false);returnTRUE;}
/** * @brief * winexec and ShellExecute Two functions do not wait for the execution of the command to complete, * will cause the file did not extract finished, do not meet our needs * RET=WINEXEC (cmd,sw_hide); ShellExecute (HWND) "Open", Lpcwstr (cmd), NULL, null,null,sw_hide); * * The system function call can, but there will be a window popup * ret = System (CMD); * * in the following way * * @param cmd cannot appear in the > symbol * * @return **/intNb_system (Char*cmd) {wchar_t cmd_w[2048] = {0}; Mbytetowchar (cmd, Cmd_w,sizeof(CMD_W)/sizeof(cmd_w[0])); Startupinfo si; ZeroMemory (&si,sizeof(SI)); SI.CB=sizeofStartupinfo; Process_information Pi={0};if(CreateProcess (Null,cmd_w,null,null,true,normal_priority_class | create_no_window,null,null,&si,&pi)) {//wait for the process to finish executingWaitForSingleObject (pi.hprocess, INFINITE);//Freeing ResourcesCloseHandle (pi.hprocess); CloseHandle (Pi.hthread); }Else{//failed to runreturn-1;}return 0;}
Test
int Main () {   Nb_system ("dir");}

Windows hides the system function pop-up window

Related Article

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.