怎样控制form显示时任务栏不隐藏,并且点WIN键后开始菜单和任务栏也不弹出!
现在想把FORM做成全屏显示,在画面运行过程中,不允许进行其他操作。
现在任务栏不显示好实现,可在画面运行当中点WIN键后,开始菜单和任务栏会弹出,怎么样能解决这个问题?
大家帮帮忙,谢谢!
[解决办法]
发核心代码给你
Imports System.Runtime.InteropServices
Imports System.Reflection
Public Class SysHook
Public Sub New()
StartHook()
End Sub
Protected Overrides Sub Finalize()
StopHook()
End Sub
#Region "Define parameters "
Private Declare Function SetWindowsHookEx Lib "user32 " Alias "SetWindowsHookExA " (ByVal idHook As Integer, ByVal lpfn As HookProc, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
Private Declare Function CallNextHookEx Lib "user32 " Alias "CallNextHookEx " (ByVal idHook As Integer, ByVal ncode As Integer, ByVal wParam As Int32, ByVal lParam As IntPtr) As Integer
Private Declare Function UnhookWindowsHookEx Lib "user32 " Alias "UnhookWindowsHookEx " (ByVal idHook As Integer) As Boolean
Private Declare Function GetKeyboardState Lib "user32 " Alias "GetKeyboardState " (ByVal pbKeyState As Byte) As Integer
Private Declare Function GetKeyState Lib "user32 " Alias "GetKeyState " (ByVal nVirtKey As Integer) As Integer
Public Delegate Function HookProc(ByVal nCode As Integer, ByVal wParam As Int32, ByVal lParam As IntPtr) As Integer
Public Event OnMouseActivity As MouseEventHandler
Public Event KeyDown As KeyEventHandler
Public Event KeyPress As KeyPressEventHandler
Public Event KeyUp As KeyEventHandler
Dim hMouseHook As Integer = 0 '//Declare mouse hook handle as int.
Dim hKeyboardHook As Integer = 0 '//Declare keyboard hook handle as int.
Public Const WH_MOUSE_LL As Integer = 14 '//mouse hook constant
Public Const WH_KEYBOARD_LL As Integer = 13 '//keyboard hook constant
Private Const WM_MOUSEMOVE As Integer = &H200 'Convert.ToInt32( "0x200 ", 16)
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_RBUTTONDOWN As Integer = &H204
Private Const WM_MBUTTONDOWN As Integer = &H207
Private Const WM_LBUTTONUP As Integer = &H202
Private Const WM_RBUTTONUP As Integer = &H205
Private Const WM_MBUTTONUP As Integer = &H208
Private Const WM_LBUTTONDBLCLK As Integer = &H203
Private Const WM_RBUTTONDBLCLK As Integer = &H206
Private Const WM_MBUTTONDBLCLK As Integer = &H209
Public MouseHookProcedure As HookProc
Public KeyboardHookProcedure As HookProc
Public Structure Point
Public x As Integer
Public y As Integer
End Structure
Public Structure MouseHookStruct
Public pt As Point
Public hwnd As Integer
Public wHitTestCode As Integer
Public dwExtraInfo As Integer
End Structure
Public Structure KeyboardHookStruct
Public vkCode As Integer '//Specifies a virtual-key code. The code must be a value in the range 1 to 254.
Public scanCode As Integer '// Specifies a hardware scan code for the key.
Public flags As Integer '// Specifies the extended-key flag, event-injected flag, context code, and transition-state flag.
Public time As Integer '// Specifies the time stamp for this message.
Public dwExtraInfo As Integer '// Specifies extra information associated with the message.
End Structure
#End Region
Public Sub StartHook()
'// install Mouse hook
If (hMouseHook = 0) Then
'// Create an instance of HookProc.
MouseHookProcedure = New HookProc(AddressOf MouseHookProc)
hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()(0)).ToInt32, 0)
'//If SetWindowsHookEx fails.
If (hMouseHook = 0) Then
StopHook()
End If
End If
'// install Keyboard hook
If (hKeyboardHook = 0) Then
KeyboardHookProcedure = New HookProc(AddressOf KeyboardHookProc)
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()(0)).ToInt32, 0)
'//If SetWindowsHookEx fails.
If (hKeyboardHook = 0) Then
StopHook()
End If
End If
End Sub
Public Sub StopHook()
Dim retMouse As Boolean = True
Dim retKeyboard As Boolean = True
If hMouseHook <> 0 Then
retMouse = UnhookWindowsHookEx(hMouseHook)
hMouseHook = 0
End If
If hKeyboardHook <> 0 Then
retKeyboard = UnhookWindowsHookEx(hKeyboardHook)
hKeyboardHook = 0
End If
'//If UnhookWindowsHookEx fails.
If Not (retMouse And retKeyboard) Then
Throw New Exception( "UnhookWindowsHookEx failed. ")
End If
End Sub