代码如下:
GetCurrentDateTime(&currDateTime); //获取系统时间
FormatDateTimeString (currDateTime, DATETIME_FORMATSTRING, NULL, 0); //格式化时间格式
bufferLen = FormatDateTimeString (currDateTime,
DATETIME_FORMATSTRING, NULL, 0);
dateTimeBuffer = malloc (bufferLen + 1); //根据指定大小分配空间
FormatDateTimeString (currDateTime, DATETIME_FORMATSTRING,
dateTimeBuffer, bufferLen + 1 );
strcpy(DirAttachPath, dateTimeBuffer);
strcat(DirAttachPath, ".tdms");
if(FileSelectPopup ("", DirAttachPath, "*.tdms","要保存的文件名",
VAL_SAVE_BUTTON,0,0,1,1, sFile ) >0)
{}
如何不弹出对话框就直接创建文件?
用 FileSelectPopup 当然会弹出对话框了。
如果是要创建TDMS文件用 TDMS_CreateFile 函数就可以了。直接指定文件路径等信息就可以创建了。在 TDM Streaming Library下面
zx158 wrote:代码如下:
GetCurrentDateTime(&currDateTime); //获取系统时间
FormatDateTimeString (currDateTime, DATETIME_FORMATSTRING, NULL, 0); //格式化时间格式
bufferLen = FormatDateTimeString (currDateTime,
DATETIME_FORMATSTRING, NULL, 0);dateTimeBuffer = malloc (bufferLen + 1); //根据指定大小分配空间
FormatDateTimeString (currDateTime, DATETIME_FORMATSTRING,
dateTimeBuffer, bufferLen + 1 );
strcpy(DirAttachPath, dateTimeBuffer);
strcat(DirAttachPath, ".tdms");
if(FileSelectPopup ("", DirAttachPath, "*.tdms","要保存的文件名",
VAL_SAVE_BUTTON,0,0,1,1, sFile ) >0){}
如何不弹出对话框就直接创建文件?
Well, you can notice the FileSelectPopup function? This is why there will be a pop up message box, and I think this code have nothing to do with creating a file, you can just find the function which have something to do with creating files, specify a file name with dates or time or anything else, just delete this function
如果是写普通的文本或者二进制文件,直接用 OpenFile() 即可,参数选择VAL_READ_WRITE 就可以创建文件了。比如:
OpenFile ("c:\\1.txt", VAL_READ_WRITE, VAL_OPEN_AS_IS, VAL_ASCII);
写TDMS用我前面回帖里说的 TDMS_CreateFile
int TDMS_CreateFile (const char *File_Path, TDMSFileFormat File_Format, const char *Name, const char *Description, const char *Title, const char *Author, TDMSFileHandle *File);
这两个都不会弹出窗口,直接可以创建
创建文件可以用下面的函数实现:
下面的代码是在工程目录下创建一个文本文件,你用的是TMDS的文件格式只是在写文件内容时会有区别。
char testfile[STRLEN]; /*文件名*/
char suffix[20] = "00.txt";
int number=1;
FILE *pftest;
GetDir (filename);
Fmt(suffix,"\\OUTPUT\\CN07-%d.txt",number++);
strcat(filename,suffix);
pftest=fopen (filename,"w+");
fprintf( pftest,"SwitchCode 7\nSetImagePath C:\\CN07");
fclose(pftest);
这个时候在工程目录下的OUPUT文件夹里会有一个为CN07-1.TXT的文件,打开文件里面会有SwitchCode 7 和SetImagePath C:\\CN07两行文本了。