加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 23:42:43 所属栏目:大数据 来源:网络整理
导读:怎样控制form显示时任务栏不隐藏,并且点WIN键后开始菜单和任务栏也不弹出! 现在想把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 __________________________________________________________________________

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读