home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD36692272000.psc / Server / other.bas < prev    next >
Encoding:
BASIC Source File  |  2000-02-27  |  6.8 KB  |  227 lines

  1. Attribute VB_Name = "other"
  2. 'Other functions and subs needed :)
  3.  
  4. Public Function ReplaceStr(ByVal strMain As String, strFind As String, strReplace As String) As String
  5. 'Thsi is the same thing as the Replace function in vb6.  I added this
  6. 'for those of you using vb5.  This was NOT written by me, it was written by
  7. ' someone named 'dos'.  He's a great programmer, visit his webpage @
  8. ' http://hider.com/dos
  9.  
  10.     Dim lngSpot As Long, lngNewSpot As Long, strLeft As String
  11.     Dim strRight As String, strNew As String
  12.     lngSpot& = InStr(LCase(strMain$), LCase(strFind$))
  13.     lngNewSpot& = lngSpot&
  14.     Do
  15.         If lngNewSpot& > 0& Then
  16.             strLeft$ = Left(strMain$, lngNewSpot& - 1)
  17.             If lngSpot& + Len(strFind$) <= Len(strMain$) Then
  18.                 strRight$ = Right(strMain$, Len(strMain$) - lngNewSpot& - Len(strFind$) + 1)
  19.             Else
  20.                 strRight = ""
  21.             End If
  22.             strNew$ = strLeft$ & strReplace$ & strRight$
  23.             strMain$ = strNew$
  24.         Else
  25.             strNew$ = strMain$
  26.         End If
  27.         lngSpot& = lngNewSpot& + Len(strReplace$)
  28.         If lngSpot& > 0 Then
  29.             lngNewSpot& = InStr(lngSpot&, LCase(strMain$), LCase(strFind$))
  30.         End If
  31.     Loop Until lngNewSpot& < 1
  32.     ReplaceStr$ = strNew$
  33. End Function
  34. Public Function text_read(filename)
  35. 'This function reads a file and spits out the text in it.
  36.  
  37. Dim f
  38. Dim textda
  39. Dim cha
  40.  
  41. On Error Resume Next
  42. f = FreeFile
  43. textda = ""
  44. If FileExists(filename) Then
  45.     If Len(filename) Then
  46.         Open filename For Input As #f   ' Open file.
  47.         Do While Not EOF(f)
  48.             cha = Input(1, #f) ' Get one character.
  49.              textda = "" & textda & cha
  50.         Loop    ' Loop if not end of file.
  51.         Close #f
  52.     End If
  53. text_read = textda
  54. Else
  55. text_read = ""
  56. End If
  57.  
  58. End Function
  59. Public Function FileExists(ByVal sFileName As String) As Integer
  60. 'Checks if the given file exists.
  61.  
  62. Dim i As Integer
  63. On Error Resume Next
  64.  
  65.     i = Len(Dir$(sFileName))
  66.     
  67.     If Err Or i = 0 Then
  68.         FileExists = False
  69.         Else
  70.             FileExists = True
  71.     End If
  72. End Function
  73. Public Sub timeout(ByVal nSecond As Single)
  74. 'Pauses for x seconds.
  75.  
  76.    Dim t0 As Single
  77.    t0 = Timer
  78.    Do While Timer - t0 < nSecond
  79.       Dim dummy As Integer
  80.  
  81.       dummy = DoEvents()
  82.       If Timer < t0 Then
  83.          t0 = t0 - CLng(24) * CLng(60) * CLng(60)
  84.       End If
  85.    Loop
  86.  
  87. End Sub
  88.  
  89. Public Function ConvertString(tmpVal As String, KeyValSize As Long) As String
  90.    If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then
  91.         ConvertString = Left(tmpVal, KeyValSize - 1)
  92.     Else
  93.         ConvertString = Left(tmpVal, KeyValSize)
  94.     End If
  95. End Function
  96.  
  97. Public Function RegReadValue(Stamm As Long, Pfad As String, Schluessel As String) As String
  98. Dim dataBuff As String, ldataBuffSize As Long, phkResult As Long, retval As Long, Text As String
  99.     dataBuff = Space(255)
  100.     ldataBuffSize = Len(dataBuff)
  101.     retval = RegOpenKeyEx(Stamm, Pfad, 0, KEY_ALL_ACCESS, phkResult)
  102.     retval = RegQueryValueEx(phkResult, Schluessel, 0, 0, dataBuff, ldataBuffSize)
  103.     If retval = ERROR_SUCCESS Then
  104.             RegReadValue = ConvertString(dataBuff, ldataBuffSize)
  105.     Else
  106.             RegReadValue = "Error"
  107.     End If
  108.     RegCloseKey Stamm
  109.     RegCloseKey phkResult
  110. End Function
  111.  
  112. Public Function RegWriteKey(Stamm As Long, Pfad As String) As Long
  113. Dim retval As Long, phkResult As Long, SA As SECURITY_ATTRIBUTES, Create As Long
  114. retval = RegCreateKeyEx(Stamm, Pfad, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, SA, phkResult, Create)
  115. RegCloseKey phkResult
  116. End Function
  117.  
  118. Public Function RegDelKey(Stamm As Long, Pfad As String) As Long
  119. Dim retval As Long, phkResult As Long
  120. retval = RegDeleteKey(Stamm, Pfad)
  121. RegCloseKey phkResult
  122. End Function
  123.  
  124. Public Function RegDelValue(Stamm As Long, Pfad As String, Value As String) As Long
  125. Dim retval As Long, phkResult As Long
  126. Pfad = AddASlash(Pfad)
  127. retval = RegOpenKeyEx(Stamm, Pfad, 0, KEY_ALL_ACCESS, phkResult)
  128. retval = RegDeleteValue(Stamm, Value)
  129. RegCloseKey phkResult
  130. End Function
  131.  
  132. Public Function RegWriteValue(Stamm As Long, Pfad As String, Value As String, Wert As String) As Long
  133. Dim retval As Long, phkResult As Long, SA As SECURITY_ATTRIBUTES, Create As Long
  134. Pfad = AddASlash(Pfad)
  135. retval = RegCreateKeyEx(Stamm, Pfad, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, SA, phkResult, Create)
  136.     retval = RegSetValueEx(phkResult, Value, 0, REG_SZ, _
  137.         Wert, CLng(Len(Wert) + 1))
  138.     RegCloseKey phkResult
  139. End Function
  140.  
  141. Public Function AddASlash(InString As String) As String
  142.     If Mid(InString, Len(InString), 1) <> "\" Then
  143.         AddASlash = InString & "\"
  144.     Else
  145.         AddASlash = InString
  146.     End If
  147. End Function
  148.  
  149. Public Sub Hook()
  150. lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
  151. End Sub
  152.  
  153. Public Sub Unhook()
  154. Dim tmp As Long
  155. tmp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
  156. End Sub
  157.  
  158. Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  159. If wParam = uID Then
  160. Select Case lParam
  161. Case WM_MOUSEMOVE
  162. Case WM_LBUTTONDOWN
  163. Case WM_LBUTTONUP
  164. Case WM_LBUTTONDBLCLK
  165.  
  166. If frmMain.mnuStart.Caption = "&Start" Then
  167. load_defaults
  168. Else
  169. stop_server
  170. End If
  171.  
  172. 'frmMain.Visible = True
  173. 'AppActivate frmMain.Caption
  174. Case WM_RBUTTONDOWN
  175.  
  176. frmMain.PopupMenu frmMain.mnuTray, vbPopupMenuRightAlign, , , frmMain.mnuStart
  177.  
  178. Case WM_RBUTTONUP
  179. Case WM_RBUTTONDBLCLK
  180. Case WM_MBUTTONDOWN
  181. Case WM_MBUTTONUP
  182. Case WM_MBUTTONDBLCLK
  183. Case Else
  184. End Select
  185. End If
  186. WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
  187. End Function
  188.  
  189. Public Sub ChangeTray(Title As String, Icon As Object)
  190. myNID.hIcon = Icon
  191. myNID.szTip = Title & Chr(0)
  192. ShellNotifyIcon NIM_MODIFY, myNID
  193. End Sub
  194.  
  195. Public Function TakeOutMenu(ThisForm As Form, ParamArray MenusToRemove() As Variant)
  196.     Dim DeleteMenu As Long
  197.     Dim ControlMenuHwnd As Long
  198.     Dim RemoveItem As Integer
  199.     Dim HighestArrayNumber
  200.     Dim x As Integer
  201.     
  202.     HighestArrayNumber = Val(UBound(MenusToRemove))
  203.       
  204.     For x = 0 To 5
  205.         'If no parameters were passed, then just exit
  206.         If HighestArrayNumber = -1 Then
  207.             MsgBox "No parameters specified"
  208.             Exit Function
  209.         End If
  210.         'If 6 or less arguments are passed, then
  211.         'we must exit when we get to the last element
  212.         'of the list!
  213.         If x > HighestArrayNumber Then
  214.            Exit Function
  215.         End If
  216.         'Take out the specified menu item now
  217.         RemoveItem = Val(MenusToRemove(x))
  218.         'Retrieve the Control Menu's handle
  219.         ControlMenuHwnd = GetSystemMenu(ThisForm.hWnd, 0)
  220.         'Remove this menu item
  221.         DeleteMenu = RemoveMenu(ControlMenuHwnd, RemoveItem, MF_BYCOMMAND)
  222.     Next x
  223. End Function
  224.  
  225.  
  226.  
  227.