Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.9 KiB

  1. #include <windows.h>
  2. #include <string.h>
  3. #include <commdlg.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "resource.h"
  7. OPENFILENAME ofn ; //�ɮ׸��T���c
  8. // ���o�ɮת���
  9. LONG FileLen(HFILE hFile)
  10. {
  11. long Len,curpos=_llseek(hFile,0L,1);
  12. Len=_llseek(hFile,0L,2);
  13. _llseek(hFile,curpos,0);
  14. return Len;
  15. }
  16. int IsUniCode(char *FileName)
  17. {
  18. FILE *fptr;
  19. WORD temp;
  20. if((fptr = fopen(FileName,"rb")) ==NULL)
  21. return IDS_ERROPENFILE;
  22. fread(&temp,1,2,fptr);
  23. fclose(fptr);
  24. if (temp!=0xFEFF)
  25. return IDS_ERRUNICODE;
  26. return 0;
  27. }
  28. /////////////////////////////////////////////////////////////////////////////
  29. int GetFilePath(char *FileName)
  30. {
  31. int i=strlen(FileName)-1;
  32. while(i>0 && FileName[i]!='\\') i--;
  33. return i;
  34. }
  35. BOOL PopFileOpenDlg (HWND hwnd, char *FileName, char *TitleName,char *Filter)//, int index)
  36. {
  37. char szDir[256];
  38. int i=GetFilePath(FileName);
  39. if(i>0)
  40. {
  41. strncpy(szDir,FileName,i); szDir[i]=0;
  42. strcpy (FileName,FileName+i+1);
  43. }
  44. else szDir[0]=0;
  45. ofn.lpstrInitialDir = szDir ;
  46. ofn.hwndOwner = hwnd ;
  47. ofn.lpstrFile = FileName ;
  48. ofn.lpstrTitle = TitleName ;
  49. ofn.lpstrFilter = Filter ;
  50. //if(index) ofn.nFilterIndex = index ;
  51. ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |OFN_HIDEREADONLY;
  52. return GetOpenFileName (&ofn) ;
  53. }
  54. BOOL PopFileSaveDlg (HWND hwnd, char *FileName, char *TitleName,char *Filter)//,int index)
  55. {
  56. char szDir[256];
  57. int i=GetFilePath(FileName);
  58. if(i>0)
  59. {
  60. strncpy(szDir,FileName,i); szDir[i]=0;
  61. strcpy (FileName,FileName+i+1);
  62. }
  63. else szDir[0]=0;
  64. ofn.hwndOwner = hwnd ;
  65. ofn.lpstrFile = FileName ;
  66. ofn.lpstrTitle = TitleName ;
  67. ofn.lpstrFilter = Filter ;
  68. //if(index) ofn.nFilterIndex = index ;
  69. ofn.Flags = OFN_OVERWRITEPROMPT ;
  70. return GetSaveFileName (&ofn) ;
  71. }
  72. void PopFileInit ()
  73. {
  74. ofn.lStructSize = sizeof (OPENFILENAME) ;
  75. ofn.hInstance = NULL ;
  76. //ofn.lpstrFilter = szFilter ;
  77. ofn.lpstrCustomFilter = NULL ;
  78. ofn.nMaxCustFilter = 0 ;
  79. ofn.nFilterIndex = 1 ;
  80. ofn.lpstrFile = NULL ; // Set in Open and Close functions
  81. ofn.nMaxFile = _MAX_PATH ;
  82. ofn.lpstrFileTitle = NULL ; // Set in Open and Close functions
  83. ofn.nMaxFileTitle = _MAX_FNAME + _MAX_EXT ;
  84. ofn.lpstrInitialDir = NULL ;
  85. ofn.lpstrTitle = NULL ;
  86. ofn.Flags = 0 ; // Set in Open and Close functions
  87. ofn.nFileOffset = 0 ;
  88. ofn.nFileExtension = 0 ;
  89. ofn.lpstrDefExt = "" ;
  90. ofn.lCustData = 0L ;
  91. ofn.lpfnHook = NULL ;
  92. ofn.lpTemplateName = NULL ;
  93. }