|
-
Feb 8th, 2002, 07:32 AM
#1
Thread Starter
Member
For the experts...( WOT NO MOUSE EVENTS !!)
Anybody aware of a way to drag text from the text field of a combo box to a standard text box, considering the combobox has no mousedown event to signify the start of the operation ?
-
Feb 8th, 2002, 07:38 AM
#2
The easy solution would be to code the combo's click event to pop the desired entry over to the textbox. You can simulate mouse events in a combo box, but it requires subclassing and a whole lotta code.
-
Feb 8th, 2002, 07:38 AM
#3
Retired VBF Adm1nistrator
Use the mouse_event API ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 8th, 2002, 07:42 AM
#4
Here is some code by Serge to simulate the mouse_down event for a combo box.
VB Code:
'module code
Public g_lngOldWinProc As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public 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
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_STYLE = (-16)
Public Const GWL_WNDPROC = (-4)
Public Const WM_MBUTTONDOWN = &H207
Public Const WM_LBUTTONDOWN = &H201
Public m_ctlCombo As ComboBox
Public m_intOldX As Integer
Public m_intOldY As Integer
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim strMsg As String
Dim lngRet As Long
Dim pt As POINTAPI
Select Case msg
Case WM_LBUTTONDOWN
'memorize the position of X and Y
Call GetCursorPos(pt)
Call ScreenToClient(Form1.hwnd, pt)
m_intOldX = pt.x * Screen.TwipsPerPixelX
m_intOldY = pt.y * Screen.TwipsPerPixelY
m_ctlCombo.Drag vbBeginDrag
End Select
NewWindowProc = CallWindowProc(g_lngOldWinProc, hwnd, msg, wParam, lParam)
End Function
'Form Code
Private Sub Form_DragDrop(Source As Control, x As Single, y As Single)
If Source.Name = "Combo1" Then
Combo1.Top = Combo1.Top + (y - m_intOldY)
Combo1.Left = Combo1.Left + (x - m_intOldX)
End If
End Sub
Private Sub Form_Load()
Set m_ctlCombo = Combo1
g_lngOldWinProc = SetWindowLong(Combo1.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call SetWindowLong(Combo1.hwnd, GWL_WNDPROC, g_lngOldWinProc)
End Sub
'Simulate A MouseDown Event With A Combo Box
'Submitted By Serge 10/22/2001
-
Feb 8th, 2002, 07:44 AM
#5
Retired VBF Adm1nistrator
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 8th, 2002, 11:01 AM
#6
Retired VBF Adm1nistrator
Heh true
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|