常用的一组API操作

来源:互联网 发布:h3c将端口划分vlan 编辑:程序博客网 时间:2024/05/16 13:03

常用的一组API操作  
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long

Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Public Type POINTAPI
        x As Long
        y As Long
End Type

Public Const SW_HIDE = 0
Public Const SW_SHOW = 5
Private Const sy = "Shell_Traywnd"  '任务栏
Private Const bu = "Button" '开始按钮
Private Const pr = "Progman" '桌面
Private Const desk = "ShellDll_Defview"
Private wnd As Long
Public Sub Hideyi() '隐藏任务栏
  wnd = FindWindow(sy, vbNullString)
  ShowWindow wnd, SW_HIDE
End Sub
Public Sub Showyi() '显示任务栏
  wnd = FindWindow(sy, vbNullString)
  If wnd <> 0 Then ShowWindow wnd, SW_SHOW
End Sub
Public Sub Hidegs() '隐藏开始按钮
  wnd = FindWindow(sy, vbNullString) '先是查找任务栏.即顶级窗口
  wnd = FindWindowEx(wnd, 0, bu, vbNullString) '后查找子窗口
  If wnd <> 0 Then ShowWindow wnd, SW_HIDE
End Sub
Public Sub Showgs() '显示开始按钮
  wnd = FindWindow(sy, vbNullString)
  wnd = FindWindowEx(wnd, 0, bu, vbNullString)
  If wnd <> 0 Then ShowWindow wnd, SW_SHOW
End Sub
Public Sub Hidezm() '隐藏桌面
  wnd = FindWindow(pr, vbNullString)
  wnd = FindWindowEx(wnd, 0, desk, vbNullString)
  If wnd <> 0 Then ShowWindow wnd, SW_HIDE
End Sub
Public Sub Showzm()
  wnd = FindWindow(pr, vbNullString) '显示桌面
  wnd = FindWindowEx(wnd, 0, desk, vbNullString)
  If wnd <> 0 Then ShowWindow wnd, SW_SHOW
End Sub
Public Sub Ghmouse(ByVal ctlHwnd As Long) 'ctlHwnd可以传一个控件或窗体
 On Error GoTo a:
   Dim rectcotr As RECT
   Dim rest As Long
   GetWindowRect ctlHwnd, rectcotr '取得这个控件的范围矩形
   rectcotr.Left = rectcotr.Left
   rectcotr.Right = rectcotr.Right
   rectcotr.Top = rectcotr.Top
   rectcotr.Bottom = rectcotr.Bottom
  
   '设定鼠标的范围
   SetCursorPos (rectcotr.Left + rectcotr.Top) / 2, (rectcotr.Bottom + rectcotr.Right) / 2
   rest = ClipCursor(rectcotr) '限定鼠标在一个区域
   Exit Sub
a:
   MsgBox Err.Description
End Sub

Public Sub Shmouse() '恢复鼠标的范围
   Dim recscreen As RECT
   Dim rest As Long
   recscreen.Top = 0
   recscreen.Left = 0
   recscreen.Right = Screen.Width / Screen.TwipsPerPixelX
   recscreen.Bottom = Screen.Height / Screen.TwipsPerPixelY
   ClipCursor recscreen
End Sub