home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD176803292001.psc / api.cls next >
Encoding:
Visual Basic class definition  |  2001-03-28  |  10.0 KB  |  308 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "WinAPI"
  10. Attribute VB_GlobalNameSpace = True
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. '--------------------------------------------------------
  15. 'Visual Basic Runtime Procedures Extension
  16. 'Sushant Pandurangi <sushant@phreaker.net>
  17. '--------------------------------------------------------
  18. Option Explicit
  19. Private Const PROCESSOR_ALPHA_21064 = 21064
  20. Private Const PROCESSOR_INTEL_386 = 386
  21. Private Const PROCESSOR_INTEL_486 = 486
  22. Private Const PROCESSOR_INTEL_PENTIUM = 586
  23. Private Const PROCESSOR_MIPS_R4000 = 4000
  24. Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
  25. Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
  26. Private Const VER_PLATFORM_WIN32_NT = 2
  27. Private Const VER_PLATFORM_WIN32_WINDOWS = 1
  28. Private Const VER_PLATFORM_WIN32s = 0
  29. Private Type SYSTEM_INFO
  30.         dwOemID As Long
  31.         dwPageSize As Long
  32.         lpMinimumApplicationAddress As Long
  33.         lpMaximumApplicationAddress As Long
  34.         dwActiveProcessorMask As Long
  35.         dwNumberOrfProcessors As Long
  36.         dwProcessorType As Long
  37.         dwAllocationGranularity As Long
  38.         dwReserved As Long
  39. End Type
  40. Private Type OSVERSIONINFO
  41.   dwOSVersionInfoSize As Long
  42.   dwMajorVersion As Long
  43.   dwMinorVersion As Long
  44.   dwBuildNumber As Long
  45.   dwPlatformId As Long
  46.   szCSDVersion As String * 128
  47. End Type
  48. Public Enum EnumPropertytype
  49.  SYSTEM_SETTINGS = 1
  50.  INTERNET_SETTINGS = 2
  51.  MODEM_SETTINGS = 3
  52.  ADD_REMOVE_APPS = 4
  53.  ADD_NEW_HARDWARE = 5
  54.  SOUNDS_SETTINGS = 6
  55.  NETWORK_SETTINGS = 7
  56.  MOUSE_SETTINGS = 8
  57.  KEYBOARD_SETTINGS = 9
  58.  TIME_DATE_SETTINGS = 10
  59.  REGIONAL_SETTINGS = 11
  60.  PASSWORD_SETTINGS = 12
  61.  DISPLAY_SETTINGS = 13
  62. End Enum
  63. Private Type MEMORYSTATUS
  64.         dwLength As Long
  65.         dwMemoryLoad As Long
  66.         dwTotalPhys As Long
  67.         dwAvailPhys As Long
  68.         dwTotalPageFile As Long
  69.         dwAvailPageFile As Long
  70.         dwTotalVirtual As Long
  71.         dwAvailVirtual As Long
  72. End Type
  73. Public Enum EnumPositions
  74.  TOPMOST_TRUE = -1
  75.  TOPMOST_FALSE = -2
  76. End Enum
  77. Public Enum EnumExitType
  78.  LOGOFF = 0
  79.  BYEBYE = 1
  80.  REBOOT = 2
  81. End Enum
  82. Dim systemInfo As SYSTEM_INFO
  83. Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
  84.  
  85.  
  86. Sub AboutBox()
  87. frmAbout.Show vbModal
  88. End Sub
  89.  
  90. Public Sub Progress(ByVal bShowProgressBar As Boolean, pForm As Object, Progressbar As Object, Statusbar As Object, Panel As Integer)
  91. Attribute Progress.VB_Description = "Show a progress bar in the status bar, integrated."
  92.     Dim tRC As RECT
  93.     If bShowProgressBar Then
  94.         SendMessageAny Statusbar.hWnd, SB_GETRECT, Panel, tRC
  95.         With tRC
  96.             .Top = (.Top * Screen.TwipsPerPixelY)
  97.             .Left = (.Left * Screen.TwipsPerPixelX)
  98.             .Bottom = (.Bottom * Screen.TwipsPerPixelY) - .Top
  99.             .Right = (.Right * Screen.TwipsPerPixelX) - .Left
  100.         End With
  101.         With Progressbar
  102.             SetParent .hWnd, Statusbar.hWnd
  103.             .Move tRC.Left, tRC.Top, tRC.Right, tRC.Bottom
  104.             .Visible = True
  105.             .Value = 0
  106.         End With
  107.     Else
  108.         SetParent Progressbar.hWnd, pForm.hWnd
  109.         Progressbar.Visible = False
  110.     End If
  111. End Sub
  112.  
  113. Public Sub DeleteFile(szFileName As String)
  114. Attribute DeleteFile.VB_Description = "Deletes a file from the given path."
  115. Dim SHop As SHFILEOPSTRUCT
  116. Dim strFile As String
  117. strFile = szFileName
  118. With SHop
  119.     .wFunc = FO_DELETE
  120.     .pFrom = strFile
  121.     .fFlags = FOF_ALLOWUNDO
  122. End With
  123. SHFileOperation SHop
  124. End Sub
  125.  
  126. Public Sub CopyFile(szFileSource As String, szFileDestination As String)
  127. Attribute CopyFile.VB_Description = "Copies a file from the source to the destination"
  128. Dim SHop As SHFILEOPSTRUCT
  129. With SHop
  130.     .wFunc = FO_COPY
  131.     .pTo = szFileDestination
  132.     .pFrom = szFileSource
  133.     .fFlags = FOF_ALLOWUNDO
  134. End With
  135. SHFileOperation SHop
  136. End Sub
  137.  
  138. Public Sub MoveFile(szFileSource As String, szFileDestination As String)
  139. Attribute MoveFile.VB_Description = "Moves a file from the source to the destination"
  140. Dim SHop As SHFILEOPSTRUCT
  141. With SHop
  142.     .wFunc = FO_MOVE
  143.     .pFrom = szFileSource
  144.     .pTo = szFileDestination
  145.     .fFlags = FOF_ALLOWUNDO
  146. End With
  147. SHFileOperation SHop
  148. End Sub
  149.  
  150. Public Function PathExists(szPath As String) As Boolean
  151. Attribute PathExists.VB_Description = "Check if a specified path exists and return true or false."
  152. PathExists = (Dir(szPath) <> "")
  153. End Function
  154.  
  155. Function ShutDown(ExitType As EnumExitType)
  156. Attribute ShutDown.VB_Description = "Shutdown,Restart or log off windows."
  157. Dim lngResult As Long
  158. lngResult = ExitWindowsEx(ExitType, 0&)
  159. End Function
  160.  
  161. Function EasyMove(pForm As Object)
  162. Attribute EasyMove.VB_Description = "Enables moving the form by dragging any control."
  163. ReleaseCapture
  164. SendMessage pForm.hWnd, &HA1, 2, 0&
  165. End Function
  166.  
  167. Sub StandBy(MilliSeconds As Long)
  168. Attribute StandBy.VB_Description = "Standby for the specified time."
  169. Sleep MilliSeconds
  170. End Sub
  171.  
  172. Sub Properties(sType As EnumPropertytype)
  173. Attribute Properties.VB_Description = "System properties."
  174. Dim dblReturn
  175. If sType = ADD_REMOVE_APPS Then
  176. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,1", 5)
  177. ElseIf sType = ADD_NEW_HARDWARE Then
  178. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl @1", 5)
  179. ElseIf sType = INTERNET_SETTINGS Then
  180. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,0", 5)
  181. ElseIf sType = KEYBOARD_SETTINGS Then
  182. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL main.cpl @1", 5)
  183. ElseIf sType = MODEM_SETTINGS Then
  184. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL modem.cpl", 5)
  185. ElseIf sType = MOUSE_SETTINGS Then
  186. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL main.cpl @0", 5)
  187. ElseIf sType = NETWORK_SETTINGS Then
  188. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL netcpl.cpl", 5)
  189. ElseIf sType = SOUNDS_SETTINGS Then
  190. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl @1", 5)
  191. ElseIf sType = SYSTEM_SETTINGS Then
  192. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,0", 5)
  193. ElseIf sType = DISPLAY_SETTINGS Then
  194. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0", 5)
  195. ElseIf sType = PASSWORD_SETTINGS Then
  196. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL password.cpl", 5)
  197. ElseIf sType = REGIONAL_SETTINGS Then
  198. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,0", 5)
  199. ElseIf sType = TIME_DATE_SETTINGS Then
  200. dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL timedate.cpl", 5)
  201. End If
  202. End Sub
  203.  
  204. Public Sub FindDialog(Optional InitialDirectory As String)
  205. Attribute FindDialog.VB_Description = "Shows the Win32 Find dialog."
  206. ShellExecute 0, "find", IIf(InitialDirectory = "", "", InitialDirectory), vbNullString, vbNullString, 10
  207. End Sub
  208.  
  209. Public Sub RunDialog(ByRef wndHandle As Long, Optional Title As String = "Run", Optional Description As String = "Type the name of a program to open, then click OK when finished.")
  210. Attribute RunDialog.VB_Description = "Shows Win32 Run Dialog."
  211. SHRunDialog wndHandle, 0, 0, Title, Description, 0
  212. End Sub
  213.  
  214. Sub CopyText(sTextBox As Object)
  215. Attribute CopyText.VB_Description = "Copies text from the given TextBox."
  216. SendMessage sTextBox.hWnd, WM_COPY, 0, 0&
  217. End Sub
  218.  
  219. Sub PasteText(sTextBox As Object)
  220. Attribute PasteText.VB_Description = "Pastes text from the clipboard."
  221. SendMessage sTextBox.hWnd, WM_PASTE, 0, 0&
  222. End Sub
  223.  
  224. Sub UndoEdit(sTextBox As Object)
  225. Attribute UndoEdit.VB_Description = "Undo the edit in a textbox."
  226. SendMessage sTextBox.hWnd, EM_UNDO, 0, 0&
  227. End Sub
  228.  
  229. Function UsedTime() As Long
  230. Dim lngTickCount As Long
  231. lngTickCount = GetTickCount
  232. UsedTime = CStr(lngTickCount / 1000)
  233. End Function
  234.  
  235. Function GetMemory(ReturnedTotal As Long, ReturnedAvailable As Long)
  236. Dim memoryInfo As MEMORYSTATUS
  237. GlobalMemoryStatus memoryInfo
  238. ReturnedTotal = memoryInfo.dwTotalPhys
  239. ReturnedAvailable = memoryInfo.dwAvailPhys
  240. End Function
  241.  
  242. Function Processor() As String
  243. GetSystemInfo systemInfo
  244. Select Case systemInfo.dwProcessorType
  245. Case PROCESSOR_ALPHA_21064 = 21064
  246. Processor = "Alpha"
  247. Case PROCESSOR_INTEL_386
  248. Processor = "Intel 80386"
  249. Case PROCESSOR_INTEL_486
  250. Processor = "Intel 80486"
  251. Case PROCESSOR_INTEL_PENTIUM
  252. Processor = "Intel Pentium"
  253. Case PROCESSOR_MIPS_R4000
  254. Processor = "MIPS"
  255. End Select
  256. End Function
  257.  
  258. Public Function WindowsVer()
  259. Dim infoStruct As OSVERSIONINFO
  260. infoStruct.dwOSVersionInfoSize = Len(infoStruct)
  261. GetVersionEx infoStruct
  262. If infoStruct.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then
  263.     WindowsVer = "Windows 95/98"
  264. Else
  265.     WindowsVer = "Windows NT"
  266. End If
  267. End Function
  268.  
  269. Function SystemDir() As String
  270.     Dim strBuf As String
  271.     strBuf = Space$(255)
  272.     'Get the system directory and then trim the buffer to the exact length
  273.     'returned and add a dir sep (backslash) if the API didn't return one
  274.     If GetSystemDirectory(strBuf, 255) > 0 Then
  275.         'strBuf = StripTerminator(strBuf)
  276.         'AddDirSep strBuf
  277.        SystemDir = Left(strBuf, GetSystemDirectory(strBuf, 255))
  278.     Else
  279.         SystemDir = vbNullString
  280.     End If
  281. End Function
  282.  
  283. Function WindowsDir() As String
  284.     Dim strBuf As String
  285.     strBuf = Space$(255)
  286.     'Get the windows directory and then trim the buffer to the exact length
  287.     'returned and add a dir sep (backslash) if the API didn't return one
  288.     If GetWindowsDirectory(strBuf, 255) > 0 Then
  289.         WindowsDir = Left(strBuf, GetWindowsDirectory(strBuf, 255))
  290.     Else
  291.         WindowsDir = vbNullString
  292.     End If
  293. End Function
  294.  
  295. Sub InstallFont(vFontFileName As String)
  296. 'Install a new font
  297. AddFontResource vFontFileName
  298. End Sub
  299.  
  300. Sub FormTop(pForm As Object)
  301. 'Always on top
  302. BringWindowToTop pForm.hWnd
  303. End Sub
  304.  
  305. Sub CloseWnd(pForm As Object)
  306. CloseWindow pForm.hWnd
  307. End Sub
  308.