home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / djapi / djapi.ctl (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-06  |  11.2 KB  |  276 lines

  1. VERSION 5.00
  2. Begin VB.UserControl DJApi 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H80000005&
  5.    BorderStyle     =   1  'Fixed Single
  6.    CanGetFocus     =   0   'False
  7.    ClientHeight    =   330
  8.    ClientLeft      =   0
  9.    ClientTop       =   0
  10.    ClientWidth     =   765
  11.    InvisibleAtRuntime=   -1  'True
  12.    ScaleHeight     =   330
  13.    ScaleWidth      =   765
  14.    ToolboxBitmap   =   "DJApi.ctx":0000
  15.    Begin VB.Label Label3 
  16.       Appearance      =   0  'Flat
  17.       AutoSize        =   -1  'True
  18.       BackColor       =   &H80000005&
  19.       Caption         =   "www.toolcity.net/~djcomlab"
  20.       ForeColor       =   &H80000008&
  21.       Height          =   195
  22.       Left            =   15
  23.       TabIndex        =   2
  24.       Top             =   525
  25.       Width           =   1980
  26.    End
  27.    Begin VB.Label Label2 
  28.       Appearance      =   0  'Flat
  29.       AutoSize        =   -1  'True
  30.       BackColor       =   &H80000005&
  31.       Caption         =   "(c)1999 DJ's Computer Labs"
  32.       ForeColor       =   &H80000008&
  33.       Height          =   195
  34.       Left            =   15
  35.       TabIndex        =   1
  36.       Top             =   315
  37.       Width           =   1995
  38.    End
  39.    Begin VB.Label Label1 
  40.       Appearance      =   0  'Flat
  41.       AutoSize        =   -1  'True
  42.       BackColor       =   &H80000005&
  43.       Caption         =   "Label1"
  44.       ForeColor       =   &H80000008&
  45.       Height          =   195
  46.       Left            =   45
  47.       TabIndex        =   0
  48.       Top             =   45
  49.       Width           =   480
  50.    End
  51. Attribute VB_Name = "DJApi"
  52. Attribute VB_GlobalNameSpace = False
  53. Attribute VB_Creatable = True
  54. Attribute VB_PredeclaredId = False
  55. Attribute VB_Exposed = False
  56. Private Declare Function EnumChildren Lib "user32" Alias "EnumChildWindows" _
  57. (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, _
  58. ByVal lParam As Long) As Long
  59. Private Declare Function GetWin Lib "user32.dll" Alias "GetWindow" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
  60. Enum GetWindow
  61.   GW_HWNDFIRST = 0
  62.   'The highest window in the Z-order having the same parent as the given window.
  63.   GW_HWNDLAST = 1
  64.   'The lowest window in the Z-order having the same parent as the given window.
  65.   GW_HWNDNEXT = 2
  66.   'The window below the given window in the Z-order.
  67.   GW_HWNDPREV = 3
  68.   'The window above the given window in the Z-order.
  69.   GW_OWNER = 4
  70.   'The window that owns the given window (not to be confused with the parent window).
  71.   GW_CHILD = 5
  72.   'The topmost of the given window's child windows. This has the same effect as using the GetTopWindow function.
  73. End Enum
  74. Private Declare Function GetWinText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  75. Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
  76. Private Declare Function IsThisWindow Lib "user32.dll" Alias "IsWindow" (ByVal hWnd As Long) As Long
  77. Private Declare Function GetParenthWnd Lib "user32.dll" Alias "GetParent" (ByVal hWnd As Long) As Long
  78. Private Declare Function SetParenthWnd Lib "user32.dll" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
  79. Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction _
  80. As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
  81. Private Declare Function ComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  82. Private Declare Function MoveWindow Lib "user32.dll" Alias "SetWindowPos" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  83. Private Declare Function GetWindow Lib "user32.dll" Alias "GetWindowRect" (ByVal hWnd As Long, lpRect As Rect) As Long
  84. '''''''''''''''''''''''''''''''''''''''''''''''''
  85. ''''''hide taskbar'''''''''''''''''''''''''''''
  86. Private Declare Function ShowWindow Lib _
  87. "user32" (ByVal hWnd As Long, _
  88. ByVal nCmdShow As Long) As Long
  89. Private Declare Function FindWindow Lib _
  90. "user32" Alias "FindWindowA" _
  91. (ByVal lpClassName As String, _
  92. ByVal lpWindowName As String) _
  93. As Long
  94. '''''''''''''''''''''''''''''''''''''''''''''''''''
  95. ''''''togglelock''''''''''''''''''''''''''''''''''''
  96. Enum LockKeys
  97.   VK_CAPITAL = &H14
  98.   VK_NUMLOCK = &H90
  99.   VK_SCROLL = &H91
  100. End Enum
  101. Private Type KeyboardBytes
  102.      kbByte(0 To 255) As Byte
  103. End Type
  104. Private kbArray As KeyboardBytes
  105. 'Private Declare Function GetKeyState Lib "user32" _
  106. '(ByVal nVirtKey As Long) As Long
  107. Private Declare Function GetKeyboardState Lib "user32" _
  108. (kbArray As KeyboardBytes) As Long
  109. Private Declare Function SetKeyboardState Lib "user32" _
  110. (kbArray As KeyboardBytes) As Long
  111. '''''''''''''''''''''''''''''''''''''''''''''
  112. ''''remove close 'x' button''''''''''''''''''
  113. Private Declare Function GetSystemMenu Lib "user32" _
  114. (ByVal hWnd As Long, ByVal bRevert As Long) As Long
  115. Private Declare Function GetMenuItemCount Lib "user32" _
  116. (ByVal hMenu As Long) As Long
  117. Private Declare Function DrawMenuBar Lib "user32" _
  118. (ByVal hWnd As Long) As Long
  119. Private Declare Function RemoveMenu Lib "user32" _
  120. (ByVal hMenu As Long, ByVal nPosition As Long, _
  121. ByVal wFlags As Long) As Long
  122. Const MF_BYPOSITION = &H400&
  123. Const MF_REMOVE = &H1000&
  124. ''''''''''''''''''''''''''''''''''''''''''''
  125. Const SWP_FRAMECHANGED = &H20
  126. Const SWP_DRAWFRAME = SWP_FRAMECHANGED
  127. Const SWP_HIDEWINDOW = &H80
  128. Const SWP_NOACTIVATE = &H10
  129. Const SWP_NOCOPYBITS = &H100
  130. Const SWP_NOMOVE = &H2
  131. Const SWP_NOSIZE = &H1
  132. Const SWP_NOREDRAW = &H8
  133. Const SWP_NOZORDER = &H4
  134. Const SWP_SHOWWINDOW = &H40
  135. Private Type Rect
  136.   Left As Long
  137.   Top As Long
  138.   Right As Long
  139.   Bottom As Long
  140. End Type
  141. Enum ZOrder
  142.   HWND_BOTTOM = 1
  143.   HWND_NOTOPMOST = -2
  144.   HWND_TOP = 0
  145.   HWND_TOPMOST = -1
  146. End Enum
  147. Enum OnOff
  148.   [Turn Off] = -1
  149.   [Turn On] = 1
  150. End Enum
  151. Private m_vShow As Boolean
  152. 'Load property values from storage
  153. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  154.   Label1.Caption = Extender.Name
  155.   m_vShow = True
  156. End Sub
  157. Private Sub UserControl_InitProperties()
  158.   Label1 = Extender.Name
  159.   m_vShow = True
  160. End Sub
  161. Public Function GetComputerName() As String
  162. Attribute GetComputerName.VB_Description = "Returns the network name of the user's computer."
  163.   Dim compname As String * 255, cname As String
  164.   Call ComputerName(compname, 255)
  165.   cname = Trim(compname)
  166.   GetComputerName = Left(cname, Len(cname) - 1)
  167. End Function
  168. Public Sub DisableSystemKeys(ByVal bDisabled As Boolean)
  169. Attribute DisableSystemKeys.VB_Description = "Toggle the enabled property of ctl-alt-del, ctl-esc, atl-tab, and win95 keyboard keys. Its all or nothing as there is no way to specify which system keys to toggle."
  170.   Call SystemParametersInfo(97, bDisabled, CStr(1), 0)
  171. End Sub
  172. Public Function GetParent(ByVal hWnd As Long) As Long
  173. Attribute GetParent.VB_Description = "Returns the handle of the parent window of another window. For example, the parent of a button would normally be the form window it is in."
  174.   GetParent = GetParenthWnd(hWnd)
  175. End Function
  176. Public Sub SetParent(ByVal Child_hWnd As Long, ByVal NewParent_hWnd As Long)
  177. Attribute SetParent.VB_Description = "Moves a window from having one parent window to another. If needed, the window itself moves so it can be ""inside"" its new parent."
  178.   Call SetParenthWnd(Child_hWnd, NewParent_hWnd)
  179. End Sub
  180. Public Sub SetWindowPos(ByVal hWnd As Long, Order As ZOrder, _
  181. ByVal Left As Single, ByVal Top As Single)
  182. Attribute SetWindowPos.VB_Description = "Moves a window to a new location. Its physical coordinates, dimensions, and Z-order position (the Z-order determines which windows are on top of others) can be set."
  183.   Dim flags As Long
  184.   Left = Left / Screen.TwipsPerPixelX
  185.   Top = Top / Screen.TwipsPerPixelY
  186.   flags = SWP_NOSIZE Or SWP_DRAWFRAME  ' don't resize, but redraw window
  187.   Call MoveWindow(hWnd, Order, Left, Top, 0, 0, flags)
  188. ' (the cx and cy parameters are ignored because of SWP_NOSIZE)
  189. End Sub
  190. Public Sub GetWindowRect(ByVal hWnd As Long, _
  191. ByRef Left As Long, ByRef Top As Long)
  192. Attribute GetWindowRect.VB_Description = "Returns the left and top screen position of a window in pixels. Not its position within its parent."
  193.   Dim r As Rect
  194.   Call GetWindow(hWnd, r)
  195.   Left = r.Left
  196.   Top = r.Top
  197. End Sub
  198. Public Sub DisableClose(hWnd As Long)
  199. Attribute DisableClose.VB_Description = "Disable the Close 'X' button of a form."
  200.   Dim hSysMenu As Long
  201.   Dim cCnt As Long
  202.   ' Get handle to our form's system menu
  203.   ' (Restore, Maximize, Move, close etc.)
  204.   hSysMenu = GetSystemMenu(hWnd, False)
  205.   If hSysMenu Then
  206.   ' Get System menu's menu count
  207.     nCnt = GetMenuItemCount(hSysMenu)
  208.     If nCnt Then
  209.       ' Menu count is based on 0 (0, 1, 2, 3...)
  210.       RemoveMenu hSysMenu, nCnt - 1, _
  211.       MF_BYPOSITION Or MF_REMOVE
  212.       RemoveMenu hSysMenu, nCnt - 2, _
  213.       MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
  214.       DrawMenuBar hWnd
  215.       ' Force caption bar's refresh. Disabling X button
  216.       'Me.Caption = "Try to close me!"
  217.     End If
  218.   End If
  219. End Sub
  220. Public Sub ShowTaskBar()
  221. Attribute ShowTaskBar.VB_Description = "Toggle visible status of TaskBar."
  222.   Dim hWnd As Long
  223.   hWnd = FindWindow("Shell_traywnd", "")
  224.   If m_vShow Then
  225.     'if TaskBar.Show=true it shows the TaskBar
  226.     Call ShowWindow(hWnd, 0)
  227.     m_vShow = False
  228.   Else
  229.     'if not it hides the TaskBar
  230.     Call ShowWindow(hWnd, 1)
  231.     m_vShow = True
  232.   End If
  233. End Sub
  234. Public Sub LockToggle(ByVal ToglKey As LockKeys, _
  235. Optional ByVal State As OnOff)
  236. Attribute LockToggle.VB_Description = "Toggle lock key status: Num, Caps, and Scroll. Use optional State value to force key into on or off position."
  237.     GetKeyboardState kbArray
  238.     Select Case State
  239.       Case 0
  240.         kbArray.kbByte(ToglKey) = _
  241.         IIf(kbArray.kbByte(ToglKey) = 1, 0, 1)
  242.       Case [Turn On]
  243.         kbArray.kbByte(ToglKey) = 1
  244.       Case [Turn Off]
  245.         kbArray.kbByte(ToglKey) = 0
  246.     End Select
  247.     SetKeyboardState kbArray
  248. End Sub
  249. Public Function IsWindow(ByVal hWnd As Long) As Boolean
  250. Attribute IsWindow.VB_Description = "Returns boolean (True or False) indicating whether the specified window handle identifies an existing window."
  251.   Dim lngX As Long
  252.   lngX = IsThisWindow(hWnd)
  253.   If lngX = 0 Then
  254.     IsWindow = False
  255.   Else
  256.     IsWindow = True
  257.   End If
  258. End Function
  259. Public Function GetWindowText(ByVal hWnd As Long) As String
  260. Attribute GetWindowText.VB_Description = "Returns the title of a window (that is, its .Caption property). This function works with any window, not just those in your application! "
  261.   Dim Buffer As String
  262.   Dim lngX As Long
  263.   Dim lngN As Long
  264.   ' Create a string of n+1 to receive the title (to allow for the ending vbNullChar
  265.   lngN = GetWindowTextLength(hWnd) + 1
  266.   Buffer = Space(lngN)
  267.   ' Read the title
  268.   lngX = GetWinText(hWnd, Buffer, lngN)
  269.   GetWindowText = Left(Buffer, lngX) ' drop the vbNullChar
  270. End Function
  271. Public Function GetNextWindow(ByVal hWnd As Long, Relation As GetWindow) As Long
  272.   GetNextWindow = GetWin(hWnd, iRelation)  ' next window in Z-order
  273. End Function
  274. Public Sub EnumChildWindows()
  275. End Sub
  276.