home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer'…arterly (Limited Edition) / Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso / code / ch26code / public.bas < prev    next >
BASIC Source File  |  1995-08-01  |  5KB  |  112 lines

  1. Attribute VB_Name = "basPublic"
  2. '*********************************************************************
  3. ' PUBLIC.BAS - Global constants, functions, and variables.
  4. '*********************************************************************
  5. Option Explicit
  6. '*********************************************************************
  7. ' API Declarations for this module.
  8. '*********************************************************************
  9. #If Win32 Then
  10. Private Declare Function GetPrivateProfileString Lib "kernel32" Alias _
  11.     "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
  12.     lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetStr _
  13.     As String, ByVal nSize As Long, ByVal lpFileName$) As Long
  14. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
  15.     (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
  16. Private Declare Function PostMessage Lib "user32" Alias _
  17.     "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal _
  18.     wParam As Long, lParam As Any) As Long
  19. Private Declare Function ShowWindow Lib "user32" (ByVal hWnd&, _
  20.     ByVal nCmdShow As Long) As Long
  21. #Else
  22. Private Declare Function GetPrivateProfileString Lib "Kernel" _
  23.     (ByVal lpAppName$, ByVal lpKeyName$, ByVal lpDefault$, _
  24.     ByVal lpReturnStr$, ByVal nSize%, ByVal lpFileName$) As Integer
  25.  
  26. Private Declare Function FindWindow Lib "User" (ByVal lpClassName$, _
  27.     ByVal lpWindowName As Long) As Integer
  28.                                
  29. Private Declare Function PostMessage Lib "User" (ByVal hWnd%, _
  30.     ByVal wMsg As Integer, ByVal wParam%, lParam&) As Long
  31.  
  32. Private Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer, _
  33.     ByVal nCmdShow As Integer) As Integer
  34. #End If
  35. '*********************************************************************
  36. ' These globals keep track of the new instances of frmExcel.
  37. '*********************************************************************
  38. Public Const MAX_WINDOWS = 4
  39. Public Excels(MAX_WINDOWS) As New frmExcel
  40. Public ExcelWindows As Integer
  41. Public ActiveIndex%
  42. '*********************************************************************
  43. ' Generic update status bar routine.
  44. '*********************************************************************
  45. Public Sub UpdateStatus(StatusBar As Label, Optional StatusText)
  46.     If IsMissing(StatusText) Then
  47.         StatusBar = "Ready"
  48.     Else
  49.         StatusBar = StatusText
  50.     End If
  51. End Sub
  52. '*********************************************************************
  53. ' Start a OLE Server, if it is not already running.
  54. '*********************************************************************
  55. Public Function StartServer(ClassName$, Program$) As Long
  56. Const SW_SHOWNA = 8
  57. #If Win32 Then
  58. Dim hWnd As Long
  59. #Else
  60. Dim hWnd As Integer
  61. #End If
  62.     '*****************************************************************
  63.     ' Prevent any error messages from interrupting the program.
  64.     '*****************************************************************
  65.     On Error Resume Next
  66.     '*****************************************************************
  67.     ' Check to see if its already running. If so, then activate it.
  68.     '*****************************************************************
  69.     hWnd = FindWindow(ClassName, 0&)
  70.     
  71.     If hWnd Then
  72.         ShowWindow hWnd, SW_SHOWNA
  73.         '*************************************************************
  74.         ' Return False to indicate that it was already running.
  75.         '*************************************************************
  76.         StartServer = False
  77.     Else
  78.         '*************************************************************
  79.         ' Otherwise, start it and return its hWnd.
  80.         '*************************************************************
  81.         Shell Program, vbMinimizedNoFocus
  82.         DoEvents
  83.         StartServer = FindWindow(ClassName, 0&)
  84.     End If
  85.     
  86. End Function
  87. '*********************************************************************
  88. ' Calls the API to read an INI file, and return the results.
  89. '*********************************************************************
  90. ' NOTE: ByVal is used, so you can pass control values such
  91. '       as Text1.Text without surrounding it in parenthesis.
  92. '*********************************************************************
  93. Public Function GetINI(ByVal Section$, ByVal Key$, ByVal _
  94.                        Default$, ByVal FileName$) As String
  95. Dim res%, retVal$
  96.     retVal = Space$(32400)
  97.     res = GetPrivateProfileString(Section, Key, Default, _
  98.                             retVal, Len(retVal), FileName)
  99.     GetINI = Left$(retVal, res)
  100. End Function
  101. '*********************************************************************
  102. ' Posts a WM_CLOSE message to an application.
  103. '*********************************************************************
  104. Public Sub CloseApp(hWnd As Long)
  105. Const WM_CLOSE = &H10
  106.     #If Win32 Then
  107.         PostMessage hWnd, WM_CLOSE, 0, 0&
  108.     #Else
  109.         PostMessage CInt(hWnd), WM_CLOSE, 0, 0&
  110.     #End If
  111. End Sub
  112.