home *** CD-ROM | disk | FTP | other *** search
/ BUG 4 / BUGCD1997_05.BIN / aplic / clip4win / clip4win.exe / C4W30E.HUF / SOURCE / WINEXEC.PRG < prev    next >
Text File  |  1995-09-03  |  4KB  |  128 lines

  1. ////////////////////////////
  2. //
  3. //    Clip-4-Win WinExec (Windows version of RUN) demo
  4. //
  5. //    Copyright (C) 1992-1995 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
  6. //    All Rights Reserved.
  7. //
  8. //    To build:    c4wbuild winexec
  9. //
  10. //    Thanks to Thomas Kaulen for the Extensions idea!
  11. //
  12. ////////////////////////////
  13.  
  14. #define    WIN_WANT_ALL
  15. #include "windows.ch"
  16. #define    NO_C4WCLASS
  17. #include "commands.ch"
  18. #include "dll.ch"
  19. #include "vo.ch"
  20. #include "msg.ch"
  21.  
  22. #define    CR    chr(13)
  23.  
  24. static    cUserApp
  25.  
  26.  
  27. function main_exec()
  28. local    oApp, oWnd
  29.  
  30. CREATE APPLICATION oApp  WINDOW oWND  TITLE "Clip-4-Win WinExec demo"    ;
  31.     ON INIT MenuSetup(oWnd)    
  32.  
  33. return nil
  34.  
  35.  
  36. static function DoRun(cProgram, cArgs, lWait)
  37. local    hInst, lFound := .T.
  38. local    cPrg := "", i
  39. local    aProgs := {{"CALENDAR.EXE", "cal"}, {"CARDFILE.EXE", "crd"},    ;
  40.                    {"NOTEPAD.EXE", "txt"}, {"TERMINAL.EXE", "trm"},    ;
  41.                    {"WRITE.EXE", "wri"}}
  42.  
  43. cArgs := iif(cArgs == nil, "", " " + cArgs)
  44. if (hInst := RunProg(cProgram + cArgs, lWait)) > 31  // Found ok
  45.     return .T.
  46. endif
  47.  
  48. // try WIN.INI's Extensions section
  49. if lFound := ((i := ascan(aProgs, {|a| a[1] == cProgram})) != 0)
  50.     cPrg := GetProfString("Extensions", aProgs[i, 2], "") + "\" + cProgram
  51.     if (i := OpenFile(cPrg, "", OF_EXIST)) == -1
  52.         lFound := .F.
  53.     endif
  54. endif
  55.  
  56. if lFound
  57.     RunProg(cPrg + cArgs, lWait)
  58. else
  59.     MessageBox( , cProgram + " not available!" + CR + CR +        ;
  60.                   "Check your installation!", MB_ICONSTOP)
  61. endif
  62.  
  63. return lFound
  64.  
  65.  
  66. _DLL function OpenFile(cFileName AS string, cStruct AS string, nMode AS UINT) ;
  67.     AS INT Pascal:Kernel.OpenFile
  68.  
  69. _DLL function GetModuleHandle(cName AS string)                ;
  70.     AS int Pascal:Kernel.GetModuleHandle
  71.  
  72.  
  73. function RunProg(cCmdLine, lWait)
  74. local    hInst, aMsg[MSG_LENGTH], cName
  75.  
  76. if (hInst := WinExec(cCmdLine)) > 31    // ok
  77.     cName = GetModuleFileName(hInst)
  78.     do while Default(@lWait, .F.) .and. GetModuleHandle(cName) != 0
  79.         if PeekMessage(aMsg)
  80.             GetMessage(aMsg)
  81.             TranslateMessage(aMsg)
  82.             DispatchMessage(aMsg)
  83.         endif
  84.     enddo
  85. endif
  86. return hInst
  87.  
  88.  
  89. static function MenuSetup(hWnd)
  90.  
  91. MENU IN hWnd
  92.     POPUP "&File"
  93.         MENUITEM "&Set your app"                    ;
  94.             ACTION cUserApp := GetOpenFileName( , "*.*", "Set App Name")
  95.         MENUITEM SEPARATOR
  96.         MENUITEM "E&xit"            ACTION PostQuitMessage()
  97.     ENDPOPUP
  98.     POPUP "&Run"
  99.         // Chars used: abcdfknoprstuw
  100.         MENUITEM "C&alendar"        ACTION DoRun("CALENDAR.EXE")
  101.         MENUITEM "Calc&ulator"      ACTION DoRun("CALC.EXE")
  102.         MENUITEM "&Cardfile"        ACTION DoRun("CARDFILE.EXE")
  103.         MENUITEM "Clip&board"       ACTION DoRun("CLIPBRD.EXE")
  104.         MENUITEM "Cloc&k"           ACTION DoRun("CLOCK.EXE")
  105.         MENUITEM "C&OMMAND.COM"     ACTION DoRun("COMMAND.COM")
  106.         MENUITEM "&DOS"             ACTION DoRun("DOSPRMPT.PIF")
  107.         MENUITEM "&File Manager"    ACTION DoRun("WINFILE.EXE")
  108.         MENUITEM "&Notepad Editor"  ACTION DoRun("NOTEPAD.EXE")
  109.         MENUITEM "&Print Manager"   ACTION DoRun("PRINTMAN.EXE")
  110.         MENUITEM "&Reg Info Editor" ACTION DoRun("REGEDIT.EXE")
  111.         MENUITEM "&Sys Config Editor" ACTION DoRun("SYSEDIT.EXE")
  112.         MENUITEM "&Terminal"        ACTION DoRun("TERMINAL.EXE")
  113.         MENUITEM "MS-&Write"        ACTION DoRun("WRITE.EXE")
  114.     ENDPOPUP
  115.     MENUITEM "&Your App!"                              ;
  116.         ACTION (Default(@cUserApp, GetOpenFileName( , "*.*", "Set App Name")),;
  117.                 iif(empty(cUserApp), , DoRun(cUserApp)))
  118.     MENUITEM "Your App and &Wait!"                          ;
  119.         ACTION (Default(@cUserApp, GetOpenFileName( , "*.*", "Set App Name")),;
  120.                 iif(empty(cUserApp), , DoRun(cUserApp, , .T.)))
  121.     POPUP "&Help"
  122.         MENUITEM "&Program Source" ACTION DoRun("NOTEPAD", "WINEXEC.PRG")
  123.         MENUITEM "&About"   ACTION MessageBox( , "WinExec Demo", "Clip-4-Win")
  124.     ENDPOPUP
  125. ENDMENU
  126.  
  127. return nil
  128.