begin process at 2012 02 16 10:42:11
  Trouver un code source :
 
dans
 
Accueil > Forum > 

VB.NET et VB 2005

 > 

Algorithme

 > 

Divers

 > 

hook souris dans Word URGENT


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

hook souris dans Word URGENT

lundi 2 juin 2008 à 15:00:13 | hook souris dans Word URGENT

sylvain230

Bonjour. Je n'arrive pas à installer un hook dans Word

J'ai toujours l'erreur suivante
" Tentative de lecture ou d'écriture de mémoire protégée. Cela indique souvent qu'une autre mémoire est endommagée."
Si quelqu'un sait ca serai cool de me dire :)
Merci d'avance . C'est assez urgent !


Voici mon code :



Imports System.Drawing
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.ComponentModel


'************************************************
'MODULE SECTION
'************************************************
Public Module mod1
    'declare delegate object
    Delegate Function HookCallback(ByVal Code As Integer, ByVal wParam As Integer, _
      ByVal lParam As Integer) As Integer

    'declare API's
    Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
      (ByVal HookID As Integer, ByVal lpfn As HookCallback, ByVal hModule As Integer, _
      ByVal ThreadId As Integer) As Integer
    Public Declare Function UnhookWindowsHookEx Lib "user32" Alias "UnhookWindowsHookEx" _
      (ByVal hHook As Integer) As Integer
    Public Declare Function CallNextHookEx Lib "user32" Alias "CallNextHookEx" _
      (ByVal hHook As Integer, ByVal Code As Integer, ByVal wParam As Integer, _
      ByVal lParam As Integer) As Integer
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
      (ByRef Destination As mod1.MOUSEHOOKSTRUCT, ByVal Source As Integer, _
      ByVal Length As Integer)
    'declare API's
    Public Declare Function getThreadID Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Integer, ByVal lpdwProcessId As Integer) As Integer
    Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
    'Global constants
    Public Const WH_MOUSE As Integer = 7

    Public Structure POINTAPI
        Public x As Integer
        Public y As Integer
    End Structure

   Public Structure MOUSEHOOKSTRUCT
        Public pt As POINTAPI
        Public hwnd As Integer
        Public wHitTestCode As Integer
        Public dwExtraInfo As Integer
    End Structure

    Private m_hHook As Integer

    'Property to access hook handle
    Property hHook() As Integer
        Set
            If m_hHook <> 0 And Value <> 0 Then
                'Don't overwrite the handle
                '   Unless it is being reset to 0
            Else
                m_hHook = Value
            End If
        End Set

        Get
            hHook = m_hHook
        End Get
    End Property
End Module


'************************************************
'FORM SECTION
'************************************************
Public Class frmHook
    Inherits System.Windows.Forms.Form

    'declare nested class var
    Public hk As Hook

    'declare delegate object
    Public cb As HookCallback
   
   
    'START HERE - default ctor for Form1 class
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        'frmHook = Me
       
        'instantiate a new nested Hook class passing in a reference to this form
        hk = New Hook(Me)
       
        'instantiate a new delegate object pointing to the HookProc function
        '   in the nested class
        cb = New HookCallback(AddressOf hk.HookProc)
    End Sub
   
   
    '************************************************
    'NESTED CLASS-containing the callback HookProc
    '************************************************
    Public Class Hook
        'reference back to the form
        Private TheWin As frmHook
       
        'ctor - used to get a reference to the main window
        '       in order to write info to the textbox1 text box
        Public Sub New(ByVal MainWnd As frmHook)
            TheWin = MainWnd
        End Sub
       
        'HOOK PROC
        Public Function HookProc(ByVal Code As Integer, ByVal wParam As Integer, _
          ByVal lParam As Integer) As Integer
            Dim Dest As New mod1.MOUSEHOOKSTRUCT()
           
            CopyMemory(Dest, lParam, Len(Dest))
            TheWin.PrintTxt(Dest.hwnd & " : " & Dest.pt.x & " : " & Dest.pt.y & _
              " : " & Dest.wHitTestCode)
           
            HookProc = CallNextHookEx(hHook, Code, wParam, lParam)
        End Function
    End Class
   
   
    'used by Form1 to add text to the textbox1 text box, called by HookProc
    Public Sub PrintTxt(ByVal ip As String)
        textBox1.Text = TextBox1.Text & ip & chr(13) & chr(10)
    End Sub
   
   
    '************************************************
    'REGULAR WINDOWS .NET STUFF
    '************************************************
#Region " Windows Form Designer generated code "
   
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container
    Private WithEvents Button2 As System.Windows.Forms.Button
    Private WithEvents Button1 As System.Windows.Forms.Button
    Private WithEvents TextBox1 As System.Windows.Forms.TextBox
   
    Dim WithEvents Hook_Try2 As System.Windows.Forms.Form
   
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Private Sub InitializeComponent()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(8, 40)
        Me.Button2.Name = "Button2"
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "UnHook"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(88, 0)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.TextBox1.Size = New System.Drawing.Size(448, 620)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = ""
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(8, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Hook"
        '
        'frmHook
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(536, 617)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.Button1, Me.TextBox1})
        Me.Name = "frmHook"
        Me.Text = "VB.NET Hooking Example"
        Me.ResumeLayout(False)

    End Sub

#End Region
   
    'Form overrides dispose to clean up the component list.
    Public Overloads Sub Dispose()
        MyBase.Dispose()
        components.Dispose()
    End Sub

    '************************************************
    'EVENT HANDLERS FOR BUTTON CONTROLS
    '************************************************
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Install hook

        Dim Word_hwnd As Integer = FindWindow(vbNullString, "Document3 - Microsoft Word")
        Dim numID As Integer
        Dim NumThread As Integer = GetWindowThreadProcessId(Word_hwnd, numID)
        'hHook = SetWindowsHookEx(WH_MOUSE, cb, 0, AppDomain.GetCurrentThreadId)
        hHook = SetWindowsHookEx(WH_MOUSE, cb, 0, getThreadID(Word_hwnd, NumThread))
        MsgBox(hHook)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'Release hook
        MsgBox(UnhookWindowsHookEx(hHook))
        hHook = 0
    End Sub
End Class



Cette discussion est classée dans : public, windows, system, integer, byval


Répondre à ce message

Sujets en rapport avec ce message

Label [ par bruno067 ] Bonjour, je debute avec Visual basic 2005 edition express, et je souhaite construire un tableau de label, 21 environ qui apparait sur une fenêtre Form passer un pointeur null en parametre [ par mmattler ] Bonjour à tous, Je suis en train de developper une application en vb.net qui utilise les api du stockage amovible (ntmsapi.dll). pour une enumerati definir un Array comme parametre dans une sub [ par ravachol ] bonjour,je voudrais faire ça :Public Sub SVG(Image_fond As String, chemVid2(12) As String, ByVal nbbouton As Integer, ByVal nbobjet As Integer)mais il VoiceInsert [ par Jav1man ] J'ai un prolème avec ce code, y a t-il un samaritin dans le coin voici le codeCode Vb.netImports VoiceInsert.ComputerFeaturesImports VoiceInser Calcule du temps total d'utilisation [ par aldrac ] Bonjour a tous, j'ai crée une petite application qui se lance au démarrage dewindows,et je chercher un moyen de calculer le temps total d'utilisation, les marges pour une impression ne fonctionne pas [ par alexandreillusion ] je cherche à imprimer une form en paysage ce que j'arrive a faire. en revanche je ne reussi pas centrer sur la page cette form. pourriez vous m'aider enumForms echoue à chaque fois [ par boulacmoi ] Bonjour bonjour,Je suis actuellement en train de faire un petit programme pour me permettre d'imprimer des fichiers en masses dans des formats de papi Probleme de modification paramètrage imprimante [ par morgan77 ] Bonjour à tous Je cherche à modifier la configuration des bac pour une imprimante. Actuellement j'arrivé à afficher la fenêtre des bac mais les opti [VB2008] Afficher ce que j'écoute dans MSN [ par Vince300 ] Bonjour Voilà, j'essaye de faire afficher "Ce que j'écoute" dans msn messenger (juste en dessous du message perso). J'utilise ce code : [code=vb] Imp [VB.NET] "Commander" la création d'un bouton [ par Gsmaniak ] Bonjour, J'ai visual studio 2008 , j'ai deux forms , une qui permet de entrer les attributs (nom , tailles , hauteur/largeur etc..." d'un bouton , po


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 4,009 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales