SCROLL DO MOUSE EM FLEXGRID
Utilizo Visual Basic 6 e gostaria que o FlexGrid rolasse com o botão de rolagem (scroll) do mouse. Como fazer?
Uso este programinha..
Citação::
Uso este programinha..
Como usar?
O programa auxilia em objetos que tem a barra mas por algum motivo normalmente não funciona...
Caso queria programar o evento do scroll em alguma função tem este código que captura o movimento do scroll...
[ô]Num modulo
Option Explicit
Private Const WM_MOUSEWHEEL = &H20A [ô]-- Indica que a roda do mouse foi girada ...
Public Const GWL_WNDPROC = (-4) [ô]-- Indica o Ãndice de processamento ...
Public lProcJanOrig1 As Long [ô]-- Armazena o valor original de [lProcJan] (1) ...
Public lProcJanOrig2 As Long [ô]-- Armazena o valor original de [lProcJan] (2) ...
Private Declare Function apiExecProcJan 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 apiGrvIdentJan Lib [Ô]user32[Ô] Alias [Ô]SetWindowLongA[Ô] (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function apiLerIdentJan Lib [Ô]user32[Ô] Alias [Ô]GetWindowLongA[Ô] (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Function lProcJan1(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
[ô]-- Verifica se a roda do mouse foi girada ...
If (wMsg = WM_MOUSEWHEEL) Then
If (wParam > 0) Then
[ô]-- Roda do mouse girada para cima ...
Form1.GiroMouse 2
Else
[ô]-- Roda do mouse girada para baixo ...
Form1.GiroMouse 1
End If
End If
[ô]-- Define o identificador do processo ...
lProcJan1 = apiExecProcJan(lProcJanOrig1, hWnd, wMsg, wParam, lParam)
End Function
Caso queria programar o evento do scroll em alguma função tem este código que captura o movimento do scroll...
[ô]Num modulo
Option Explicit
Private Const WM_MOUSEWHEEL = &H20A [ô]-- Indica que a roda do mouse foi girada ...
Public Const GWL_WNDPROC = (-4) [ô]-- Indica o Ãndice de processamento ...
Public lProcJanOrig1 As Long [ô]-- Armazena o valor original de [lProcJan] (1) ...
Public lProcJanOrig2 As Long [ô]-- Armazena o valor original de [lProcJan] (2) ...
Private Declare Function apiExecProcJan 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 apiGrvIdentJan Lib [Ô]user32[Ô] Alias [Ô]SetWindowLongA[Ô] (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function apiLerIdentJan Lib [Ô]user32[Ô] Alias [Ô]GetWindowLongA[Ô] (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Function lProcJan1(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
[ô]-- Verifica se a roda do mouse foi girada ...
If (wMsg = WM_MOUSEWHEEL) Then
If (wParam > 0) Then
[ô]-- Roda do mouse girada para cima ...
Form1.GiroMouse 2
Else
[ô]-- Roda do mouse girada para baixo ...
Form1.GiroMouse 1
End If
End If
[ô]-- Define o identificador do processo ...
lProcJan1 = apiExecProcJan(lProcJanOrig1, hWnd, wMsg, wParam, lParam)
End Function
Olá!
Crie um Módulo com o nome que desejar...eu criei com o nome de [Ô]Mod_MouseWheel[Ô], para assim utilizar em todos os meus projetos;
Insira o código abaixo nele:
Para usar, basta chamar as Rotinas [Ô]WheelHook[Ô] (dentro do evento GotFocus do FlexGrid) e [ô][ô]WheelUnHook[Ô] (dentro do evento LostFocus do FlexGrid).
Tipo assim:
Valeu!
Crie um Módulo com o nome que desejar...eu criei com o nome de [Ô]Mod_MouseWheel[Ô], para assim utilizar em todos os meus projetos;
Insira o código abaixo nele:
Option Explicit
[ô][ô]// Inseri Mouse Whell Scroll no componente MSFlexGrid
[ô][ô] Através do Uso dos métodos:
[ô][ô] -- WheelHook (dentro do GotFocus)
[ô][ô] -- WheelUnHook (dentro do LostFocus)
[Ô] By Dannleonhart
Private Declare Function CallWindowProc Lib [Ô]user32.dll[Ô] Alias [Ô]CallWindowProcA[Ô] ( _
ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal Wparam As Long, _
ByVal Lparam As Long) As Long
Private Declare Function SetWindowLong Lib [Ô]user32.dll[Ô] Alias [Ô]SetWindowLongA[Ô] ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Const MK_CONTROL = &H8
Public Const MK_LBUTTON = &H1
Public Const MK_RBUTTON = &H2
Public Const MK_MBUTTON = &H10
Public Const MK_SHIFT = &H4
Private Const GWL_WNDPROC = -4
Private Const WM_MOUSEWHEEL = &H20A
Dim LocalHwnd As Long
Dim LocalPrevWndProc As Long
Dim MyForm As Form
Dim mGrid As MSFlexGrid
Private Function WindowProc(ByVal Lwnd As Long, ByVal Lmsg As Long, ByVal Wparam As Long, ByVal Lparam As Long) As Long
Dim MouseKeys As Long
Dim Rotation As Long
Dim Xpos As Long
Dim Ypos As Long
If Lmsg = WM_MOUSEWHEEL Then
MouseKeys = Wparam And 65535
Rotation = Wparam / 65536
Xpos = Lparam And 65535
Ypos = Lparam / 65536
[ô]MyForm.MouseWheel MouseKeys, Rotation, Xpos, Ypos
MouseWheel2 MouseKeys, Rotation, Xpos, Ypos
End If
WindowProc = CallWindowProc(LocalPrevWndProc, Lwnd, Lmsg, Wparam, Lparam)
End Function
Public Sub WheelHook(PassedForm As Form, lGrid As MSFlexGrid)
On Error Resume Next
Set mGrid = lGrid
Set MyForm = PassedForm
LocalHwnd = PassedForm.hWnd
LocalPrevWndProc = SetWindowLong(LocalHwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub WheelUnHook()
Dim WorkFlag As Long
On Error Resume Next
WorkFlag = SetWindowLong(LocalHwnd, GWL_WNDPROC, LocalPrevWndProc)
Set MyForm = Nothing
End Sub
Private Sub MouseWheel2(ByVal MouseKeys As Long, ByVal Rotation As Long, ByVal Xpos As Long, ByVal Ypos As Long)
Dim NewValue As Long
Dim Lstep As Single
On Error Resume Next
Dim lGrid As Control
For Each lGrid In MyForm.Controls
If TypeOf lGrid Is MSFlexGrid Then
If lGrid.Name = mGrid.Name Then
Exit For
End If
End If
Next
With lGrid
[ô] Lstep = .height / .RowHeight(0) / 4
[ô] Lstep = Int(Lstep)
[ô] If Lstep < 5 Then
[ô] Lstep = 5
[ô] End If
Lstep = 1
If Rotation > 0 Then
NewValue = .TopRow - Lstep
If NewValue < 1 Then
NewValue = 1
End If
Else
NewValue = .TopRow + Lstep
If NewValue > .Rows - 1 Then
NewValue = .Rows - 1
End If
End If
.TopRow = NewValue
End With
End Sub
Para usar, basta chamar as Rotinas [Ô]WheelHook[Ô] (dentro do evento GotFocus do FlexGrid) e [ô][ô]WheelUnHook[Ô] (dentro do evento LostFocus do FlexGrid).
Tipo assim:
Private Sub FlexGrid1_GotFocus()
WheelHook Me, FlexGrid1
End Sub
Private Sub FlexGrid1_LostFocus()
WheelUnHook
End Sub
Valeu!
Tópico encerrado , respostas não são mais permitidas