| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 870 人关注过本帖
标题:VB6热键代码到了VB2005不能运行,望指教!
只看楼主 加入收藏
nhhykly9d
Rank: 1
等 级:新手上路
帖 子:30
专家分:5
注 册:2008-1-4
收藏
 问题点数:0 回复次数:3 
VB6热键代码到了VB2005不能运行,望指教!
 以下是VB6的热键代码,在各大小网站无不是沿用此代码。从VB2005出现后网上没查见过用VB2005同样实现的代码。望高人写一个VB2005实现的代码,方便我等初学者。难道VB2005没多少人使用了吗?


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
   preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
   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
   ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, preWinProc)
   Call UnregisterHotKey(Me.hwnd, uVirtKey)
   End Sub

[[italic] 本帖最后由 nhhykly9d 于 2008-1-17 16:44 编辑 [/italic]]
搜索更多相关主题的帖子: 热键 代码 指教 运行 
2008-01-14 15:34
luodachao
Rank: 1
等 级:新手上路
帖 子:116
专家分:0
注 册:2007-10-26
收藏
得分:0 
VB5和VB6都有个一个运行支持库的呀!
2008-01-17 14:16
nhhykly9d
Rank: 1
等 级:新手上路
帖 子:30
专家分:5
注 册:2008-1-4
收藏
得分:0 
本题目前还没解决,望高人出现
VB2005中,AddressOf  使用有别于VB6,报错;
第二,在
lp.ll = lParam
LSet i2 = lp    语句中,LSet不能这样使用了。
这个是委托实现的例子,对初学者太难,望高人重写代码让我们学习
2008-01-17 16:43
nhhykly9d
Rank: 1
等 级:新手上路
帖 子:30
专家分:5
注 册:2008-1-4
收藏
得分:0 
没有解决啊
没有解决啊,高人快出来呀
2008-01-24 10:12
快速回复:VB6热键代码到了VB2005不能运行,望指教!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019306 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved