CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 1999
    Location
    Quebec, Canada
    Posts
    13

    Subclassing ComboBox

    Hello,

    I'm trying to subclass the ComboBox control so that I can process WM_MOUSEMOVE message. It seems that the WM_MOUSEMOVE messages are only sent to the child TextBox inside the combo, so I need to do FindWindowEx() first to get the handle.

    I am getting a strange bug. If I subclass the combo box, it works fine. If I subclass the child text box, VB seems to get in an infinite loop and crash very fast (invalid page fault).

    If anyone has any solution or any alternatives to getting mouse movement info for this control let me know.

    Best regards,
    Gabriel


  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Subclassing ComboBox

    Why do you want to Trap the WM_MOUSEMOVE Message? To Get the ListItem as it's selected?

    Try this:'In a Module..
    private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (byval hwnd as Long, byval nIndex as Long, byval dwNewLong as Long) as Long
    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 SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, lParam as Any) as Long

    private Const GWL_WNDPROC = (-4)
    private Const WM_CTLCOLORLISTBOX = &H134
    private Const LB_GETCURSEL = &H188

    private lPrevWndFunc as Long
    public oLabel as Label

    private Function WindowProc(byval hwnd as Long, byval Msg as Long, byval wParam as Long, byval lParam as Long) as Long
    Dim iIndex as Long

    If Msg = WM_CTLCOLORLISTBOX then
    iIndex = SendMessage(lParam, LB_GETCURSEL, 0&, byval 0&)
    If iIndex >= 0 then oLabel = "Item Index: " & iIndex
    End If
    WindowProc = CallWindowProc(lPrevWndFunc, hwnd, Msg, wParam, lParam)
    End Function

    public Sub SubClassIt(byval hwnd as Long, byval Add as Boolean)
    If Add then
    lPrevWndFunc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
    else
    Call SetWindowLong(hwnd, GWL_WNDPROC, lPrevWndFunc)
    End If
    End Sub

    'In a Form, with a Label and a ComboBox..
    private Sub Form_Load()
    Dim iIndex as Long
    set oLabel = Label1
    SubClassIt Combo1.hwnd, true
    for iIndex = 1 to 10
    Combo1.AddItem "Item " & iIndex
    next
    End Sub

    private Sub Form_Unload(Cancel as Integer)
    SubClassIt Combo1.hwnd, false
    End Sub



    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

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

Featured