PDA

Click to See Complete Forum and Search --> : VB - Display Right Click Menu From Command Button Click


RobDog888
Jan 3rd, 2005, 11:55 PM
This is how to send a right click to a textbox from another controls event.
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101

Private Const WM_RBUTTONDOWN As Long = &H204
Private Const WM_RBUTTONUP As Long = &H205
Private Const MK_RBUTTON As Long = &H2

Private Sub Command1_Click()
Dim DaWord As Long
DaWord = MakeDWord((Text1.Width / 15) / 2, (Text1.Height / 15) / 2) 'Centers the click and 15 is twips per pixel
SendMessage Text1.hwnd, WM_RBUTTONDOWN, 2&, ByVal DaWord
SendMessage Text1.hwnd, WM_RBUTTONUP, 2&, ByVal DaWord
End Sub

Private Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function