/函数:PopFileSaveDlg /作用:弹出Save As对话框 BOOL PopFileSaveDlg (HWND hwnd,PSTR pstrFileName,PSTR pstrTitleName) ofn.hwndOwner=hwnd ofn.IpstrFile=pstrFileName ofn.IpstrFileTitle=pstrTitleName ofn.Flags=OFN OVERWRITEPROMPT return GetSaveFileName (&ofn); /函数:PopFileLength 作用:计算文件长度 static long PopFileLength (FILE *file) int iCurrentPos,iFileLength iCurrentPos ftell (file);
//函数:PopFileSaveDlg //作用:弹出Save As对话框 BOOL PopFileSaveDlg (HWND hwnd, PSTR pstrFileName, PSTR pstrTitleName) { ofn.hwndOwner= hwnd ; ofn.lpstrFile= pstrFileName ; ofn.lpstrFileTitle= pstrTitleName ; ofn.Flags= OFN_OVERWRITEPROMPT ; return GetSaveFileName (&ofn) ; } //函数:PopFileLength //作用:计算文件长度 static long PopFileLength (FILE *file) { int iCurrentPos, iFileLength ; iCurrentPos = ftell (file) ;
fseek (file,0,SEEK END); iFileLength ftell (file); fseek (file,iCurrentPos,SEEK SET); return iFileLength /函数:PopFileRead ∥作用:读取文件 BOOL PopFileRead (HWND hwndEdit,PSTR pstrFileName) { FILE *file; int iLength; PSTR pstrBuffer;
fseek (file, 0, SEEK_END) ; iFileLength = ftell (file) ; fseek (file, iCurrentPos, SEEK_SET) ; return iFileLength ; } //函数:PopFileRead //作用:读取文件 BOOL PopFileRead (HWND hwndEdit, PSTR pstrFileName) { FILE *file; int iLength; PSTR pstrBuffer;
打开文件 if (NULL ==(file fopen (pstrFileName,"rb"))) return FALSE: iLength=PopFileLength(fle);/获取文件长度 if (NULL==(pstrBuffer =(PSTR)malloc (iLength))) fclose(file);/关闭文件 return FALSE; fread (pstrBuffer,sizeof(char),iLength,file); 读取文件 fclose (file); pstrBuffer[iLength]=0';
//打开文件 if (NULL == (file = fopen (pstrFileName, "rb"))) return FALSE; iLength = PopFileLength (file);//获取文件长度 if (NULL == (pstrBuffer = (PSTR) malloc (iLength))) { fclose (file); //关闭文件 return FALSE; } fread (pstrBuffer, sizeof(char), iLength, file); //读取文件 fclose (file); pstrBuffer[iLength] = '\0';
SetWindowText (hwndEdit,pstrBuffer); /设置编辑框中的文本内容 return TRUE; /函数:PopFileWrite /作用:写文件 BOOL PopFileWrite (HWND hwndEdit,PSTR pstrFileName) FILE *file int iLength PSTR pstrBuffer if(NULL=(file=fopen(pstrFileName,"wb")/打开文件 return FALSE iLength GetWindowTextLength (hwndEdit); /获取编辑框中的文本内容长度
SetWindowText (hwndEdit, pstrBuffer); //设置编辑框中的文本内容 return TRUE; } //函数:PopFileWrite //作用:写文件 BOOL PopFileWrite (HWND hwndEdit, PSTR pstrFileName) { FILE *file ; int iLength ; PSTR pstrBuffer ; if (NULL == (file = fopen (pstrFileName, "wb")))//打开文件 return FALSE ; iLength = GetWindowTextLength (hwndEdit) ; //获取编辑框中的文本内容长度
if (NULL==(pstrBuffer =(PSTR)malloc (iLength +1))) {fclose(file);/关闭文件 return FALSE Q} /获取编辑框中的文本内容 GetWindowText (hwndEdit,pstrBuffer,iLength 1); /写文件 if (iLength !=(int)fwrite (pstrBuffer,1,iLength,file)) { fclose (file); /关闭文件 free (pstrBuffer); return FALSE;
if (NULL == (pstrBuffer = (PSTR) malloc (iLength + 1))) { fclose (file) ;//关闭文件 return FALSE ; } //获取编辑框中的文本内容 GetWindowText (hwndEdit, pstrBuffer, iLength + 1) ; //写文件 if (iLength != (int) fwrite (pstrBuffer, 1, iLength, file)) { fclose (file); //关闭文件 free (pstrBuffer); return FALSE; }