VB屏蔽热键的问题

zhihuei 2002-06-22 11:15:27
在VB中如何把CTRL+ALT+DEL的功能屏蔽掉
如果你知道 请告诉我 谢谢
...全文
82 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
blueer 2002-06-22
  • 打赏
  • 举报
回复
2K下,可以屏蔽ctrl+alt+del下出来的各个按钮(修改注册表键值),若想不响应它,得替换一个系统DLL,用于处理WINLOGON的
junwhj 2002-06-22
  • 打赏
  • 举报
回复
下面的方法只适用于Win9x
API:
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long

调用方法:
SystemParametersInfo 97, True, CStr(1), 1 '屏蔽
SystemParametersInfo 97, False, CStr(1), 1 '取消屏蔽
no_lost 2002-06-22
  • 打赏
  • 举报
回复
第二种:定义运行某个程序的热键  
  在DOS时代,我们常用拦截中断向量的方法来实现热键的功能。现在我们可以用RegisterHotKey这个API函数来定义热键。当热键注册过后,无论我们在哪个程序中按下这组热键,系统会把相关信息传递给等待接收这个信息的窗口,再由这个窗口来处理信息,完成指定功能。所以在接收信息的窗口中还要采用子分类的方法来处理,程序结束时用unRegisterHotKey来取消热键的定义。
  RegisterHotKey的参数结构如下:
  RegisterHotKey(ByVal hwnd As Long,//接收Hotkey的Window
  ByVal idHotKey as Long, // 热键的ID,范围从 0x0000 到 0xBFFF
  ByVal Modifiers As Long, // 定义alt shift control等的组合
  ByVal uVirtKey As Long // 低端的键值 )
  下面我们就来看看具体程序,这个程序的功能是无论在哪个程序中按下ALT-SHIFT-G就执行记事本程序:
   '以下程序放在模块中
  Option Explicit
  
  Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA”_
   (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA”_
   (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  Declare Function CallWindowProc Lib “user32” Alias “CallWindowProcA”_
   (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, _
   ByVal wParam As Long, ByVal lParam As Long) As Long
  Declare Function RegisterHotKey Lib “user32” (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
  Declare Function UnregisterHotKey Lib “user32” (ByVal hwnd As Long, ByVal id As Long) As Long
  
  Public Const WM_HOTKEY = &H312
  Public Const MOD_ALT = &H1
  Public Const MOD_CONTROL = &H2
  Public Const MOD_SHIFT = &H4
  Public Const GWL_WNDPROC = (-4)
  
  Public preWinProc As Long
  Public Modifiers As Long, uVirtKey As Long, idHotKey As Long
  
  Private Type taLong
   ll As Long
  End Type
  Private Type t2Int
   lWord As Integer
   hword As Integer
  End Type
   Public Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, _
  ByVal wParam As Long, ByVal lParam As Long) As Long
   If Msg = WM_HOTKEY Then
   If wParam = idHotKey Then
   Dim lp As taLong, i2 As t2Int
   lp.ll = lParam
   LSet i2 = lp
   If (i2.lWord = Modifiers) And i2.hword = uVirtKey Then
   Debug.Print “HotKey Shift-Alt-G Pressed ”
   Shell “notepad”, vbNormalFocus
   End If
   End If
   End If
   '如果不是热键信息则调用原来的程序
   wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
   End Function
  
  '以下程序放在窗体中
  Sub Form_Load()
   Dim ret As Long
   '记录原来的window程序地址
   preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
   '用自定义程序代替原来的window程序
   ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf wndproc)
   idHotKey = 1 'in the range &h0000 through &hBFFF
   Modifiers = MOD_ALT + MOD_SHIFT
   uVirtKey = vbKeyG
   '注册热键
   ret =RegisterHotKey(Me.hwnd, idHotKey, Modifiers, uVirtKey)
   End Sub
  
   Private Sub Form_Unload(Cancel As Integer)
   Dim ret As Long
   '取消Message的截取,使之送往原来的window程序
   ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, preWinProc)
   Call UnregisterHotKey(Me.hwnd, uVirtKey)
   End Sub
  怎么样,对热键的定义有所了解了吧?通过这两种方法我想可以满足程序中对热键的需求了,try it。
  

no_lost 2002-06-22
  • 打赏
  • 举报
回复
Option Explicit
  Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal_
   hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
   Const WM_SETHOTKEY = &H32
   Const HOTKEYF_SHIFT = &H1 ' shift键
   Const HOTKEYF_CONTROL = &H2 'ctrl键
   Const HOTKEYF_ALT = &H4 'alt键
   Const HOTKEYF_EXT = &H8 '附加键
  
  Private Type tInteger
   aint As Integer
  End Type
  Private Type t2Byte
   lByte As Byte
   hByte As Byte
  End Type
  Private ii As tInteger
  Private bb As t2Byte
  
  Private Sub Command1_Click()
  Dim wParam As Long, I As Long
  
  '设定ctl-shift-T为该window的hotkey
  bb.hByte = HOTKEYF_CONTROL Or HOTKEYF_SHIFT
  bb.lByte = vbKeyT
  LSet ii = bb
  
  wParam = CLng(ii.aint)
  I = SendMessage(Me.hwnd, WM_SETHOTKEY, wParam, 0)
  If I = 1 Then
   Debug.Print “Ctl-Shift-T为hotkey”
  Else
   If I = 2 Then
   Debug.Print “有其他Window也用Ctl-Shift-T作Hotkey”
   Else
   Debug.Print “指定失败”
   End If
  End If
  End Sub
  注: SendMessage()的传回值有以下的意义:
   -1 hotkey 设定不对
   0 hWnd的指定有错
   1 成功,并且没有其他window用相同的hotkey
   2 成功,但是有其他window使用相同的hotkey

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧