Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SPO-1-win.cpp : Defines the entry point for the console application.
- #include "stdafx.h"
- #include <Windows.h>
- #include <stdio.h>
- #include <tchar.h>
- #include <conio.h>
- void PrintLocalTime( int x, int y);
- void _tmain( int argc, TCHAR *argv[] )
- {
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- ZeroMemory( &si, sizeof(si) );
- si.cb = sizeof(si);
- ZeroMemory( &pi, sizeof(pi) );
- // Parent process
- if ( argc == 1){
- // Set args for child process
- TCHAR cmdlineargs[100] = {0};
- _tcscat_s( cmdlineargs, *argv);
- _tcscat_s( cmdlineargs, TEXT(" -child"));
- // Start the child process.
- if( !CreateProcess(
- NULL, // No module name (use command line)
- cmdlineargs, // Command line
- NULL, // Process handle not inheritable
- NULL, // Thread handle not inheritable
- FALSE, // Set handle inheritance to FALSE
- 0, // No creation flags
- NULL, // Use parent's environment block
- NULL, // Use parent's starting directory
- &si, // Pointer to STARTUPINFO structure
- &pi ) // Pointer to PROCESS_INFORMATION structure
- )
- {
- printf( "CreateProcess failed (%d).\n", GetLastError() );
- return;
- }
- // Print time in parent process
- PrintLocalTime( 40, 40);
- }
- else{
- // Print time in child process
- PrintLocalTime( 40, 60);
- }
- // Close process and thread handles.
- CloseHandle( pi.hProcess );
- CloseHandle( pi.hThread );
- }
- // Print current time in specified area of console.
- void PrintLocalTime( int x, int y){
- HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
- SYSTEMTIME currentTime;
- COORD xy = {x, y};
- while( !_kbhit() )
- {
- GetLocalTime(¤tTime);
- SetConsoleCursorPosition(consoleHandle, xy);
- printf("Current Time %.2d:%.2d:%.2d", currentTime.wHour, currentTime.wMinute, currentTime.wSecond);
- Sleep(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement