我用hFocus取得当前活动窗口句柄,判断如果跟上次的活动窗口句柄不一样就读入,并用szTitle保存下来,可是为什么fprintf(stream,"%C%S%C%C%S",10,time1+time2,32,32,szTitle);后logfile.txt中有时间没有szTitle记录的标题呢,代码在下边
FILE *stream=fopen("c:\\logfile.txt","a+t");
//char szTitle[256];//当前窗口名称
hFocus=::GetActiveWindow();//取得当前活动窗口句柄
if(g_hLastFocus!=hFocus)
{
::GetWindowText(hFocus,szTitle,256);
g_hLastFocus=hFocus;
CTime pt;
CString time1,time2;
pt=CTime::GetCurrentTime();
time1=pt.Format(_T("%A, %B %d, %Y "));
time2=pt.Format(_T("%H : %M : %S "));
fprintf(stream,"%C%S%C%C%S",10,time1+time2,32,32,szTitle);
fprintf(stream,"%C%C",32,32);
fprintf(stream,"\r\n",32);
}
这是怎么回事啊?
FILE *stream=fopen("c:\\logfile.txt","a+t");
//char szTitle[256];//当前窗口名称
hFocus=::GetActiveWindow();//取得当前活动窗口句柄
if(g_hLastFocus!=hFocus)
{
::GetWindowText(hFocus,szTitle,256);
g_hLastFocus=hFocus;
CTime pt;
CString time1,time2;
pt=CTime::GetCurrentTime();
time1=pt.Format(_T("%A, %B %d, %Y "));
time2=pt.Format(_T("%H : %M : %S "));
fprintf(stream,"%C%S%C%C%S",10,time1+time2,32,32,szTitle);
fprintf(stream,"%C%C",32,32);
fprintf(stream,"\r\n",32);
}
这是怎么回事啊?
fprintf(stream,"%c%c",32,32); %C改成%c
%S改成%s
我代码里是用数组存放的wchar_t szTitle[256];
怎么转啊?我初学VC,不会啊,请楼上的大侠帮帮忙啊!!!!
Saturday, March 22, 2008 16 : 56 : 55
kstar
我刚试了,还是没有输出标题来.... 写入文件后的效果:
Saturday, March 22, 2008 16 : 56 : 55
kstar
我调试了,CString(szTitle)里面的内容是正确的..
#include <stdio.h>
#include <process.h> FILE *stream; void main( void )
{
int i = 10;
double fp = 1.5;
char s[] = "this is a string";
char c = '\n'; stream = fopen( "fprintf.out", "w" );
fprintf( stream, "%s%c", s, c );
fprintf( stream, "%d\n", i );
fprintf( stream, "%f\n", fp );
fclose( stream );
system( "type fprintf.out" );
} 屏幕输出: this is a string
10
1.500000