Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SPO-2.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <windows.h>
- #include <conio.h>
- #include <process.h>
- #include <locale.h>
- #define MAX_COUNT 12
- PROCESS_INFORMATION CreateNewProcess(TCHAR* AppName, TCHAR *cmd);
- void Contol(TCHAR *AppName);
- void DrawString(int);
- void fTryPrintf(HANDLE hProcCanWrite, char* str);
- int _tmain(int argc, TCHAR* argv[])
- {
- setlocale(LC_ALL, "");
- if(argc == 2){
- DrawString( _ttoi(argv[1]) );
- }
- else{
- Contol(argv[0]);
- }
- return 0;
- }
- void Contol(TCHAR *AppName)
- {
- int Number = 0;
- HANDLE hProcCanWrite = CreateEvent(NULL, FALSE, TRUE, TEXT("ProcCanWrite"));
- char ch;
- PROCESS_INFORMATION MasOfPi[MAX_COUNT];
- while( ch = _getch() )
- {
- if(ch == 'q'){
- break;
- }
- if(ch=='-' && Number) {
- TerminateProcess(MasOfPi[Number-1].hProcess, 0);
- CloseHandle(MasOfPi[Number-1].hProcess);
- CloseHandle(MasOfPi[Number-1].hThread);
- Number--;
- if ( Number == 0 )
- {
- SetEvent(hProcCanWrite);
- }
- }
- if((ch == '+') && (Number < MAX_COUNT ))
- {
- TCHAR buf[30] = {0};
- _itot_s(Number, buf, 10);
- MasOfPi[Number] = CreateNewProcess( AppName, buf);
- Number++;
- }
- }
- for(int i = 0; i < Number; i++)
- {
- TerminateProcess(MasOfPi[i].hProcess, 0);
- CloseHandle(MasOfPi[i].hProcess);
- CloseHandle(MasOfPi[i].hThread);
- }
- }
- TCHAR* createArgsString(TCHAR* app, TCHAR* arg)
- {
- TCHAR args[100] = {0};
- _tcscat_s( args, app);
- _tcscat_s( args, TEXT(" "));
- _tcscat_s( args, arg);
- return args;
- }
- PROCESS_INFORMATION CreateNewProcess(TCHAR* AppName, TCHAR *cmd)
- {
- STARTUPINFO cif;
- ZeroMemory(&cif,sizeof(STARTUPINFO));
- PROCESS_INFORMATION pi;
- if(!CreateProcess(
- NULL,
- createArgsString(AppName, cmd),
- NULL,
- NULL,
- TRUE,
- NULL,
- NULL,
- NULL,
- &cif,
- &pi )
- )
- {
- puts("Create process failed!");
- }
- return pi;
- }
- char* getTextString(int number){
- static char outputStringArray[MAX_COUNT][150] = {
- "Nirvana was an American rock band that was formed by singer/guitarist Kurt Cobain and bassist Krist Novoselic ",
- "In early 1986, Queen recorded the album A Kind of Magic, containing several reworkings of songs written for the fantasy action film Highlander. ",
- "Scorpions are a rock band from Hannover, Germany formed in 1965 by guitarist Rudolf Schenker. ",
- "Metallica has released nine studio albums, three live albums, five extended plays, 24 music videos, and 45 singles. ",
- "Bon Jovi is an American rock band from Sayreville, New Jersey. ",
- "The Final Countdown is the third studio album by the Swedish hard rock band Europe. Released on 26 May 1986. ",
- "Rammstein was founded by guitarist Richard Z. Kruspe. In 1989, he escaped to West Berlin and started the band Orgasm Death Gimmicks. ",
- "Louna is a Russian Alternative/Punk rock band, formed in Moscow in 2008 by Tracktor Bowling's musicians Lusine Gevorkyan and Vitaly Demidenko ",
- "Sonic Syndicate is a heavy metal band from Falkenberg, Sweden. ",
- "Skillet is an American Christian rock band formed in Memphis, Tennessee in 1996. ",
- "Надежда Никитична Кадышева (род. 1 июня 1959, Горки, Лениногорский район, Татарская АССР) — российская певица эрзянского происхождения. ", // easter egg %)
- "The Beatles are unquestionably the best and most important band in rock history, as well as the most compelling story. "
- };
- return outputStringArray[number];
- }
- void DrawString( int number )
- {
- int pid = _getpid();
- HANDLE hProcCanWrite = OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("ProcCanWrite") );
- while( 1 )
- {
- fTryPrintf(hProcCanWrite, getTextString(number) );
- }
- }
- void fTryPrintf(HANDLE hProcCanWrite, char* str)
- {
- if(WaitForSingleObject( hProcCanWrite, INFINITE) == WAIT_OBJECT_0)
- {
- ResetEvent(hProcCanWrite);
- for ( int i = 0; i < strlen(str); ++i)
- {
- printf_s("%c", str[i] );
- Sleep(50);
- }
- Sleep(100);
- SetEvent(hProcCanWrite);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement