Implementation of emergency removal during the disappearance of lianggong spring

Source: Internet
Author: User

I recently watched the deprecated Theatrical Version of the Spring Festival of lianggong. The plot is amazing. However, as a programmer, I am very interested in the film's "coming out urgently, after watching the movie, I decided to implement this mini-program by myself. However, I did not expect that some difficulties were encountered when I completed this program, but it was still normal at last. Here we will share with you several main methods of this program.

First of all, the long-winded ones are not printed on the screen, but printed one by one. In addition, there is a pause after each piece of information. To implement this output method, I wrote the following function:

The first parameter of this function is the string to be output, the second parameter, and the third parameter is the delay of printing each word and the delay of printing each word, and whether to wrap the line after printing the current string, it is determined by a Boolean value n.

void output(wstring str, int timea, int timeb,bool n){    for (string::size_type i = 0; i < str.size(); i++)    {        setlocale(LC_ALL ,"chs");        Sleep(timea);        wprintf(L"%c",str[i]);    }    if (n)    {         printf("\n");    }    Sleep(timeb);}

Then, I output the piece of story, which means that, according to the story, press enter and it will return to the event processing function three years ago after 20:30 on the Chinese Valentine's Day.

Void printmessage () {wstring s;/**/S = l "Yuki. n> when there are too many threads running, \ n too many threads running too many threads. "; Output (S, 100,300,); s = l" Yuki. n> when there are too many threads, there are too many threads, \ n when there are too many threads, zookeeper and \ n ancient Spring trees exist in zookeeper and zookeeper. "; Output (S, 100,300,); s = l" Yuki. n> commandid keys. \ N too many answers. For more information, see "too many answers. "; Output (S, 100,300,); s = l" Yuki. n> zookeeper emerged urgently. \ N when starting zookeeper, when starting zookeeper, when using zookeeper. \ N when starting strongswan, \ n when starting strongswan, and time-space correction when the opportunity is too late. \ N zookeeper success guarantee against zookeeper failure. \ N too many bytes and ensure that they are too many bytes. "; Output (S, 100,300,); s = l" Yuki. n> too many attempts have been initiated when starting when too many attempts have been made. \ N rows have been deleted and deleted. \ N for non-empty rows, select "too many rows". When "too many rows" are selected, the system will start to remove "too many rows. \ N ready? "; Output (S, 100,300);/**/If (_ getch () = 13) {for (int K = 1; k <20; k ++) {system ("color FC"); System ("color 07");} systemtime st; getlocaltime (& St); ST. wyear-= 3; ST. wmonth = 7; ST. wday = 7; ST. whour = 20; ST. wminute = 30; setlocaltime (& St); exit (1) ;}else {S = l "Yuki. n> remove zookeeper. "; Output (S, 100,100, 0); s = l "..... "; Output (S, 500,300 );}}

Next, in order to maximize the display of the output window on the screen, use the analog button to maximize the output window

void FullScreen()  {      keybd_event(VK_MENU,          0x38,          0,          0);      keybd_event(VK_RETURN,          0x1c,          0,          0);      keybd_event(VK_RETURN,          0x1c,          KEYEVENTF_KEYUP,          0);      keybd_event(VK_MENU,          0x38,          KEYEVENTF_KEYUP,          0);  }  

The next step is where I encountered a problem. Because in the story, the program will be deleted if the program is not confirmed. This encountered a problem. How to let the program delete itself is actually a variety of methods to achieve self-deletion of the program. Some programs are completely copied to the memory, and then exit the program. They are self-deleted using programs in the memory, and Windows batch files are also used for self-deletion. I am a practical latter. The Code is as follows. I have added comments to key points.

Void selfdelete () {static char Templ [] = ": repeat \ r \ n "" Del \ "% s \" \ r \ n "" If exist \ "% s \" Goto repeat \ r \ n "" rmdir % s \ r \ n "" Del \ "% s \""; // The main structure of the BAT file. After deleting the program, you can delete it yourself. Batch files are static const char tempbatname [] = "_ uninsep. bat "; // batch processing file name char modulename [max_path]; char temppath [max_path]; char folder [max_path]; gettemppatha (max_path, temppath); strcat (temppath, tempbatname ); getmodulefilenamea (null, modulename, max_path); strcpy (folder, modulename); char * pb = strrchr (folder, '\'); If (PB! = NULL) * pb = 0; // The above code is used to obtain the path and file name of the current program, and finally store the entire path and file name in the folder variable, obtain the path for storing temporary files in the current system, and store the temporary files in the temppath handle Hf; HF = createfilea (temppath, generic_write, 0, null, create_always, file_attribute_normal, null); If (HF! = Invalid_handle_value) {DWORD Len; char * BAT; BAT = (char *) alloca (strlen (Templ) + strlen (modulename) * 2 + strlen (temppath) + 20 ); sprintf (BAT, Templ, modulename, modulename, folder, temppath); writefile (HF, bat, strlen (BAT), & Len, null); closehandle (HF ); free (BAT); // combines all the previously obtained data. The creation will delete the program and its own bat file shellexecutea (null, "open", temppath, null, null, sw_hide); // execute this file through ShellExecute. Because it is used to write narrow characters, shellexecutea }}

Then the main program

int _tmain(int argc, _TCHAR* argv[]){    FullScreen();    system("color fc");    system("color 8c");    system("color 07");    Sleep(2000);    printmessage();    SelfDelete();    exit(1);    return 0;}

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.