FILES.C

Go to the documentation of this file.
00001 /* file FILES.C */
00002 
00003 // Utilitiy functions to provide file open/save dialogs. Loads strings
00004 // from resources files to allow for internationalisation
00005 
00006 #define MODULE_FILES 1
00007 
00008 #include "animate.h"
00009 #include "spin_dll.h"
00010 
00011 int SelectFileName(int save, char *szfile, char *szdir,
00012                    char *szTitle, char *szfilter, HWND parent){
00013  int i;
00014  OPENFILENAME ofn;
00015  char szFilter[256],szdummy[MAX_FILE];
00016  szdummy[0]='\0';
00017  strcpy(szFilter,szfilter);
00018  i=0; while(szFilter[i] != '\0'){
00019    if(szFilter[i] == '|')szFilter[i]='\0'; i++;
00020  }
00021  memset(&ofn,0,sizeof(OPENFILENAME));
00022  ofn.lStructSize=sizeof(OPENFILENAME);
00023  ofn.hwndOwner=parent;
00024  ofn.lpstrFilter=szFilter;
00025  ofn.nFilterIndex=1;
00026  ofn.lpstrFile=szfile;              /* will contain file + path */
00027  ofn.nMaxFile=MAX_FILE;
00028  ofn.lpstrFileTitle=szdummy;         /* file name only */
00029  ofn.nMaxFileTitle=MAX_FILE;
00030  ofn.lpstrInitialDir=szdir;
00031  ofn.lpstrTitle=szTitle;
00032  if(save){
00033   ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST;
00034    i=(int)(GetSaveFileName(&ofn));
00035  }
00036  else{
00037   ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST;
00038    i=(int)(GetOpenFileName(&ofn));
00039  }
00040  if(i){
00041    strcpy(szdummy,szfile);
00042    *AnsiPrev(szdummy,FileInPath(szdummy)) = '\0';
00043    strcpy(szdir,szdummy);
00044  }
00045    {MSG msg;  /* allow WM_COMMAND message to be processed */
00046     while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
00047       TranslateMessage(&msg);
00048       DispatchMessage(&msg);
00049     }
00050    }
00051 
00052  return i;
00053 }
00054 
00055 int SelectDirectoryName(char *szfile, char *szdir,
00056                    char *szTitle, char *szfilter, HWND parent){
00057  int i;
00058  OPENFILENAME ofn;
00059  char szFilter[80],szdummy[MAX_FILE];
00060  szdummy[0]='\0';
00061  strcpy(szFilter,szfilter);
00062  i=0; while(szFilter[i] != '\0'){
00063    if(szFilter[i] == '|')szFilter[i]='\0'; i++;
00064  }
00065  memset(&ofn,0,sizeof(OPENFILENAME));
00066  ofn.lStructSize=sizeof(OPENFILENAME);
00067  ofn.hwndOwner=parent;
00068  ofn.lpstrFilter=szFilter;
00069  ofn.nFilterIndex=1;
00070  ofn.lpstrFile=szfile;              /* will contain file + path */
00071  ofn.nMaxFile=MAX_FILE;
00072  ofn.lpstrFileTitle=szdummy;         /* file name only */
00073  ofn.nMaxFileTitle=MAX_FILE;
00074  ofn.lpstrInitialDir=szdir;
00075  ofn.lpstrTitle=szTitle;
00076  ofn.hInstance=ghinst_main;
00077  ofn.lpfnHook=NULL;
00078  ofn.lpTemplateName="DIRECTORYOPEN";
00079  ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|
00080             OFN_ENABLETEMPLATE|OFN_NONETWORKBUTTON|
00081             OFN_NOTESTFILECREATE;  /* for PAR problem */
00082  i=(int)(GetSaveFileName(&ofn));
00083  if(i){
00084    strcpy(szdummy,szfile);
00085    *AnsiPrev(szdummy,FileInPath(szdummy)) = '\0';
00086    strcpy(szdir,szdummy);
00087  }
00088  return i;
00089 }
00090 
00091 int SelectSfxFileName(int save, char *szfile, char *szdir, long ID,
00092                       char *szfilter, HWND parent){
00093  char szTitle[256];
00094  LoadString(ghinst_main,ID,szTitle,255);
00095  return SelectFileName(save,szfile,szdir,szTitle,szfilter,parent);
00096 }
00097 
00098 static int MorphSetupValue;
00099 
00100 static unsigned CALLBACK MorphFileOpenHookProc(HWND hwnd,UINT msg,
00101                               WPARAM wparam,LPARAM lparam){
00102  switch( msg ) {
00103    case WM_INITDIALOG:
00104      MorphSetupValue=1;
00105      SendDlgItemMessage(hwnd,100,BM_SETCHECK,1,0);
00106      return FALSE;
00107    case WM_COMMAND:
00108     switch(LOWORD(wparam)){
00109       case 100: MorphSetupValue=1; break;
00110       case 101: MorphSetupValue=2; break;
00111       case 102: MorphSetupValue=3; break;
00112       default: break;
00113     }
00114     break;
00115    case WM_NOTIFY:{
00116        LPOFNOTIFY lp=(LPOFNOTIFY)lparam;
00117        if(lp->hdr.code == CDN_FILEOK){
00118 //       LPNMHDR lp=(LPNMHDR)lparam;
00119 //       if(lp->code == CDN_FILEOK){
00120          ;
00121        }
00122      }
00123      break;
00124    default: break;
00125  }
00126  return FALSE;
00127 }
00128 
00129 int SelectMorphFileName(char *szfile, char *szdir,
00130                    char *szTitle, char *szfilter, HWND parent){
00131  int i;
00132  DWORD version;
00133  version=GetVersion();
00134 // if(((version & 0x80000000) == 0x80000000) &&
00135 //     (LOBYTE(LOWORD(version)) >= 4)){ /* windows 95 */
00136 //   i=SelectFileName(0,szfile,szdir,szTitle,szfilter,parent);
00137 //   if(i > 0)return 4;
00138 //   else     return i;
00139 // }
00140  {
00141  OPENFILENAME ofn;
00142  char szFilter[80],szdummy[MAX_FILE];
00143  szdummy[0]='\0';
00144  strcpy(szFilter,szfilter);
00145  i=0; while(szFilter[i] != '\0'){
00146    if(szFilter[i] == '|')szFilter[i]='\0'; i++;
00147  }
00148  memset(&ofn,0,sizeof(OPENFILENAME));
00149  ofn.lStructSize=sizeof(OPENFILENAME);
00150  ofn.hwndOwner=parent;
00151  ofn.lpstrFilter=szFilter;
00152  ofn.nFilterIndex=1;
00153  ofn.lpstrFile=szfile;              /* will contain file + path */
00154  ofn.nMaxFile=MAX_FILE;
00155  ofn.lpstrFileTitle=szdummy;         /* file name only */
00156  ofn.nMaxFileTitle=MAX_FILE;
00157  ofn.lpstrInitialDir=szdir;
00158  ofn.lpstrTitle=szTitle;
00159  ofn.hInstance=ghinst_main;
00160  ofn.lpfnHook=MorphFileOpenHookProc;
00161  ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|
00162            OFN_ENABLEHOOK|OFN_ENABLETEMPLATE|OFN_NONETWORKBUTTON;
00163  if(LOBYTE(LOWORD(version)) >= 4){
00164    ofn.lpTemplateName="FILEOPEN95";
00165    ofn.Flags |= OFN_EXPLORER;
00166  }
00167  else{
00168    ofn.lpTemplateName="FILEOPEN";
00169  }
00170  i=(int)(GetOpenFileName(&ofn));
00171  if(i){
00172    strcpy(szdummy,szfile);
00173    *AnsiPrev(szdummy,FileInPath(szdummy)) = '\0';
00174    strcpy(szdir,szdummy);
00175    i=MorphSetupValue;
00176  }
00177  return i;
00178  }
00179 }
00180 
00181 static int RobotSetupValue=1;
00182 
00183 static unsigned CALLBACK RobotFileOpenHookProc(HWND hwnd,UINT msg,
00184                               WPARAM wparam,LPARAM lparam){
00185  BOOL err;
00186  int i;
00187  switch( msg ) {
00188    case WM_INITDIALOG:
00189      RobotSetupValue=1;
00190      SetDlgItemInt(hwnd,100,1,FALSE);
00191      SendDlgItemMessage(hwnd,101,SPNM_SETRANGE,0,
00192                         MAKELPARAM(1,10000));
00193      SendDlgItemMessage(hwnd,101,SPNM_SETCRNTVALUE,
00194                         (WPARAM)1,0);
00195      SendDlgItemMessage(hwnd,101,SPNM_SETEDITCTRL,0,
00196                         (LPARAM)GetDlgItem(hwnd,100));
00197   SendDlgItemMessage(hwnd,100,BM_SETCHECK,1,0);
00198      return FALSE;
00199    case WM_COMMAND:
00200     switch(LOWORD(wparam)){
00201       default: break;
00202     }
00203     break;
00204    case WM_NOTIFY:{
00205        LPOFNOTIFY lp=(LPOFNOTIFY)lparam;
00206        if(lp->hdr.code == CDN_FILEOK){
00207          i=GetDlgItemInt(hwnd,100,&err,FALSE);
00208          if(err && i > 0)RobotSetupValue=i;
00209        }
00210      }
00211      break;
00212    default: break;
00213  }
00214  return FALSE;
00215 }
00216 
00217 int SelectRobotFileName(char *szfileI, char *szdirI,
00218                    long ID, char *szfilter, HWND parent){
00219  int i;
00220  DWORD version;
00221  char szTitle[256];
00222  version=GetVersion();
00223  LoadString(ghinst_main,ID,szTitle,255);
00224  {
00225   OPENFILENAME ofn;
00226   char szFilter[80],szdummy[MAX_FILE],szfile[MAX_FILE],szdir[MAX_FILE];
00227   strcpy(szfile,szfileI); strcpy(szdir,szdirI);
00228   szdummy[0]='\0';
00229   strcpy(szFilter,szfilter);
00230   i=0; while(szFilter[i] != '\0'){
00231     if(szFilter[i] == '|')szFilter[i]='\0'; i++;
00232   }
00233   memset(&ofn,0,sizeof(OPENFILENAME));
00234   ofn.lStructSize=sizeof(OPENFILENAME);
00235   ofn.hwndOwner=parent;
00236   ofn.lpstrFilter=szFilter;
00237   ofn.nFilterIndex=1;
00238   ofn.lpstrFile=szfile;              /* will contain file + path */
00239   ofn.nMaxFile=MAX_FILE;
00240   ofn.lpstrFileTitle=szdummy;         /* file name only */
00241   ofn.nMaxFileTitle=MAX_FILE;
00242   ofn.lpstrInitialDir=szdir;
00243   ofn.lpstrTitle=szTitle;
00244   ofn.hInstance=ghinst_main;
00245   ofn.lpfnHook=RobotFileOpenHookProc;
00246   ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|
00247             OFN_ENABLEHOOK|OFN_ENABLETEMPLATE|OFN_NONETWORKBUTTON;
00248   if(LOBYTE(LOWORD(version)) >= 4){
00249     ofn.lpTemplateName="FILEOPENROBOT";
00250     ofn.Flags |= OFN_EXPLORER;
00251   }
00252   else{
00253     ofn.lpTemplateName="FILEOPEN";
00254   }
00255   i=(int)(GetOpenFileName(&ofn));
00256   if(i == 0)return 0;
00257 
00258   strlwr(szfile);
00259   strcpy(szdummy,szfile);
00260   *AnsiPrev(szdummy,FileInPath(szdummy)) = '\0';
00261   strcpy(szdir,szdummy);
00262   if(strstr(szfile,".rsq") == NULL){
00263     strcpy(szfileI,szfile);
00264     strcpy(szdirI,szdir);
00265     i=RobotSetupValue;
00266   }
00267   else{
00268     strcpy(gszRSQfile,szfile);
00269     strcpy(gszRSQdir,szdir);
00270     i = -RobotSetupValue;
00271   }
00272   return i;
00273  }
00274 }

Generated on Sun Apr 27 14:20:08 2014 for OpenFX by  doxygen 1.5.6