微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

[VB.NET]怎样控制form显示时任务栏不隐藏,并且点WIN键后开始菜单和任务栏也不弹出!

怎样控制form显示时任务栏不隐藏,并且点WIN键后开始菜单和任务栏也不弹出! 现在想把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 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,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 __________________________________________________________________________ Private Function MouseHookProc(ByVal nCode As Integer,ByVal lParam As IntPtr) As Integer If (nCode > = 0) And (OnMouseActivityEvent IsNot nothing) Then Dim button As New MouseButtons button = MouseButtons.None Select Case wParam Case WM_LBUTTONDOWN //case WM_LBUTTONUP: //case WM_LBUTTONDBLCLK: button = MouseButtons.Left Case WM_RBUTTONDOWN //case WM_RBUTTONUP: //case WM_RBUTTONDBLCLK: button = MouseButtons.Right End Select Dim clickCount As Integer = 0 If (button <> MouseButtons.None) Then If (wParam = WM_LBUTTONDBLCLK Or wParam = WM_RBUTTONDBLCLK) Then clickCount = 2 Else clickCount = 1 End If End If //Marshall the data from callback. Dim MyMouseHookStruct As MouseHookStruct MyMouseHookStruct = Marshal.PtrToStructure(lParam,GetType(MouseHookStruct)) Dim e As MouseEventArgs e = New MouseEventArgs(button,clickCount,MyMouseHookStruct.pt.x,MyMouseHookStruct.pt.y,0) RaiseEvent OnMouseActivity(Me,e) Dim STPOS As Rectangle STPOS = GetStartPos() If (clickCount > 0) And (MyMouseHookStruct.pt.x > = STPOS.Left) And (MyMouseHookStruct.pt.x <= STPOS.Right) And (MyMouseHookStruct.pt.y > = STPOS.Top) And (MyMouseHookStruct.pt.y <= STPOS.Bottom) Then A0startmenu.Show() Return 1 Else If (clickCount > 0) And A0startmenu.Visible And ((MyMouseHookStruct.pt.x < A0startmenu.Left) Or (MyMouseHookStruct.pt.x > A0startmenu.Right) Or (MyMouseHookStruct.pt.y < A0startmenu.Top) Or (MyMouseHookStruct.pt.y > A0startmenu.Bottom)) Then A0startmenu.Hide() End If Return CallNextHookEx(hMouseHook,nCode,wParam,lParam) End If End If End Function #Region Define keyboard parameters Private Const WM_KEYDOWN As Integer = &H100 0x100 Private Const WM_KEYUP As Integer = &H101 Private Const WM_SYSKEYDOWN As Integer = &H104 Private Const WM_SYSKEYUP As Integer = &H105 #End Region Private Function KeyboardHookProc(ByVal nCode As Integer,ByVal lParam As IntPtr) As Integer Dim brk As Boolean If ((nCode > = 0) And (KeyDownEvent IsNot nothing Or KeyUpEvent IsNot nothing Or KeyPressEvent IsNot nothing)) Then Dim MyKeyboardHookStruct As KeyboardHookStruct MyKeyboardHookStruct = Marshal.PtrToStructure(lParam,GetType(KeyboardHookStruct)) // raise KeyDown If (KeyDownEvent IsNot nothing And (wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN)) Then Dim keyData As Keys keyData = MyKeyboardHookStruct.vkCode Dim e As KeyEventArgs e = New KeyEventArgs(keyData) RaiseEvent KeyDown(Me,e) break the keys -- Win If (e.KeyData = Keys.LWin) Or (e.KeyData = Keys.RWin) Then A0startmenu.Show() brk = True End If Ctrl+Esc & Alt + Esc If e.KeyData = Keys.Escape And (My.Computer.Keyboard.CtrlKeyDown Or My.Computer.Keyboard.AltKeyDown) Then A0startmenu.Show() brk = True End If If (e.KeyData = Keys.Escape And Not (My.Computer.Keyboard.CtrlKeyDown Or _ My.Computer.Keyboard.AltKeyDown Or (My.Computer.Keyboard.ShiftKeyDown AndAlso _ My.Computer.Keyboard.CtrlKeyDown))) And A0startmenu.Focused Then A0startmenu.Hide() End If Ctrl+Shift+Esc If (e.KeyData = Keys.Escape) AndAlso My.Computer.Keyboard.ShiftKeyDown AndAlso My.Computer.Keyboard.CtrlKeyDown Then A0startmenu.Show() brk = True End If End If // raise KeyPress If (KeyPressEvent IsNot nothing And wParam = WM_KEYDOWN) Then Dim keyState As Byte GetKeyboardState(keyState) Dim inBuffer As Byte If (ToAscii(MyKeyboardHookStruct.vkCode,MyKeyboardHookStruct.scanCode,keyState,inBuffer,MyKeyboardHookStruct.flags) = 1) Then Dim e1 As KeyPressEventArgs e1 = New KeyPressEventArgs(CChar(CStr(inBuffer))) RaiseEvent KeyPress(Me,e1) End If End If // raise KeyUp If (KeyUpEvent IsNot nothing And (wParam = WM_KEYUP Or wParam = WM_SYSKEYUP)) Then Dim keyData As Keys keyData = MyKeyboardHookStruct.vkCode Dim e2 As KeyEventArgs e2 = New KeyEventArgs(keyData) RaiseEvent KeyUp(Me,e2) End If End If If brk Then Return 1 Else Return CallNextHookEx(hKeyboardHook,lParam) End If End Function End Class __________________________________________________________________________

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐