一下代码实现模拟自动隐藏,至于用注册表实现的,你可以用regmon跟踪一下系统 '=======================窗体============================= Private Sub Form_Load() '获得任务栏宽度 Dim R As RECT Dim screenHeight As Long GetWindowRect FindWindow("Shell_TrayWnd", vbNullString), R screenHeight = Screen.Height / Screen.TwipsPerPixelY taskHeight = R.Bottom - R.Top lHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf CallMouseHookProc, App.hInstance, 0) End SubPrivate Sub Form_Unload(Cancel As Integer) Dim hnd As Long hnd = FindWindow("Shell_traywnd", "") 'get the Window ShowWindow hnd, 5 UnhookWindowsHookEx lHook End Sub'========================模块============================ '模块 Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long) Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long Public Const WH_MOUSE_LL = 14'鼠标消息 Public Const WM_MOUSEMOVE = &H200 Public lHook As Long'鼠标信息 Public Type MOUSEMSGS x As Long 'x座标 y As Long 'y座标 a As Long b As Long time As Long 'Window运行时间 End Type'窗口信息 Public Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Public taskHeight As Long '查找任务栏的函数 Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function SetWindowPos Lib "user32" (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 Public Const SWP_HIDEWINDOW = &H80 Public Const SWP_SHOWWINDOW = &H40 Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) 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 Function CallMouseHookProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Static flag As Boolean Dim hnd As Long hnd = FindWindow("Shell_traywnd", "") 'get the Window Dim MouseMsg As MOUSEMSGS If wParam = WM_MOUSEMOVE Then CopyMemory MouseMsg, lParam, LenB(MouseMsg) If MouseMsg.y > Screen.Height / Screen.TwipsPerPixelY And flag = True Then ShowWindow hnd, 5 flag = False End If If MouseMsg.y < Screen.Height / Screen.TwipsPerPixelY - taskHeight And flag = False Then '我估计任务栏的宽度为(Screen.Height / 15) / 20,不是很标准,可自行调整 ShowWindow hnd, 0 flag = True End If End If If code <> 0 Then CallMouseHookProc = CallNextHookEx(0, code, wParam, lParam) End If End Function
Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function SetWindowPos Lib "user32" (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 LongPrivate Const SWP_NOMOVE = &H2 '忽略x,y Private Const SWP_NOSIZE = &H1 '忽略cx,cy Private Const SWP_HIDEWINDOW = &H80 '隐藏窗口 Private Const SWP_SHOWWINDOW = &H40 '显示窗口 Private Const HWND_NOTOPMOST = -2Dim Hwnds As Long Private Sub Command1_Click() 'show SetWindowPos Hwnds, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE End SubPrivate Sub Command2_Click() 'hide SetWindowPos Hwnds, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_HIDEWINDOW Or SWP_NOMOVE Or SWP_NOSIZE End SubPrivate Sub Form_Load() '找到任务栏的句柄 Hwnds = FindWindow("Shell_TrayWnd", vbNullString) End Sub
引用"Windows Script Host "(WScript) Dim reg As IWshRuntimeLibrary.WshShell Set reg = New IWshRuntimeLibrary.WshShell 然后就可以reg.regwrite方法写注册表 至于写哪里,我找不出来...
'=======================窗体=============================
Private Sub Form_Load()
'获得任务栏宽度
Dim R As RECT
Dim screenHeight As Long
GetWindowRect FindWindow("Shell_TrayWnd", vbNullString), R
screenHeight = Screen.Height / Screen.TwipsPerPixelY
taskHeight = R.Bottom - R.Top lHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf CallMouseHookProc, App.hInstance, 0)
End SubPrivate Sub Form_Unload(Cancel As Integer)
Dim hnd As Long
hnd = FindWindow("Shell_traywnd", "") 'get the Window
ShowWindow hnd, 5
UnhookWindowsHookEx lHook
End Sub'========================模块============================
'模块
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WH_MOUSE_LL = 14'鼠标消息
Public Const WM_MOUSEMOVE = &H200
Public lHook As Long'鼠标信息
Public Type MOUSEMSGS
x As Long 'x座标
y As Long 'y座标
a As Long
b As Long
time As Long 'Window运行时间
End Type'窗口信息
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public taskHeight As Long '查找任务栏的函数
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SetWindowPos Lib "user32" (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
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_SHOWWINDOW = &H40
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) 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 Function CallMouseHookProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Static flag As Boolean
Dim hnd As Long
hnd = FindWindow("Shell_traywnd", "") 'get the Window
Dim MouseMsg As MOUSEMSGS
If wParam = WM_MOUSEMOVE Then
CopyMemory MouseMsg, lParam, LenB(MouseMsg)
If MouseMsg.y > Screen.Height / Screen.TwipsPerPixelY And flag = True Then
ShowWindow hnd, 5
flag = False
End If If MouseMsg.y < Screen.Height / Screen.TwipsPerPixelY - taskHeight And flag = False Then '我估计任务栏的宽度为(Screen.Height / 15) / 20,不是很标准,可自行调整
ShowWindow hnd, 0
flag = True
End If
End If If code <> 0 Then
CallMouseHookProc = CallNextHookEx(0, code, wParam, lParam)
End If
End Function
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" (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 LongPrivate Const SWP_NOMOVE = &H2 '忽略x,y
Private Const SWP_NOSIZE = &H1 '忽略cx,cy
Private Const SWP_HIDEWINDOW = &H80 '隐藏窗口
Private Const SWP_SHOWWINDOW = &H40 '显示窗口
Private Const HWND_NOTOPMOST = -2Dim Hwnds As Long
Private Sub Command1_Click() 'show
SetWindowPos Hwnds, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End SubPrivate Sub Command2_Click() 'hide
SetWindowPos Hwnds, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_HIDEWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End SubPrivate Sub Form_Load()
'找到任务栏的句柄
Hwnds = FindWindow("Shell_TrayWnd", vbNullString)
End Sub
Dim reg As IWshRuntimeLibrary.WshShell
Set reg = New IWshRuntimeLibrary.WshShell
然后就可以reg.regwrite方法写注册表
至于写哪里,我找不出来...