rivierem
Messages postés25Date d'inscriptionjeudi 26 décembre 2002StatutMembreDernière intervention12 avril 2006
-
14 mars 2003 à 16:14
forrestier2003
Messages postés11Date d'inscriptionjeudi 9 février 2006StatutMembreDernière intervention 1 mars 2006
-
12 mai 2006 à 12:03
Comment faire pour supprimer le menu contextuel de Windows sur un clic droit!!
Car mon menu appaarit apres deux clic droit??
Je voudrais que seul le mien apparaissent
Merci d'avance
fredlynx
Messages postés662Date d'inscriptionmercredi 16 janvier 2002StatutModérateurDernière intervention16 octobre 20103 14 mars 2003 à 19:14
Oula tout un programme ...
Pour un composante TextBox ...
Dans Ta Form :
Private Sub Form_Load()
Hook Text1.Hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unhook
End Sub
Private Sub TextBox_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
PopupMenu TonMenuAToi
End Sub
Dans un Module.bas
Option Explicit
Private 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
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal Hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = -4
Public Const WM_RBUTTONUP As Long = &H205
Private LngPrevWndProc As Long
Private IsHooked As Boolean
Private HookedHWND As Long
Public Sub Hook(Hwnd As Long)
'Mise en place du hook s'il n'est pas déjà actif
If IsHooked = False Then
HookedHWND = Hwnd
LngPrevWndProc = SetWindowLong(HookedHWND, GWL_WNDPROC, AddressOf WindowProc)
IsHooked = True
End If
End Sub
Public Sub Unhook()
'Suppression du hook s'il est actif
Dim LngTemp As Long
If IsHooked = True Then
LngTemp = SetWindowLong(HookedHWND, GWL_WNDPROC, LngPrevWndProc)
IsHooked = False
End If
End Sub
Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg
Case WM_RBUTTONUP
Case Else
WindowProc = CallWindowProc(LngPrevWndProc, hw, uMsg, wParam, lParam)
End Select
End Function
fredlynx
Messages postés662Date d'inscriptionmercredi 16 janvier 2002StatutModérateurDernière intervention16 octobre 20103 18 mars 2003 à 08:36
Private Sub TextBox_MouseUp(Button As Integer, Shift As
Integer, X As Single, Y As Single)
If Button = vbRightButton Then
PopupMenu TonMenuAToi
End If
End Sub
oliviervillemain
Messages postés4Date d'inscriptionmercredi 24 septembre 2003StatutMembreDernière intervention25 août 2005 25 août 2005 à 22:18
Tout le mérite revient à 3073 fredlynx, mais voici une petite amélioration possible : plutôt que d'intercepter le "MouseUp", il est préférable d'intercepter le "MouseDown". Ainsi le menu contextuel standard n'apparaît pas et l'événement VB "MouseUp" fonctionne pour faire apparaître son propre menu.
Pour cela ajouter dans le module :
Public Const WM_RBUTTONDOWN As Long = &H204
et remplacer dans la fonction WindowProc :
Case WM_RBUTTONUP
par
Case WM_RBUTTONDOWN
forrestier2003
Messages postés11Date d'inscriptionjeudi 9 février 2006StatutMembreDernière intervention 1 mars 2006 12 mai 2006 à 12:03
Bonjour,
Cette méthode marche très bien pour mes textboxes mais ne marche pas pour les DBGrids. Curieusement si on veut déplacer la form qui contient le DBGrid on obtient : Visual Basic a rencontré un problème et doit fermer.
Supprimer le
Hook (DBGrid1.Hwnd)
corrige le problème. J'ai bien mon menu contextuel qui s'affiche mais après le menu contextuel de Windows apparaît.
Quelqu'un a-t-il une méthode pour corriger ce problème ?