Private Declare Function EnumChildren Lib "user32" Alias "EnumChildWindows" _
(ByVal hWndParent As Long, ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Private Declare Function GetWin Lib "user32.dll" Alias "GetWindow" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Enum GetWindow
GW_HWNDFIRST = 0
'The highest window in the Z-order having the same parent as the given window.
GW_HWNDLAST = 1
'The lowest window in the Z-order having the same parent as the given window.
GW_HWNDNEXT = 2
'The window below the given window in the Z-order.
GW_HWNDPREV = 3
'The window above the given window in the Z-order.
GW_OWNER = 4
'The window that owns the given window (not to be confused with the parent window).
GW_CHILD = 5
'The topmost of the given window's child windows. This has the same effect as using the GetTopWindow function.
End Enum
Private Declare Function GetWinText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Private Declare Function IsThisWindow Lib "user32.dll" Alias "IsWindow" (ByVal hWnd As Long) As Long
Private Declare Function GetParenthWnd Lib "user32.dll" Alias "GetParent" (ByVal hWnd As Long) As Long
Private Declare Function SetParenthWnd Lib "user32.dll" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction _
As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare Function ComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
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
Private Declare Function GetWindow Lib "user32.dll" Alias "GetWindowRect" (ByVal hWnd As Long, lpRect As Rect) As Long
'Private Declare Function GetKeyState Lib "user32" _
'(ByVal nVirtKey As Long) As Long
Private Declare Function GetKeyboardState Lib "user32" _
(kbArray As KeyboardBytes) As Long
Private Declare Function SetKeyboardState Lib "user32" _
(kbArray As KeyboardBytes) As Long
'''''''''''''''''''''''''''''''''''''''''''''
''''remove close 'x' button''''''''''''''''''
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Const MF_BYPOSITION = &H400&
Const MF_REMOVE = &H1000&
''''''''''''''''''''''''''''''''''''''''''''
Const SWP_FRAMECHANGED = &H20
Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Const SWP_HIDEWINDOW = &H80
Const SWP_NOACTIVATE = &H10
Const SWP_NOCOPYBITS = &H100
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const SWP_NOREDRAW = &H8
Const SWP_NOZORDER = &H4
Const SWP_SHOWWINDOW = &H40
Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Enum ZOrder
HWND_BOTTOM = 1
HWND_NOTOPMOST = -2
HWND_TOP = 0
HWND_TOPMOST = -1
End Enum
Enum OnOff
[Turn Off] = -1
[Turn On] = 1
End Enum
Private m_vShow As Boolean
'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Label1.Caption = Extender.Name
m_vShow = True
End Sub
Private Sub UserControl_InitProperties()
Label1 = Extender.Name
m_vShow = True
End Sub
Public Function GetComputerName() As String
Attribute GetComputerName.VB_Description = "Returns the network name of the user's computer."
Dim compname As String * 255, cname As String
Call ComputerName(compname, 255)
cname = Trim(compname)
GetComputerName = Left(cname, Len(cname) - 1)
End Function
Public Sub DisableSystemKeys(ByVal bDisabled As Boolean)
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."
Public Function GetParent(ByVal hWnd As Long) As Long
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."
GetParent = GetParenthWnd(hWnd)
End Function
Public Sub SetParent(ByVal Child_hWnd As Long, ByVal NewParent_hWnd As Long)
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."
Call SetParenthWnd(Child_hWnd, NewParent_hWnd)
End Sub
Public Sub SetWindowPos(ByVal hWnd As Long, Order As ZOrder, _
ByVal Left As Single, ByVal Top As Single)
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."
Dim flags As Long
Left = Left / Screen.TwipsPerPixelX
Top = Top / Screen.TwipsPerPixelY
flags = SWP_NOSIZE Or SWP_DRAWFRAME ' don't resize, but redraw window
' (the cx and cy parameters are ignored because of SWP_NOSIZE)
End Sub
Public Sub GetWindowRect(ByVal hWnd As Long, _
ByRef Left As Long, ByRef Top As Long)
Attribute GetWindowRect.VB_Description = "Returns the left and top screen position of a window in pixels. Not its position within its parent."
Dim r As Rect
Call GetWindow(hWnd, r)
Left = r.Left
Top = r.Top
End Sub
Public Sub DisableClose(hWnd As Long)
Attribute DisableClose.VB_Description = "Disable the Close 'X' button of a form."
Dim hSysMenu As Long
Dim cCnt As Long
' Get handle to our form's system menu
' (Restore, Maximize, Move, close etc.)
hSysMenu = GetSystemMenu(hWnd, False)
If hSysMenu Then
' Get System menu's menu count
nCnt = GetMenuItemCount(hSysMenu)
If nCnt Then
' Menu count is based on 0 (0, 1, 2, 3...)
RemoveMenu hSysMenu, nCnt - 1, _
MF_BYPOSITION Or MF_REMOVE
RemoveMenu hSysMenu, nCnt - 2, _
MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
DrawMenuBar hWnd
' Force caption bar's refresh. Disabling X button
'Me.Caption = "Try to close me!"
End If
End If
End Sub
Public Sub ShowTaskBar()
Attribute ShowTaskBar.VB_Description = "Toggle visible status of TaskBar."
Dim hWnd As Long
hWnd = FindWindow("Shell_traywnd", "")
If m_vShow Then
'if TaskBar.Show=true it shows the TaskBar
Call ShowWindow(hWnd, 0)
m_vShow = False
Else
'if not it hides the TaskBar
Call ShowWindow(hWnd, 1)
m_vShow = True
End If
End Sub
Public Sub LockToggle(ByVal ToglKey As LockKeys, _
Optional ByVal State As OnOff)
Attribute LockToggle.VB_Description = "Toggle lock key status: Num, Caps, and Scroll. Use optional State value to force key into on or off position."
GetKeyboardState kbArray
Select Case State
Case 0
kbArray.kbByte(ToglKey) = _
IIf(kbArray.kbByte(ToglKey) = 1, 0, 1)
Case [Turn On]
kbArray.kbByte(ToglKey) = 1
Case [Turn Off]
kbArray.kbByte(ToglKey) = 0
End Select
SetKeyboardState kbArray
End Sub
Public Function IsWindow(ByVal hWnd As Long) As Boolean
Attribute IsWindow.VB_Description = "Returns boolean (True or False) indicating whether the specified window handle identifies an existing window."
Dim lngX As Long
lngX = IsThisWindow(hWnd)
If lngX = 0 Then
IsWindow = False
Else
IsWindow = True
End If
End Function
Public Function GetWindowText(ByVal hWnd As Long) As String
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! "
Dim Buffer As String
Dim lngX As Long
Dim lngN As Long
' Create a string of n+1 to receive the title (to allow for the ending vbNullChar
lngN = GetWindowTextLength(hWnd) + 1
Buffer = Space(lngN)
' Read the title
lngX = GetWinText(hWnd, Buffer, lngN)
GetWindowText = Left(Buffer, lngX) ' drop the vbNullChar
End Function
Public Function GetNextWindow(ByVal hWnd As Long, Relation As GetWindow) As Long
GetNextWindow = GetWin(hWnd, iRelation) ' next window in Z-order