CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Subclassing

  1. #1
    Join Date
    Jan 2000
    Posts
    1

    Subclassing

    I'm working on a new usercontrol... its not very advanced, just some lines making a "3D Flat Button" which prints text to the center of it, i have the code to draw the lines pushed in... etc... but i want to know when the users moves the mouse "Off" of the control, once that has happend i want it to use the HideLines sub to hide the lines. how can i subclass my form to figure out the mouse has moved off of it, or any other code i can use other than a timer to figure out that the mouse has moved off the usercontrol completely.


  2. #2
    Join Date
    Jul 2000
    Location
    The Netherlands
    Posts
    26

    Re: Subclassing

    Use the setcapture and ReleaseCapture API functions:

    Declare Function SetCapture Lib "user32.dll" (ByVal hWnd As Long) As Long
    Declare Function ReleaseCapture Lib "user32.dll" () As Long

    SetCapture directs all input from the mouse (including move messages) to the window specified in hWnd, and ReleaseCapture cancels that. So, if you place the following code in the mousemove event of your UserControl:

    Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If X >= 0 And X <= UserControl.ScaleWidth And Y >= 0 And Y <= UserControl.ScaleHeight Then
    SetCapture UserControl.hWnd
    'call whatever function you use if the mouse is over your control
    Else
    ReleaseCapture
    'call whatever function you use if the mouse is not over your control
    End If
    End Sub

    Because SetCapture directed all input from the mouse to your control from the moment the mouse moved over it, the mousemove event will continue to fire even when the mouse is no longer over the control, in which case the capture is released by the If-Then-Else statement in the sub. You can then use the sub to fire any function that blanks out the lines around your control.

    I hope that helped. If you have any questions about this, you can mail me: [email protected]

    Good luck,

    Vampyre


  3. #3
    Join Date
    Jul 2000
    Posts
    110

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