Results 1 to 6 of 6

Thread: For the experts...( WOT NO MOUSE EVENTS !!)

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Bath, England
    Posts
    45

    Question 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 ?
    SJRigby

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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.

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Use the mouse_event API ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Here is some code by Serge to simulate the mouse_down event for a combo box.
    VB Code:
    1. 'module code
    2. Public g_lngOldWinProc As Long
    3.  
    4. Private Type POINTAPI
    5. x As Long
    6. y As Long
    7. End Type
    8.  
    9. Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    10. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    11.  
    12. 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
    13. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    14. Public Const GWL_STYLE = (-16)
    15. Public Const GWL_WNDPROC = (-4)
    16. Public Const WM_MBUTTONDOWN = &H207
    17. Public Const WM_LBUTTONDOWN = &H201
    18. Public m_ctlCombo As ComboBox
    19.  
    20. Public m_intOldX As Integer
    21. Public m_intOldY As Integer
    22.  
    23. Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    24.  
    25.     Dim strMsg As String
    26.     Dim lngRet As Long
    27.     Dim pt As POINTAPI      
    28.  
    29.     Select Case msg
    30.  
    31.         Case WM_LBUTTONDOWN
    32.  
    33.             'memorize the position of X and Y
    34.  
    35.             Call GetCursorPos(pt)
    36.  
    37.             Call ScreenToClient(Form1.hwnd, pt)            
    38.  
    39.             m_intOldX = pt.x * Screen.TwipsPerPixelX
    40.  
    41.             m_intOldY = pt.y * Screen.TwipsPerPixelY      
    42.  
    43.             m_ctlCombo.Drag vbBeginDrag      
    44.  
    45.     End Select
    46.  
    47.     NewWindowProc = CallWindowProc(g_lngOldWinProc, hwnd, msg, wParam, lParam)
    48.  
    49. End Function
    50.  
    51. 'Form Code
    52.  
    53. Private Sub Form_DragDrop(Source As Control, x As Single, y As Single)
    54.     If Source.Name = "Combo1" Then
    55.         Combo1.Top = Combo1.Top + (y - m_intOldY)
    56.         Combo1.Left = Combo1.Left + (x - m_intOldX)
    57.     End If
    58. End Sub
    59.  
    60.  
    61. Private Sub Form_Load()
    62.     Set m_ctlCombo = Combo1
    63.     g_lngOldWinProc = SetWindowLong(Combo1.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
    64. End Sub
    65.  
    66. Private Sub Form_Unload(Cancel As Integer)
    67.     Call SetWindowLong(Combo1.hwnd, GWL_WNDPROC, g_lngOldWinProc)
    68. End Sub
    69. 'Simulate A MouseDown Event With A Combo Box
    70. 'Submitted By Serge 10/22/2001

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Handy code
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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
  •  



Click Here to Expand Forum to Full Width