Autor Tema: Mouse en el IDE  (Leído 2649 veces)

0 Usuarios y 1 Visitante están viendo este tema.

cobein

  • Moderador Global
  • Gigabyte
  • *****
  • Mensajes: 348
  • Reputación: +63/-0
  • Más Argentino que el morcipan
    • Ver Perfil
Mouse en el IDE
« en: Octubre 23, 2010, 08:43:27 pm »
una pregunta, que uso en winblows 7 para tener scroll en el IDE? porque el viejo parche de M$ que esta para descargar de la seccion utilidades no me anda por "problemas de compatibilidad", el driver que usaba me esta crasheando el sistema y el otro que tenia ... ni se donde lo puse. Alguna solucion ? si es sin drivers mejor.

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
Re:Mouse en el IDE
« Respuesta #1 en: Octubre 24, 2010, 10:35:09 am »
Hola, fijate puede que te sirva para hacer un adding, hasta donde probe funciona en las dos ventana de codigo y el debug.

Código: [Seleccionar]
Option Explicit
'Autor: Leandro Ascierto
'Web: www.leandroacierto.com.ar
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function WindowFromPoint Lib "user32.dll" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Private Declare Function SystemParametersInfo Lib "user32.dll" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Integer, lParam As Any) As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long

Private Const SPI_GETWHEELSCROLLLINES As Long = 104
Private Const GW_CHILD          As Long = 5
Private Const GW_HWNDNEXT       As Long = 2
Private Const WM_KEYDOWN        As Long = &H100
Private Const WM_KEYUP          As Long = &H101
Private Const WM_MOUSEWHEEL     As Long = &H20A
Private Const WH_GETMESSAGE     As Long = &H3

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Type POINTAPI
     X As Long
     Y As Long
End Type
       
Private Type MSG
     hwnd As Long
     message As Long
     wParam As Long
     lParam As Long
     time As Long
     PT As POINTAPI
End Type

Private IMWHEEL_MSG As Long
Private hHook As Long


Private WheelScrollLines    As Long

Public Function InstalIDEWheel() As Boolean
    Call SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, WheelScrollLines, 0)
    hHook = SetWindowsHookEx(WH_GETMESSAGE, AddressOf Hook_Proc, 0, App.ThreadID)
End Function

Public Function UnInstalIDEWheel()
    UnhookWindowsHookEx hHook
End Function

Function Hook_Proc(ByVal nCode As Long, ByVal wParam As Long, lParam As MSG) As Long
    Dim hWin As Long
    Dim hScroll As Long
    Dim i As Long

    If lParam.message = WM_MOUSEWHEEL Then
       
        hWin = WindowFromPoint(lParam.PT.X, lParam.PT.Y)
               
        If ClassNameOf(hWin) = "VbaWindow" Then
       
            hScroll = FindScroll(hWin, lParam.PT.Y)
         
             If hScroll Then
           
                 For i = 1 To WheelScrollLines
                     If lParam.wParam > 0 Then
                         Call SendMessageLong(hScroll, WM_KEYDOWN, 38, 0)
                         Call SendMessageLong(hScroll, WM_KEYUP, 38, 0)
                     Else
                         Call SendMessageLong(hScroll, WM_KEYDOWN, 40, 0)
                         Call SendMessageLong(hScroll, WM_KEYUP, 40, 0)
                     End If
                 Next
             
             End If
         
        End If

    End If
   
    Hook_Proc = CallNextHookEx(hHook, nCode, wParam, lParam)

End Function


Private Function FindScroll(ByVal hParent As Long, MousePosY As Long) As Long
    Dim hChild As Long
    Dim hDirectUIHWND As Long
    Dim Rec As RECT

    hChild = GetWindow(hParent, GW_CHILD)
   
    Do While hChild
        If ClassNameOf(hChild) = "ScrollBar" Then
            GetWindowRect hChild, Rec
            If MousePosY > Rec.Top And MousePosY < Rec.Bottom Then
                FindScroll = hChild
                Exit Do
            End If
        End If
        hChild = GetWindow(hChild, GW_HWNDNEXT)
    Loop

End Function

 Private Function ClassNameOf(ByVal hwnd As Long) As String
    Dim sClassName As String, Ret As Long
    sClassName = String(256, Chr$(0))
    Ret = GetClassName(hwnd, sClassName, 256)
    If Ret Then ClassNameOf = Left$(sClassName, Ret)
 End Function

Saludos.

cobein

  • Moderador Global
  • Gigabyte
  • *****
  • Mensajes: 348
  • Reputación: +63/-0
  • Más Argentino que el morcipan
    • Ver Perfil
Re:Mouse en el IDE
« Respuesta #2 en: Octubre 24, 2010, 07:14:16 pm »
Gracias Leandro, lo voy a modificar un poco para cargarlo como un addin y listo, es mejor que utilizar los drivers del mouse que son un dolor de cabeza.