[RESOLVED] SetWindowLong and WM_MOUSEMOVE
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: [RESOLVED] SetWindowLong and WM_MOUSEMOVE

  1. #1
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    [RESOLVED] SetWindowLong and WM_MOUSEMOVE

    Question for the gurus. I need to be able to ignore the mousemove event selectively for a selected control on a form. More specifically, I need the X and Y mousepointer coordinates to reflect the X,Y coordinates relative to the parent form window and NOT the control the mouse is over. I assume I can use GetWindowLong and SetWindowLong then only handle WM_MOUSEMOVE messages in some routine other than my SelectedControl_Mousemove event routine. But I'm not sure exactly how I would go about ignoring the control boundaries of the selected window I'm processing the messages for.

    In my perfect world LOL, I could just discard the WM_MOUSEMOVE messages entirely for a selected window and the WM_MOUSEMOVE messages for the parent window would continue to work uninterrupted as if the mouse had never passed over another window, but that would be too easy now wouldn't it???

    Anyone have any ideas on a good starting point?

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,987

    Re: SetWindowLong and WM_MOUSEMOVE

    Do the math. One control is a subset of the screen, so if you're in that space, ignore clicks. Not sure about hiding mouse move, though. Depends on what you mean
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: SetWindowLong and WM_MOUSEMOVE

    DG,

    Thanks for the reply. Yeah, I knew that controls on my my form were child windows of the parent, and ignoring the mouseclicks is fairly straight forward, but I'm actually looking to ignore the mousemove event of all subwindows during a drag event. I may be re-inventing the wheel here, as I'm now looking at a function:

    DragDetect. I can't readily find a VB implementation of this but I've looked at some of the example C++ code and it looks like it might be what I'm looking for. I'm going to charge the Front Line and see if I can make it work.

    What I want to do is drag one control across my form window and not lose track of my current location on the form as I drag 'Across' another control.

    Thoughts?

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,987

    Re: SetWindowLong and WM_MOUSEMOVE

    Sub-windows of YOUR app, or any open app? You can't prevent mouse_move, as the cursor WILL move over the control.

    I suggest disabling the DROP while over your form.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jun 2004
    Location
    NH
    Posts
    674

    Re: SetWindowLong and WM_MOUSEMOVE

    Still not sure what you mean.
    Do you have something written in your controls mouse move procedure, that you don't want invoked?

    If so, you could use the GetKeyState API, to detect if the mouse is down.

    If, not then GetCursorPos API will give the screen coordinates of the pointer.
    Then GetWindowRect will give you the boundry coordinates of your form.
    This would allow you to keep track of the position relative to the form.

    Some declarations:
    Code:
    Private Declare Function apiGetKeyState Lib "user32" Alias "GetKeyState" (ByVal vKey As Long) As Long
    
    Private Declare Function apiGetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hWnd As Long, ByRef lpRect As RECT) As Boolean 
    
    Private Declare Function apiGetCursorPos Lib "user32" Alias "GetCursorPos" (ByRef lpPoint As POINTAPI) As Boolean

    If that doesn't solve your problem, let us know.
    Last edited by TT(n); July 18th, 2009 at 12:58 AM.

  6. #6
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: SetWindowLong and WM_MOUSEMOVE

    Thanks for all the input guys. I actually resolved the situation with

    SetCapture Lib "user32" (ByVal hWnd As Long) As Long
    ReleaseCapture Lib "user32" () As Long


    It works nicely. I've attached a Demo Project if anyone would like see the procedure and effect.
    Attached Files Attached Files

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,092

    Re: SetWindowLong and WM_MOUSEMOVE

    Thanx for sharing your wonderful solution

  8. #8
    Join Date
    Dec 2001
    Posts
    6,332

    Re: SetWindowLong and WM_MOUSEMOVE

    Glad to see you've got it resolved. Another way to get a window to ignore the mouse, is to disable it. Then the mouse messages go to the window underneath.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center