Advertisement
rnort

Untitled

Sep 16th, 2012
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. //SPO-1-win.cpp : Defines the entry point for the console application.
  2.  
  3. #include "stdafx.h"
  4. #include <Windows.h>
  5. #include <stdio.h>
  6. #include <tchar.h>
  7. #include <conio.h>
  8.  
  9.  
  10. void PrintLocalTime( int x, int y);
  11.  
  12. void _tmain( int argc, TCHAR *argv[] )
  13. {
  14.     STARTUPINFO si;
  15.     PROCESS_INFORMATION pi;
  16.  
  17.     ZeroMemory( &si, sizeof(si) );
  18.     si.cb = sizeof(si);
  19.     ZeroMemory( &pi, sizeof(pi) );
  20.  
  21.     // Parent process
  22.     if ( argc == 1){
  23.  
  24.         // Set args for child process
  25.         TCHAR cmdlineargs[100] = {0};
  26.         _tcscat_s( cmdlineargs, *argv);
  27.         _tcscat_s( cmdlineargs, TEXT(" -child"));
  28.        
  29.  
  30.         // Start the child process.
  31.         if( !CreateProcess(
  32.             NULL,           // No module name (use command line)
  33.             cmdlineargs,    // Command line
  34.             NULL,           // Process handle not inheritable
  35.             NULL,           // Thread handle not inheritable
  36.             FALSE,          // Set handle inheritance to FALSE
  37.             0,              // No creation flags
  38.             NULL,           // Use parent's environment block
  39.             NULL,           // Use parent's starting directory
  40.             &si,            // Pointer to STARTUPINFO structure
  41.             &pi )           // Pointer to PROCESS_INFORMATION structure
  42.             )
  43.         {
  44.             printf( "CreateProcess failed (%d).\n", GetLastError() );
  45.             return;
  46.         }
  47.         // Print time in parent process
  48.         PrintLocalTime( 40, 40);
  49.     }
  50.     else{
  51.         // Print time in child process
  52.         PrintLocalTime( 40, 60);
  53.     }
  54.  
  55.     // Close process and thread handles.
  56.     CloseHandle( pi.hProcess );
  57.     CloseHandle( pi.hThread );
  58. }
  59.  
  60. // Print current time in specified area of console.
  61. void PrintLocalTime( int x, int y){
  62.    
  63.     HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
  64.     SYSTEMTIME currentTime;
  65.     COORD xy = {x, y};
  66.     while( !_kbhit() )
  67.     {
  68.         GetLocalTime(&currentTime);
  69.         SetConsoleCursorPosition(consoleHandle, xy);
  70.         printf("Current Time %.2d:%.2d:%.2d", currentTime.wHour, currentTime.wMinute, currentTime.wSecond);
  71.         Sleep(1000);
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement