home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / wsres2 / module1.bas < prev    next >
Encoding:
BASIC Source File  |  1995-05-09  |  3.2 KB  |  86 lines

  1. Option Explicit
  2. Global Const GFSR_GDIRESOURCES = &H1
  3. Global Const GFSR_SYSTEMRESOURCES = &H0
  4. Global Const GFSR_USERRESOURCES = &H2
  5. Global CRLF$
  6. Global Ini$
  7. 'exit windows declaration
  8. Declare Function ExitWindows% Lib "USER" (ByVal dwReserved&, ByVal wReturnCode%)
  9. 'windows system info declares
  10. Declare Function GetDriveType% Lib "KERNEL" (ByVal nDrive%)
  11. 'status.dll declares
  12. Declare Function FreeDriveSpace& Lib "status.dll" (ByVal Drive$)
  13. Declare Function FreeMem& Lib "status.dll" ()
  14. Declare Function GetFreeRes% Lib "status.dll" (ByVal ResType%)
  15. 'INI declarations
  16. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer
  17. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFilename As String) As Integer
  18. 'search window list declares
  19. Declare Function GetWindow% Lib "USER" (ByVal hWnd%, ByVal wCmd%)
  20. Global Const GW_HWNDFIRST = 0
  21. Global Const GW_HWNDNEXT = 2
  22. Declare Function GetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpString As String, ByVal aint As Integer) As Integer
  23. Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer
  24. 'prev inst restoration declarations
  25. Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
  26. Global Const SW_RESTORE = 9
  27. Global Const SW_SHOWNORMAL = 1
  28. Declare Function GetClassName Lib "User" (ByVal hWnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
  29.  
  30. 'window placement declarations
  31. Type PointAPI  '4 Bytes - Synonymous with LONG
  32.     x As Integer
  33.     y As Integer
  34. End Type
  35. Type Rect   '8 Bytes
  36.     Left As Integer
  37.     Top As Integer
  38.     right As Integer
  39.     bottom As Integer
  40. End Type
  41. Type WindowPlacement    '22 Bytes
  42.    Length As Integer
  43.    Flags As Integer
  44.    ShowCmd As Integer
  45.    ptMinPosition As PointAPI
  46.    ptMaxPosition As PointAPI
  47.    rcNormalPosition As Rect
  48. End Type
  49. Declare Function GetWindowPlacement% Lib "User" (ByVal hWnd%, lpwndpl As WindowPlacement)
  50.  
  51. Sub CenterForm (F As Form)
  52. F.Left = (Screen.Width - F.Width) / 2
  53. F.Top = (Screen.Height - F.Height) / 2
  54. End Sub
  55.  
  56. Function FindPrevInstance% (Cap$)
  57. Dim w%, y%, winCap As String * 255
  58. w% = GetWindow%(Form1.hWnd, GW_HWNDFIRST)
  59. Do While w% <> 0
  60.    y% = GetWindowText(w%, winCap, 254)
  61.    If Left$(winCap, Len(Cap$)) = Cap$ And w% <> Form1.hWnd Then
  62.       'kludge to prevent finding hidden vb parent window
  63.       y% = GetClassName(w%, winCap, 254)
  64.       If InStr(winCap, "ThunderForm") > 0 Then
  65.       FindPrevInstance% = w%
  66.      Exit Do
  67.       End If
  68.   End If
  69.   w% = GetWindow%(w%, GW_HWNDNEXT)
  70. Loop
  71. End Function
  72.  
  73. Function GetIni$ (pKey$)
  74. Dim x%
  75. Dim Ret As String * 1024
  76. x% = GetPrivateProfileString%("Settings", pKey$, "", Ret, Len(Ret), Ini$)
  77. If x% > 0 Then GetIni$ = Left$(Ret, x%)
  78. End Function
  79.  
  80. Function WriteIni% (ByVal Key$, ByVal iOut$)
  81. Dim x%, s$
  82. x% = WritePrivateProfileString("Settings", Key$, iOut$, Ini$)
  83. If x% <> 0 Then WriteIni% = True
  84. End Function
  85.  
  86.