Hatena::Grouprubyist

たばさの RSSフィード

04/20(水) 2011

beep音、その2

14:57 | beep音、その2 - たばさの を含むブックマーク はてなブックマーク - beep音、その2 - たばさの

ひさびさにcpp言語でも。おぼえてないー

filetimecheckloop.cpp

//--------------------------------------
//	filetimecheckloop.cpp	ver.0.1
//	
//	ファイルtimestamp check loop
//	
//	
//	2011/04/20
//
//

#include <windows.h>
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>


const nmax=1000;
const int buffmax=2048;

char file[nmax]="";
char form[nmax]="%04d/%02d/%02d %02d:%02d:%02d";//書式
char infname[buffmax]="";

char buff[buffmax*5];


char nengappi[nmax];


char* comparetimestamp()
{
	char command0[nmax+nmax];

	FILETIME ftime,ltime;
	SYSTEMTIME	sytime;
	LPSYSTEMTIME	stime=&sytime;
	HANDLE file=
	CreateFile(
		infname,
		GENERIC_READ,
		FILE_SHARE_READ|FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,
		NULL
	);
	GetFileTime(file,NULL ,NULL,&ftime);
	FileTimeToLocalFileTime(&ftime,&ltime);
	FileTimeToSystemTime(&ltime,stime);
	sprintf(
		nengappi,
		form,
	
		stime->wYear,
		stime->wMonth,
		stime->wDay,
		stime->wHour,
		stime->wMinute,
		stime->wSecond
	);
	return nengappi;
}

mybeep()
{
	int b=880;
	Beep(b,48);
	for(int i=1;i*220<4400;i++){
		Sleep(24);
		Beep(b+i*220,24);
	}
}

//-------------------------------------------
int main(int argc, char** argv)
{
	sprintf(infname,argv[1]);
	cout<<"file: "<<infname<<endl;
	char ngp[nmax],old_ngp[nmax];

	for( int i=0;;i++){
		strcpy(ngp,comparetimestamp());
		if(strcmp(ngp,old_ngp)){
			cout<<ngp<<endl;
			mybeep();
			strcpy(old_ngp,ngp);
		}
		else
		{
			// cout<<",";
		}
		Sleep(200);
	}
	return(0);
} 

実行例

> filetimecheckloop "c:\Document .. \nantoka"

ここに置きました

http://tabasano.sakura.ne.jp/mono/

トラックバック - http://rubyist.g.hatena.ne.jp/hatecha/20110420