home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / PASM.LZH / BMPOPEN.CPP < prev    next >
C/C++ Source or Header  |  1996-07-15  |  6KB  |  237 lines

  1. #include <owl\owlpch.h>
  2. #pragma hdrstop
  3.  
  4. #include <owl\opensave.h>
  5. #include <stdio.h>
  6. #include <io.h>
  7. #include "bmpopen.h"
  8. #include "files.h"
  9.  
  10. #define TMP1 "__gtmp1.txt"
  11. #define TMP2 "__gtmp2.txt"
  12. #ifndef MAX_PATH
  13.     #define MAX_PATH 256
  14. #endif
  15. #ifndef SW_SHOWDEFAULT
  16.     #define SW_SHOWDEFAULT 10
  17. #endif
  18.  
  19. #if 0
  20. #define IDD_INPUTDIALOG         32514
  21.  
  22.  
  23. int WinExecWait(TWindow *parent, char *lpszCmdLine, UINT fuCmdShow, char *waitfile = NULL);
  24.  
  25. class TDummyDialog: public TDialog {
  26. public:
  27.     int flag;
  28.     TWindow *parent;
  29.     char *cmdLine;
  30.     UINT cmdShow;
  31.     char *waitFile;
  32.     TDummyDialog(TWindow* _parent, char *_cmdLine, UINT _cmdShow, char *_waitfile = NULL);
  33.     virtual ~TDummyDialog(){}
  34.     virtual BOOL IdleAction(long idleCount);
  35. };
  36.  
  37. TDummyDialog::TDummyDialog(TWindow* _parent, char *_cmdLine, UINT _cmdShow, char *_waitFile) :
  38.     TDialog(parent, IDD_INPUTDIALOG)
  39. {
  40.     flag = FALSE;
  41.     parent = _parent;
  42.     cmdLine = _cmdLine;
  43.     cmdShow = _cmdShow;
  44.     waitFile = _waitFile;
  45. }
  46.  
  47. TDummyDialog::IdleAction(long idleCount)
  48. {
  49.     TDialog::IdleAction(idleCount);
  50.  
  51.     if (flag) {
  52.         return TRUE;
  53.     }
  54.  
  55.     flag = TRUE;
  56.     int ret = WinExecWait(parent, cmdLine, cmdShow, waitFile);
  57.  
  58.     CloseWindow(ret);
  59.     return TRUE;
  60. }
  61.  
  62. int WinExecWaitDialog(TWindow *parent, char *lpszCmdLine, UINT fuCmdShow, char *waitfile)
  63. {
  64.     return TDummyDialog(parent, lpszCmdLine, fuCmdShow, waitfile).Execute();
  65. }
  66. #endif
  67.  
  68. void PumpDrawMessage(TWindow *parent)
  69. {
  70.     MSG msg;
  71.     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
  72.         if (msg.message == WM_PAINT) {
  73.             TranslateMessage(&msg);
  74.             DispatchMessage(&msg);
  75.         } else if (msg.message == WM_LBUTTONDOWN) {
  76.             MessageBeep(-1);
  77.         }
  78.     }
  79.     parent->GetApplication()->PumpWaitingMessages();
  80. }
  81.  
  82. int WinExecWait(TWindow *parent, char *lpszCmdLine, UINT fuCmdShow, char *waitfile)
  83. {
  84. #ifdef __WIN32__
  85.     STARTUPINFO StartInfo;
  86.     PROCESS_INFORMATION ProcInfo;
  87.  
  88.     memset(&StartInfo, 0, sizeof(STARTUPINFO));
  89.     StartInfo.cb = sizeof(STARTUPINFO);
  90.     StartInfo.wShowWindow = (WORD)fuCmdShow;
  91.  
  92.     if (CreateProcess(NULL, lpszCmdLine, NULL, NULL,
  93.                       FALSE, 0, NULL, NULL, &StartInfo, &ProcInfo) == FALSE) {
  94.         return FALSE;
  95.     }
  96.     CloseHandle(ProcInfo.hThread);
  97.  
  98.  
  99.     DWORD code;
  100.     if (GetExitCodeProcess(ProcInfo.hProcess, &code) == FALSE && waitfile != NULL) {
  101.         while (access(waitfile, 0) != 0) {
  102. //            parent->GetApplication()->PumpWaitingMessages();
  103.             PumpDrawMessage(parent);
  104.             Sleep(50);
  105.         }
  106.         Sleep(50);
  107.         SetActiveWindow(parent->GetApplication()->GetMainWindow()->HWindow);
  108.     } else {
  109.         while (WaitForSingleObject(ProcInfo.hProcess, 50) == WAIT_TIMEOUT) {
  110. //            parent->GetApplication()->PumpWaitingMessages();
  111.             PumpDrawMessage(parent);
  112.         }
  113.         SetForegroundWindow(parent->GetApplication()->GetMainWindow()->HWindow);
  114.     }
  115.     CloseHandle(ProcInfo.hProcess);
  116.     return TRUE;
  117. #else
  118.     return FALSE;
  119. #endif
  120. }
  121.  
  122.  
  123. int FileOpenSaveDialogWithBMP(
  124.                 TWindow* parent, char *filename,
  125.                 DWORD flags, const char* /*filter*/, char* /*customFilter*/,
  126.                 char* initialDir, char* defExt)
  127. {
  128.     int ret;
  129. /*    char tmppath[MAX_PATH];*/
  130.     char tmp1[MAX_PATH], tmp2[MAX_PATH];
  131.     char gme[MAX_PATH];
  132. /*
  133.     GetTempPath(MAX_PATH, temppath);
  134.     GetTempFileName(tmppath, "_g", 0, tmp1);
  135.     GetTempFileName(tmppath, "_g", 0, tmp2);
  136. */
  137.     sprintf(tmp1, "%s%s", tempdir.c_str(), TMP1);
  138.     sprintf(tmp2, "%s%s", tempdir.c_str(), TMP2);
  139.     if (defExt == NULL
  140.      || (strcmpi(defExt, "frm") != 0 && strcmpi(defExt, "fsc") != 0)
  141.      || ((flags & (OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT)) == 0)) {
  142.         return -1;
  143.     }
  144.     unlink(tmp1);
  145.     unlink(tmp2);
  146.     FILE *fp;
  147.     if ((fp = fopen(tmp1, "w")) == NULL) {
  148.         return -1;
  149.     }
  150.     fprintf(fp, "%s\n", initialDir);
  151.     fprintf(fp, ".%s\n", defExt);
  152.     fprintf(fp, "%s\n", parent->GetApplication()->GetName());
  153.     if (strcmpi(defExt, "frm") == 0) {
  154.         if (flags & OFN_FILEMUSTEXIST) {
  155.             fprintf(fp, "読み込むモーションファイルを指定してください\n");
  156.             fprintf(fp, "open\n");
  157.         } else {
  158.             fprintf(fp, "保存するモーションファイルの名前を入力してください\n");
  159.             fprintf(fp, "save\n");
  160.         }
  161.     } else {
  162.         if (flags & OFN_FILEMUSTEXIST) {
  163.             fprintf(fp, "読み込むメカのデザインファイルを指定してください\n");
  164.             fprintf(fp, "open\n");
  165.         } else {
  166.             fprintf(fp, "保存するメカデザインファイルの名前を入力してください\n");
  167.             fprintf(fp, "save\n");
  168.         }
  169.     }
  170.     fprintf(fp, "%s\n", tmp2);
  171.     fclose(fp);
  172.     sprintf(gme, "%sGME.EXE -vf %s", pathdir.c_str(), tmp1);
  173.  
  174.     if (WinExecWait(parent, gme, SW_SHOWDEFAULT, tmp2) == FALSE) {
  175.         unlink(tmp1);
  176.         unlink(tmp2);
  177.         return -1;
  178.     }
  179.     if ((fp = fopen(tmp2, "r")) == NULL) {
  180.         return -1;
  181.     }
  182.     if (fgets(tmp1, MAX_PATH, fp) == NULL) {
  183.         ret = -1;
  184.     } else {
  185.         if (tmp1[0] == '\n' || tmp1[0] == '\0') {
  186.             ret = IDCANCEL;
  187.         } else {
  188.             strcpy(filename, tmp1);
  189.             char *p;
  190.             if ((p = strchr(filename, '\n')) != NULL) {
  191.                 *p = '\0';
  192.             }
  193.             ret = IDOK;
  194.         }
  195.     }
  196.     fclose(fp);
  197.     unlink(tmp1);
  198.     unlink(tmp2);
  199.     return ret;
  200. }
  201.  
  202. int FileOpenDialogWithBMP(
  203.                 TWindow* parent, char *filename,
  204.                 DWORD flags, const char* filter, char* customFilter,
  205.                 char* initialDir, char* defExt)
  206. {
  207.     int ret;
  208.  
  209.     ret = FileOpenSaveDialogWithBMP(parent, filename, flags, filter, customFilter, initialDir, defExt);
  210.     if (ret != IDOK && ret != IDCANCEL) {
  211.         TOpenSaveDialog::TData FileData(flags, filter, customFilter, initialDir, defExt);
  212.         ret = TFileOpenDialog(parent, FileData).Execute();
  213.         if (ret == IDOK) {
  214.             strcpy(filename, FileData.FileName);
  215.         }
  216.     }
  217.     return ret;
  218. }
  219.  
  220. int FileSaveDialogWithBMP(
  221.                 TWindow* parent, char *filename,
  222.                 DWORD flags, const char* filter, char* customFilter,
  223.                 char* initialDir, char* defExt)
  224. {
  225.     int ret;
  226.     ret = FileOpenSaveDialogWithBMP(parent, filename, flags, filter, customFilter, initialDir, defExt);
  227.     if (ret != IDOK && ret != IDCANCEL) {
  228.         TOpenSaveDialog::TData FileData(flags, filter, customFilter, initialDir, defExt);
  229.         ret = TFileSaveDialog(parent, FileData).Execute();
  230.         if (ret == IDOK) {
  231.             strcpy(filename, FileData.FileName);
  232.         }
  233.     }
  234.     return ret;
  235. }
  236.  
  237.