home *** CD-ROM | disk | FTP | other *** search
/ VRML Tools for 3D Cyberspace / VRML_Tools_For_3D_Cyberspace.iso / virtus / vutility.in_ / vutility.bin
Text File  |  1996-07-01  |  9KB  |  313 lines

  1. '----------------------------------------------------------------
  2. '- more specialized little functions to make our lives easier.
  3. '- John Alspaugh 13OCT94
  4. '- Copyright 1993-1994 Virtus Corporation.  All Rights Reserved.
  5. '-
  6. '- Note that this must be included after MSDETECT.INC and SETUPAPI.INC
  7. '-
  8. '----------------------------------------------------------------
  9. 'simple utility include.
  10.  
  11. '' dialog number
  12. CONST LOOKFORFILE_DLG    = 6352
  13. CONST NO_WIN_3_1_DLG     = 410
  14. CONST WRONG_CPU_DLG     = 411
  15.  
  16.  
  17. DECLARE SUB VMessageBox(msg$, title$)
  18. DECLARE SUB VDbgMsgBox(msg$, title$)
  19. DECLARE FUNCTION VMakePath (szDir$, szFile$) AS STRING
  20. DECLARE SUB VMaximizeFrame
  21. DECLARE FUNCTION VFindExeFromRegistration(pFExten$, pDest$) AS INTEGER
  22. DECLARE FUNCTION VFindExe(pFName$, pFExten$, pDest$) AS INTEGER
  23. DECLARE FUNCTION VIsSystemAdequate AS INTEGER
  24.  
  25.  
  26.  
  27. '----------------------------------------------------------------
  28. '- Purpose:
  29. '-         to have cheap quicky way to message boxes
  30. '- Arguments:
  31. '-         the text message and the dialog title
  32. '- Returns:
  33. '-         nothing
  34. '----------------------------------------------------------------
  35. SUB VMessageBox(msg$, title$) STATIC
  36.  
  37.     i% = DoMsgBox(msg$, title$, MB_ICONEXCLAMATION+MB_OK)
  38.  
  39. END SUB
  40.  
  41.  
  42. '----------------------------------------------------------------
  43. '- Purpose:
  44. '-         to do quicky debug messages
  45. '- Arguments:
  46. '-         the text message and the dialog title
  47. '- Returns:
  48. '-         nothing
  49. '----------------------------------------------------------------
  50. SUB VDbgMsgBox(msg$, title$) STATIC
  51.  
  52. '$IFDEF DEBUG
  53.     VMessageBox msg$, title$
  54. '$ENDIF 'DEBUG
  55.  
  56. END SUB
  57.  
  58.  
  59. '----------------------------------------------------------------
  60. '- Purpose:
  61. '-     Appends a file name to the end of a directory path,
  62. '-     inserting a backslash character if needed.
  63. '- Arguments:
  64. '-     szDir$  - full directory path (with optional ending "\")
  65. '-     szFile$ - filename to append to directory
  66. '- Returns:
  67. '-     Resulting fully qualified path name.
  68. '----------------------------------------------------------------
  69. FUNCTION VMakePath (szDir$, szFile$) STATIC  AS STRING
  70.     IF szDir$ = "" THEN
  71.         VMakePath = szFile$
  72.     ELSEIF szFile$ = "" THEN
  73.         VMakePath = szDir$
  74.     ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
  75.         VMakePath = szDir$ + szFile$
  76.     ELSE
  77.         VMakePath = szDir$ + "\" + szFile$
  78.     END IF
  79. END FUNCTION
  80.  
  81.  
  82. '----------------------------------------------------------------
  83. '----------------------------------------------------------------
  84. '' From the MS Knowledge Base CD #2:
  85. ''following were taken from windows.h. &H means they're hex
  86. CONST WS_VISIBLE=&H10000000
  87. CONST WS_BORDER =&H00800000
  88. CONST WS_CLIPCHILDREN =&H02000000
  89. CONST GWL_STYLE =-16
  90. CONST SW_SHOWMAXIMIZED=3
  91.  
  92. DECLARE FUNCTION ShowWindow  LIB "user.exe" (hWnd%,iShow%) AS INTEGER
  93. DECLARE FUNCTION SetWindowLong LIB "user.exe" (hWnd%, offset%, style&) AS LONG
  94.  
  95.  
  96. SUB VMaximizeFrame STATIC
  97.     hWnd%=HwndFrame()
  98.     i&=SetWindowLong(hWnd%,GWL_STYLE,WS_VISIBLE+WS_BORDER+WS_CLIPCHILDREN)
  99.     j%=ShowWindow(hWnd%,SW_SHOWMAXIMIZED)
  100. END SUB
  101.  
  102. '----------------------------------------------------------------
  103. '----------------------------------------------------------------
  104. FUNCTION VFindExeFromRegistration (pFExten$, pDest$) STATIC AS INTEGER
  105.     '' set the local vars.
  106.     lDestDir$ = ""
  107.     lDrive$ = ""
  108.     CursorSave% = ShowWaitCursor()
  109.  
  110.  
  111.    '' step one:  try to find the file in the win.ini extensions section.
  112.     IF pFExten$ <> "" THEN
  113.         lDrive$ = GetIniKeyString("WIN.INI", "Extensions", pFExten$)
  114.  
  115.         VDbgMsgBox "Extension entry from Win.ini: " + lDrive$, "VRDEBUG"
  116.  
  117.         IF lDrive$ <> "" THEN  ''there is a key
  118.             ''remove the tail (^.VVR)
  119.             StrLen% = LEN(lDrive$)
  120.             WHILE (MID$(lDrive$, StrLen%, 1) <> "^") AND (StrLen% > 1)
  121.                 StrLen% = StrLen% - 1
  122.             WEND
  123.             StrLen% = StrLen% - 1
  124.  
  125.             TNAME$ = MID$(lDrive$, 1, StrLen%)
  126.             lDrive$ = RTRIM$(TNAME$)
  127.  
  128.             VDbgMsgBox "After stripping the file type:  " + lDrive$, "VRDEBUG"
  129.  
  130.             StrLen% = DoesFileExist(lDrive$, femExists) '' file still there?
  131.  
  132.             IF StrLen% = 0 THEN
  133.                 '' we didn't find it.  But it could be in the path, in which case
  134.                 '' the entry might just be the file name.  We should check for this
  135.                 '' case (however, we must extract the exe name from any path first,
  136.                 '' since otherwise FindTargetOnEnvVar will fail nastily.
  137.  
  138.                 '' Extract file name from directory name.  Find if this is a path
  139.                 PathLen% = LEN(lDrive$)
  140.                 WHILE (PathLen% > 0) AND(MID$(lDrive$, PathLen%, 1) <> "\")
  141.                     PathLen% = PathLen% - 1
  142.                 WEND
  143.  
  144.                 '' If Pathlen% = 0, lDrive$ is a filename  and we should search the
  145.                 '' path environment variable.  If PathLen% > 0, lDrive$ is an invalid
  146.                 '' path and we should punt.
  147.                 IF PathLen% = 0 THEN
  148.                     tempStr$ = FindTargetOnEnvVar(lDrive$, "PATH")
  149.                     IF tempStr$ <> "" THEN
  150.                         StrLen% = DoesFileExist(tempStr$, femExists)
  151.                         IF StrLen% = 1 THEN '' file exists
  152.                             lDrive$ = tempStr$
  153.                             VDbgMsgBox "Found EXE through PATH$ at:  " + lDrive$, "VRDEBUG"
  154.                         END IF
  155.                     END IF
  156.                 END IF
  157.             END IF
  158.  
  159.             IF StrLen% = 1 THEN   '' file still there!
  160.                 StrLen% = LEN(lDrive$)
  161.  
  162.                 '' Extract directory name
  163.                 WHILE (MID$(lDrive$, StrLen%, 1) <> "\") AND (StrLen% > 1)
  164.                     StrLen% = StrLen% - 1
  165.                 WEND
  166.                 StrLen% = StrLen% - 1
  167.  
  168.                 lDestDir$ = MID$(lDrive$, 1, StrLen%)
  169.  
  170.  
  171.                 VDbgMsgBox "Dir name:  " + lDestDir$, "lDestDir"
  172.  
  173.  
  174.                 '' Directory okay?
  175.                 i% = DoesDirExist(lDestDir$)
  176.                 IF i% = 0 THEN
  177.                     lDrive$ = ""
  178.                     lDestDir$ = ""
  179.                 END IF
  180.                 
  181.             ELSE  '' no key.  Poop.
  182.                 lDrive$ = ""
  183.                 lDestDir$ = ""
  184.             END IF
  185.         ENDIF
  186. '$IFDEF DEBUG
  187.     ELSE
  188.         VMessageBox "No file extension passed to VFindExe", "VFindExe Debug"
  189. '$ENDIF 'DEBUG
  190.     ENDIF
  191.  
  192.     '' can't find it;  punt!
  193.     IF lDestDir$ = "" THEN
  194.  
  195.         VDbgMsgBox "Can't find exe anywhere", "VFindExeFromRegistration Debug"
  196.  
  197.         pDest$ = ""
  198.         VFindExeFromRegistration = 0
  199.      ELSE
  200.         pDest$ = lDestDir$
  201.         VFindExeFromRegistration = 1
  202.     ENDIF
  203.  
  204.     RestoreCursor CursorSave%
  205.  
  206. END FUNCTION
  207.  
  208. '----------------------------------------------------------------
  209. '----------------------------------------------------------------
  210. FUNCTION VFindExe (pFName$, pFExten$, pDest$) STATIC AS INTEGER
  211. '$ifdef DEBUG
  212.     if pFName$ = "" then
  213.         BadArgErr 1, "VFindExe", pFName$
  214.     end if
  215. '$endif ''DEBUG
  216.     '' set the local vars.
  217.     lDestDir$ = ""
  218.     lDrive$ = ""
  219.  
  220.  
  221.    '' step one:  try to find the file in the win.ini extensions section.
  222.    found% = VFindExeFromRegistration (pFExten, lDestDir$)
  223.  
  224.     '' step two:  search the hard drive for the exe.
  225.     IF lDestDir$ = "" THEN
  226.         dLetter$ = ""
  227.         LDList$ = "LocalHardDriveList"
  228.  
  229.  
  230.         VDbgMsgBox "Can't find exe from win.ini", "VFindExe Debug"
  231.  
  232.         OldCursor% = ShowWaitCursor()    '' set waiting cursor
  233.         sz$ = UIStartDlg("mscuistf.dll", LOOKFORFILE_DLG, "FModelessDlgProc", 0, "")
  234.         GetLocalHardDrivesList LDList$
  235.         DListLength% = GetListLength(LDList$)
  236.         FOR i% = 1 TO DListLength% STEP 1
  237.             dLetter$ = GetListItem(LDList$, i%)
  238.             IF (dLetter$ <> "" AND lDestDir$ = "") THEN
  239.                 lDrive$ = dLetter$ + ":\"
  240.                 lDestDir$ = FindFileInTree(pFName$, lDrive$)
  241.              ENDIF
  242.         NEXT i%
  243.  
  244.  
  245.         VDbgMsgBox "found an exe in " + lDestDir$, "VFindExe" 
  246.  
  247.  
  248.         IF lDestDir$ <> "" THEN
  249.             lDrive$ = lDestDir$
  250.             StrLen% = LEN(lDrive$)
  251.  
  252.             '' Extract directory name
  253.             WHILE (MID$(lDrive$, StrLen%, 1) <> "\") AND (StrLen% > 1)
  254.                 StrLen% = StrLen% - 1
  255.             WEND
  256.             StrLen% = StrLen% - 1
  257.  
  258.             lDestDir$ = MID$(lDrive$, 1, StrLen%)
  259.         END IF
  260.  
  261.         UIPop 1
  262.         RestoreCursor OldCursor%
  263.     END IF
  264.  
  265.     '' step three:  punt!
  266.     IF lDestDir$ = "" THEN
  267.  
  268.  
  269.         VDbgMsgBox "Can't find exe anywhere", "VFindExe Debug"
  270.  
  271.         pDest$ = ""
  272.         VFindExe = 0
  273.      ELSE
  274.         pDest$ = lDestDir$
  275.         VFindExe = 1
  276.     ENDIF
  277.  
  278. END FUNCTION
  279.  
  280.  
  281.  
  282.  
  283. '----------------------------------------------------------------
  284. '- Purpose:
  285. '-         to check if the user's system can handle our stuff.
  286. '-           (Win 3.1 on a 386 or better)
  287. '- Arguments:
  288. '-         none.
  289. '- Returns:
  290. '-         TRUE/FALSE if system is up to our products
  291. '----------------------------------------------------------------
  292. FUNCTION VIsSystemAdequate STATIC AS INTEGER
  293.     '' check the windows version and machine type.  Verify that it is capable.
  294.     WinMajVer% = GetWindowsMajorVersion()    '' 3, as in 3.1
  295.     WinMinVer% = GetWindowsMinorVersion()    '' 10, as in 3.10
  296.     Processor% = GetProcessorType()          '' 3(86), 4(86), 5(86)
  297.  
  298.     VIsSystemAdequate = 1
  299.     IF ((WinMajVer% = 3) AND (WinMinVer% < 10)) OR (WinMajVer < 3) THEN
  300.         sz$ = UIStartDlg("mscuistf.dll", NO_WIN_3_1_DLG, "FInfo0DlgProc", 0, "")
  301.         UIPop 1
  302.         VIsSystemAdequate = 0
  303.     ENDIF
  304.  
  305.     IF Processor% < 3 THEN
  306.         sz$ = UIStartDlg("mscuistf.dll", WRONG_CPU_DLG, "FInfo0DlgProc", 0, "")
  307.         UIPop 1
  308.         VIsSystemAdequate = 0
  309.     ENDIF
  310.  
  311. END FUNCTION
  312.  
  313.