经过师傅验收后,师傅给提了一系列的意见,其中有一个我觉得是很有必要的,就是给MSFlexGrid控件加滚轮的功能。
考虑到用户的问题,入果添加一个滚轮功能,可以让用户使用起来更加方便,更加节约时间。经过百度,终于找到了添加这个功能的方法。
1、在模块中写入下列的代码:
<strong><span style="font-size:24px;"><strong><span style="font-size:18px;">Option Explicit '以下为模块代码 '声明支持滚轮鼠标API--------------------------------- Public Const GWL_WNDPROC = (-4) Public Const WM_COMMAND = &H111 Public Const WM_MBUTTONDOWN = &H207 Public Const WM_MBUTTONUP = &H208 Public Const WM_MOUSEWHEEL = &H20A Public Oldwinproc As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public 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 Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long '声明支持滚轮鼠标API--------------------------------- Public Function FlexScroll(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long '支持滚轮的滚动 Select Case wMsg Case WM_MOUSEWHEEL Select Case wParam Case -7864320 '向下滚 SendKeys "{PGDN}" Case 7864320 '向上滚 SendKeys "{PGUP}" End Select End Select FlexScroll = CallWindowProc(Oldwinproc, hwnd, wMsg, wParam, lParam) End Function</span></strong></span></strong>
2、在需要调用这个功能的船体中添加代码:
'滚轮功能 Private Sub MSFlexGrid1_GotFocus() '控件得到焦点时调用此功能 Oldwinproc = GetWindowLong(Me.hwnd, GWL_WNDPROC) SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf FlexScroll End Sub Private Sub MSFlexGrid1_LostFocus() ' 控件失去焦点时停止调用此功能 SetWindowLong Me.hwnd, GWL_WNDPROC, Oldwinproc End Sub
</pre><p></p><pre>添加上这两部分代码后,就可以很顺利的使用滚轮了。