Results 1 to 11 of 11

Thread: SetTimer inside a UserControl questions

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Greece
    Posts
    5

    Question SetTimer inside a UserControl questions

    Hi there.

    I want to create a button that has custom shape and I also
    want to implement hottracking (or mouseout/mouseover-type
    functionality).

    I've been trying to implement that with SetTimer/KillTimer
    but it only works for the first instance of my control.

    1) How can I go around this obstacle?
    2) if not possible is there an alternative? and if YES can you please give me an example? or just send me to a site with such
    an example?

    Thanks in Advance
    DOSida.


  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    I don't think you need that API right. you can use the UserControl_MoveMove event for you need.

    VB Code:
    1. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     '// Put your code here...
    3. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Greece
    Posts
    5

    Objective-> mouseOut

    Its not the MouseMove part that I cant handle its that I want
    a quick way of detecting when the Mouse is OUT of the control.

    That's why I am using SetTimer/KillTimer.

    Because what I want to create in the final run is a custom
    shaped button that can detect when the user takes the mouse
    Off it so that I can duplicate the rollover buttons that we see
    on webpages.

    The only way to get an accurate report of where the mouse is
    is to use POINTAPI structures and set the usercontrol to
    the shape that I want. BUT where I'm STUCK is on how to
    detect whether the mouse is actually in the mouse or not.

    I managed that with the SetTimer/KillTimer Combo BUT only
    for the 1st Instance. The other instances of my control are
    dead in the water doing NADA.

    Any help or pointers?
    Thanks in advance

    DOSida

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    or.. you can use the window ready made HitTest API PtInRegion when ever your move inthe control is move.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Greece
    Posts
    5

    Exclamation Doesnt work in all cases

    Chris,

    Thanks again for your response.

    I am indeed using PntInRegion to detect that.
    but in the case where I have a button that has a shape
    different than the default rectangle it doesnt work.

    The reason being is that when you apply the shape to the
    control and the button is indeed out of it there is NO
    MouseMove anywhere to execute PntInRegion so that
    I can detect whether or not the cursor is out of the control.

    To your (or anyone else's) knowledge is there a way to
    implement an instance-independent SetTimer/KillTimer
    combo?

    (hope this makes sense)
    Thanks in advance.
    DOSida.

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Hi! DOSida, here is what i found from MSDN Library

    HOWTO: Use the HitTest Event and HitBehavior Property

    Q185882


    --------------------------------------------------------------------------------
    The information in this article applies to:

    Microsoft Visual Basic Learning Edition for Windows, version 6.0
    Microsoft Visual Basic Professional Edition for Windows, version 6.0
    Microsoft Visual Basic Enterprise Edition for Windows, version 6.0

    --------------------------------------------------------------------------------


    SUMMARY
    This article discusses a new Event-Property pair available for UserControls created using Visual Basic 6.0. The general purpose of the HitTest Event, and the HitBehavior Property is to give greater flexibility in responding to UserControl events. Specifically, this article demonstrates how to build a transparent UserControl that responds to mouse events. This was not possible in previous versions of Visual Basic.



    MORE INFORMATION
    Using HitTest is relatively straightforward. "HitResult" is a value that is passed into the HitTest event by the system. By examining the value of HitResult, you can determine on which area of the control the mouse event occurred. Based on that information, you can reset the value of HitResult to have the control respond in the desired manner. You can instruct the control to process the mouse event, or you can instruct the control to pass the event on to the container. The default settings for the HitBehavior Property do not need to be changed for these examples.

    For the examples used here, there are two different scenarios depending on whether or not the UserControl has been masked using MaskPicture and MaskColor. If your UserControl does not have a masked area please see the section entitled "Capturing Mouse Events on a Transparent UserControl." If your UserControl has a masked area, please see the section entitled "Capturing Mouse Events on a Masked Usercontrol."

    It is important to note that the HitTest event occurs only on a Windowless UserControl with the BackStyle property set to Transparent. Windowless UserControls are also new to Visual Basic 6.0.


    Capturing Mouse Events on a Transparent UserControl
    Create a New Standard EXE project.


    Add a UserControl to the project. (You may receive a warning that the UserControl can not be Public in this type of project. Choose OK in response to this message.)


    Set the BackStyle property of the UserControl to Transparent.


    Set the Windowless property of the UserControl to True.


    Add the following code to the UserControl's module:

    Private Sub UserControl_Click()
    Debug.Print "Usercontrol Click"
    End Sub

    Private Sub UserControl_DblClick()
    Debug.Print "Usercontrol Doubleclick"
    End Sub

    Private Sub UserControl_HitTest(X As Single, Y As Single, _
    HitResult As Integer)

    'Instruct the UserControl to behave as if the click occurred on a
    ' painted region of the control.
    If HitResult = vbHitResultOutside Then
    HitResult = vbHitResultHit
    End If

    End Sub




    Place the UserControl on Form1. You may wish to draw a rectangle or other shape around the control since the control will not be visible.


    Run the project.


    Clicking or double-clicking the UserControl should result in the display of the message boxes.


    Capturing Mouse Events on a Masked UserControl
    This example requires a UserControl set up to use the MaskPicture and MaskColor Properties.

    For more information on using the MaskPicture and MaskColor properties, please see the article listed in the REFERENCES section.

    Create a bitmap with a white background that contains a filled red circle.


    Perform steps 1-4 from the previous section.


    Set the following properties for the UserControl:

    BackStyle: 0 - Transparent
    MaskColor: &H00FFFFFF& 'White
    MaskPicture: The bitmap created in Step 1.
    BackColor: &H000000FF& 'Red




    Add the following code to the UserControl:

    Private Sub UserControl_Click()
    Debug.Print "Usercontrol Click"
    End Sub




    Add the following code to Form1:

    Private Sub Form_Click()
    Debug.Print "Form Click"
    End Sub




    Run the project. Click the masked (or visible) portion of the UserControl. You should see the "UserControl Click" message box. Clicking the transparent area of the control should cause the "Form Click" message box to display. This is the default behavior of a masked control - events on the painted area will be processed by the control and events on the transparent area will be forwarded to the container.


    The event process behavior can be modified at this point to create separate responses based on which area of the UserControl received the Mouse event.


    Add the following code to the General Section of the UserControl's module:

    Private HitTestFlag As Integer

    Private Sub UserControl_HitTest(X As Single, Y As Single, _
    HitResult As Integer)
    HitTestFlag = HitResult
    'Set the UserControl to respond to the event.
    HitResult = vbHitResultHit
    End Sub




    Replace the UserControl_Click event created in step 2 with the following:

    Private Sub UserControl_Click()
    If HitTestFlag = vbHitResultOutside Then
    Debug.Print "usercontrol transparent area click"
    ElseIf HitTestFlag = vbHitResultHit Then
    Debug.Print "usercontrol painted area click"
    End If
    End Sub




    Run the project. Clicking the Masked area of the control should display the "painted area click" message. Clicking the transparent area of the control should display the "transparent area click" message.


    Using X and Y Coordinates with HitTest
    Along with the HitResult argument, the X and Y coordinates of the mouse event are also passed into the HitText Event. The ability to determine whether the event occurred on a transparent area of the control or a masked area of the control can be sufficient in many cases. However, it may be necessary to determine if the event occurred on a specific area on the control. The X and Y coordinates can be used to accomplish this. The following example demonstrates a simple scenario.

    For the example, we will determine over which quadrant of a UserControl the mouse pointer is currently positioned.

    Start a new Standard EXE project in Visual Basic 6.0.


    Add a Usercontrol to the project.


    Set the Windowless property of the UserControl to True.


    Set the BackStyle property of the UserControl to Transparent.


    Add the following code to the UserControl module:

    Private Sub UserControl_HitTest(X As Single, Y As Single, _
    HitResult As Integer)

    Dim txtDisplay As String
    With UserControl
    If Y < .Height / 2 Then
    txtDisplay = "Upper "
    Else
    txtDisplay = "Lower "
    End If
    If X < .Width / 2 Then
    txtDisplay = txtDisplay & "Left"
    Else
    txtDisplay = txtDisplay & "Right"
    End If
    End With

    Parent.Label1.Caption = txtDisplay

    End Sub




    Add a Label to the Form.


    Add the UserControl to Form1. You may wish to draw a square or rectangle around the control since it will not be visible. You may also want to display a picture on the form using the form's Picture property.


    Set the BackStyle of the Label to Transparent.


    Run the Project. As you move the mouse over the UserControl, the text in the Label control changes as you move from one quadrant to another.


    The HitBehavior Property
    The HitBehavior is settable at design time or run-time, and controls how HitTest works. There are three options, which are explained in Online Help. Since HitBehavior has the potential to effect logical evaluations in your code, it is important to understand the differences and determine which HitBehavior is desirable before you write the code.

    Summary
    HitTest and HitBehavior are new features in Visual Basic 6.0. These features allow event handling on transparent UserControls that was not possible in previous versions. There are many possible combinations when using HitTest, HitBehavior, and XY coordinates. They could be used to create any number of behaviors, ToolTips or HotSpots for example. Keep in mind that these properties and events are available for Windowless, Transparent UserControls only.



    REFERENCES
    For additional information on using the MaskPicture and MaskColor properties, please see the following article(s) in the Microsoft Knowledge Base:


    Q174216 : TransparentPaint Backstyle Option Unavailable

    Additional query words: kbDSupport kbDSD kbCtrlCreate kbVBp600 kbVBp

    Keywords : kbGrpDSVB
    Issue type : kbhowto
    Technology :


    Last Reviewed: January 9, 2001
    © 2001 Microsoft Corporation. All rights reserved. Terms of Use.




    --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources.

  7. #7
    Addicted Member ZanM's Avatar
    Join Date
    Oct 1999
    Location
    The here and now.
    Posts
    191

    you can also

    use the x and y of the control to test if you are in the control or not i'm looking for the code now but the mouse move fires after you are outside the control one last time. I'll get the code and place it here its really easier than the hit thing
    Magiaus
    Visual Basic 6.0 SP5
    Visual C++ 6.0 SP5


    The only sovereign you can allow to rule you is reason.

  8. #8
    Addicted Member ZanM's Avatar
    Join Date
    Oct 1999
    Location
    The here and now.
    Posts
    191
    i don't have it anymore and microsoft won't let me log in yet again.... but if you can log in to the download area for VB grab the soft-button example it is exactly what you need to look at + grab the web control examples
    Magiaus
    Visual Basic 6.0 SP5
    Visual C++ 6.0 SP5


    The only sovereign you can allow to rule you is reason.

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    A while ago, i posted an activeX dll of mine that adds mouseenter/exit events to any window
    http://forums.vb-world.net/showthrea...ght=mouseenter
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Greece
    Posts
    5

    Thumbs up Thanks guys

    Hey guys thanks for all the responses to my question

    Thanks also go to Kedaman.
    The DLL fits right in to my project and its working great

    Do you mind if I use it in my freeware projects that I am working
    on right now?

    (Full credits will be attributed, that goes without saying)

    Thanks again to all of you guys
    See ya later.

    DOSida

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    no problemo
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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