home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / windxy.zip / FLIST.C < prev    next >
Text File  |  1990-11-25  |  9KB  |  286 lines

  1. #include <windows.h>
  2. #include "windxf.h"
  3.  
  4. HANDLE GBL_hInst;
  5. extern char GBL_mfname[256];
  6.  
  7. void SeparateFile(HWND, LPSTR, LPSTR, LPSTR);
  8. void UpdateListBox(HWND);
  9. void AddExt(PSTR, PSTR);
  10. void ChangeDefExt(PSTR, PSTR);
  11.  
  12. char  GBL_dbpath[256];
  13. char  GBL_mfpath[256];
  14.  
  15. char FileName[128];
  16. char PathName[128];
  17. char OpenName[128];
  18. char DefPath[128]="";
  19. char DefSpec[13] = "*.dxf";
  20. char DefExt[] = ".dxf";
  21. char str[255];
  22.  
  23. BOOL FAR PASCAL
  24. FILEDIALOGPROC(hDlg, message, wParam, lParam)
  25. HWND hDlg;                                /* window handle of the dialog box */
  26. unsigned message;                         /* type of message                 */
  27. WORD wParam;                              /* message-specific information    */
  28. LONG lParam;
  29. {
  30.    HWND ChWnd;
  31.    char fname[256];
  32.  
  33.    switch (message) {
  34.     case WM_INITDIALOG:           /* message: initialize dialog box */
  35.        DlgDirList(hDlg, "*.dxf", IDC_LISTBOX, IDC_PATH, 0x4010);
  36.        SendMessage(ChWnd,LB_DIR,0x37,(LONG) "*.dxf");
  37.        SetDlgItemText(hDlg, IDC_FILENAME, "*.dxf");
  38.        SetFocus(GetDlgItem(hDlg, IDC_FILENAME));
  39.         return (TRUE);
  40.  
  41.     case WM_COMMAND:              /* message: received a command */
  42.             switch (wParam) 
  43.             {
  44.                 case IDC_LISTBOX:
  45.                     switch (HIWORD(lParam)) {
  46.  
  47.                         case LBN_SELCHANGE:
  48.                             /* If item is a directory name, append "*.*" */
  49.                             if (DlgDirSelect(hDlg, str, IDC_LISTBOX)) 
  50.                                 lstrcat(str, DefSpec);
  51.  
  52.                             SetDlgItemText(hDlg, IDC_FILENAME, str);
  53.                             SendDlgItemMessage(hDlg,
  54.                                 IDC_FILENAME,
  55.                                 EM_SETSEL,
  56.                                 NULL,
  57.                                 MAKELONG(0, 0x7fff));
  58.                             break;
  59.  
  60.                        case LBN_DBLCLK:
  61.                              goto openfile; 
  62.  
  63.                     } /* Switch hiword */
  64.                     return (TRUE);
  65.                     break;
  66.  
  67.                 case IDM_FOPEN:
  68. openfile:
  69.                     GetDlgItemText(hDlg, IDC_FILENAME, OpenName, 128);
  70.                     if (strchr(OpenName, '*') || strchr(OpenName, '?')) {
  71.                         SeparateFile(hDlg, (LPSTR) str, (LPSTR) DefSpec,
  72.                             (LPSTR) OpenName);
  73.                         if (str[0])
  74.                             lstrcpy(DefPath, str);
  75.                         ChangeDefExt(DefExt, DefSpec);
  76.                         UpdateListBox(hDlg);
  77.                         return (TRUE);
  78.                     }
  79.  
  80.                     if (!OpenName[0]) {
  81.                         MessageBox(hDlg, "No filename specified.",
  82.                             NULL, MB_OK | MB_ICONHAND);
  83.                         return (TRUE);
  84.                     }
  85.  
  86.                     AddExt(OpenName, DefExt);
  87.  
  88.                     GetDlgItemText(hDlg, IDC_PATH, GBL_dbpath, 256);
  89.                     GetDlgItemText(hDlg, IDC_FILENAME, fname, 256);
  90.                     lstrcat(GBL_dbpath,"/");
  91.                     lstrcat(GBL_dbpath,fname);
  92.  
  93.                     EndDialog(hDlg, NULL);
  94.                     return (TRUE);
  95.                     break;
  96.  
  97.                 case IDM_FCANCEL:
  98.                     EndDialog(hDlg, NULL);
  99.                     return (FALSE);
  100.                     break;
  101.              } /* end wparam */
  102.              break;
  103.  
  104.         } /* Switch message */
  105.     return (FALSE);                  /* Didn't process a message    */
  106. }
  107.  
  108. void SeparateFile(hDlg, lpDestPath, lpDestFileName, lpSrcFileName)
  109. HWND hDlg;
  110. LPSTR lpDestPath, lpDestFileName, lpSrcFileName;
  111. {
  112.     LPSTR lpTmp;
  113.     char  cTmp;
  114.  
  115.     lpTmp = lpSrcFileName + (long) strlen(lpSrcFileName);
  116.     while (*lpTmp != ':' && *lpTmp != '\\' && lpTmp > lpSrcFileName)
  117.         lpTmp = AnsiPrev(lpSrcFileName, lpTmp);
  118.     if (*lpTmp != ':' && *lpTmp != '\\') {
  119.         lstrcpy(lpDestFileName, lpSrcFileName);
  120.         lpDestPath[0] = 0;
  121.         return;
  122.     }
  123.     lstrcpy(lpDestFileName, lpTmp + 1);
  124.     cTmp = *(lpTmp + 1);
  125.     lstrcpy(lpDestPath, lpSrcFileName);
  126.      *(lpTmp + 1) = cTmp;
  127.     lpDestPath[(lpTmp - lpSrcFileName) + 1] = 0;
  128. }
  129. void ChangeDefExt(Ext, Name)
  130. PSTR Ext, Name;
  131. {
  132.     PSTR pTptr;
  133.  
  134.     pTptr = Name;
  135.     while (*pTptr && *pTptr != '.')
  136.         pTptr++;
  137.     if (*pTptr)
  138.         if (!strchr(pTptr, '*') && !strchr(pTptr, '?'))
  139.             lstrcpy(Ext, pTptr);
  140. }
  141. void UpdateListBox(hDlg)
  142. HWND hDlg;
  143. {
  144.     lstrcpy(str, DefPath);
  145.     lstrcat(str, DefSpec);
  146.     DlgDirList(hDlg, str, IDC_LISTBOX, IDC_PATH, 0x4010);
  147.     SetDlgItemText(hDlg, IDC_FILENAME, DefSpec);
  148. }
  149. void AddExt(Name, Ext)
  150. PSTR Name, Ext;
  151. {
  152.     PSTR pTptr;
  153.  
  154.     pTptr = Name;
  155.     while (*pTptr && *pTptr != '.')
  156.         pTptr++;
  157.     if (*pTptr != '.')
  158.         lstrcat(Name, Ext);
  159. }
  160.  
  161. void GetDbPath( dbpath )
  162. char * dbpath;
  163. {
  164. lstrcpy(dbpath, GBL_dbpath);
  165. }
  166.  
  167. BOOL FAR PASCAL
  168. MFNAMEPROC(hDlg, message, wParam, lParam)
  169. HWND hDlg;                                /* window handle of the dialog box */
  170. unsigned message;                         /* type of message                 */
  171. WORD wParam;                              /* message-specific information    */
  172. LONG lParam;
  173. {
  174.  
  175.    switch (message) {
  176.     case WM_INITDIALOG:           /* message: initialize dialog box */
  177.        SetDlgItemText(hDlg, IDM_MFNAME, GBL_mfname); 
  178.         return (TRUE);
  179.  
  180.     case WM_COMMAND:              /* message: received a command */
  181.             switch (wParam) 
  182.             {
  183.                 case IDM_WRITEMF:
  184.                     GetDlgItemText(hDlg, IDM_MFNAME, (LPSTR)GBL_mfname, 256);
  185.                     EndDialog(hDlg, TRUE);
  186.                     return (TRUE);
  187.                     break;
  188.  
  189.                 case IDM_CANCELMF:
  190.                     EndDialog(hDlg, NULL);
  191.                     return (FALSE);
  192.                     break;
  193.  
  194.              } /* end wparam */
  195.              break;
  196.         } /* Switch message */
  197.     return (FALSE);                  /* Didn't process a message    */
  198. }
  199.  
  200.  
  201. BOOL FAR PASCAL
  202. MFPROC(hDlg, message, wParam, lParam)
  203. HWND hDlg;                                /* window handle of the dialog box */
  204. unsigned message;                         /* type of message                 */
  205. WORD wParam;                              /* message-specific information    */
  206. LONG lParam;
  207. {
  208.    HWND ChWnd;
  209.    char fname[256];
  210.  
  211.    switch (message) {
  212.     case WM_INITDIALOG:           /* message: initialize dialog box */
  213.        DlgDirList(hDlg, "*.wmf", IDC_LISTBOX, IDC_PATH, 0x4010);
  214.        SendMessage(ChWnd,LB_DIR,0x37,(LONG) "*.wmf");
  215.        SetDlgItemText(hDlg, IDC_FILENAME, "*.wmf");
  216.        SetFocus(GetDlgItem(hDlg, IDC_FILENAME));
  217.         return (TRUE);
  218.  
  219.     case WM_COMMAND:              /* message: received a command */
  220.             switch (wParam) 
  221.             {
  222.                 case IDC_LISTBOX:
  223.                     switch (HIWORD(lParam)) {
  224.  
  225.                         case LBN_SELCHANGE:
  226.                             /* If item is a directory name, append "*.*" */
  227.                             if (DlgDirSelect(hDlg, str, IDC_LISTBOX)) 
  228.                                 lstrcat(str, DefSpec);
  229.  
  230.                             SetDlgItemText(hDlg, IDC_FILENAME, str);
  231.                             SendDlgItemMessage(hDlg,
  232.                                 IDC_FILENAME,
  233.                                 EM_SETSEL,
  234.                                 NULL,
  235.                                 MAKELONG(0, 0x7fff));
  236.                             break;
  237.  
  238.                        case LBN_DBLCLK:
  239.                              goto openfile; 
  240.  
  241.                     } /* Switch hiword */
  242.                     return (TRUE);
  243.                     break;
  244.  
  245.                 case IDM_FOPEN:
  246. openfile:
  247.                     GetDlgItemText(hDlg, IDC_FILENAME, OpenName, 128);
  248.                     if (strchr(OpenName, '*') || strchr(OpenName, '?')) {
  249.                         SeparateFile(hDlg, (LPSTR) str, (LPSTR) DefSpec,
  250.                             (LPSTR) OpenName);
  251.                         if (str[0])
  252.                             lstrcpy(DefPath, str);
  253.                         ChangeDefExt(DefExt, DefSpec);
  254.                         UpdateListBox(hDlg);
  255.                         return (TRUE);
  256.                     }
  257.  
  258.                     if (!OpenName[0]) {
  259.                         MessageBox(hDlg, "No filename specified.",
  260.                             NULL, MB_OK | MB_ICONHAND);
  261.                         return (TRUE);
  262.                     }
  263.  
  264.                     AddExt(OpenName, DefExt);
  265.  
  266.                     GetDlgItemText(hDlg, IDC_PATH, GBL_mfpath, 256);
  267.                     GetDlgItemText(hDlg, IDC_FILENAME, fname, 256);
  268.                     lstrcat(GBL_mfpath,"/");
  269.                     lstrcat(GBL_mfpath,fname);
  270.  
  271.                     EndDialog(hDlg, NULL);
  272.                     return (TRUE);
  273.                     break;
  274.  
  275.                 case IDM_FCANCEL:
  276.                     EndDialog(hDlg, NULL);
  277.                     return (FALSE);
  278.                     break;
  279.              } /* end wparam */
  280.              break;
  281.  
  282.         } /* Switch message */
  283.     return (FALSE);                  /* Didn't process a message    */
  284. }
  285.  
  286.