Results 1 to 13 of 13

Thread: Label1.hWnd ?????

  1. #1

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Question

    Hi,

    Can someone tell me how to get the hWnd for a label?

    Help would be appreciated.

    r0ach™
    Don't forget to rate the post

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You can't. When you run your project, the contents of the Label are being printed directly on the form.

  3. #3

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Unhappy

    Aaaaaaaaaaarrrggghhhh!!

    Thanks anyway.

    r0ach™
    Don't forget to rate the post

  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I thought a Label wass based on the static class, ie has no window procedure and no internal DC, you should be able to get at the hWnd from Findwindow or WindowFromPoint, the class name is "ThunderLabel".

    I could be wrong though.

    Hope this helps.

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Not VB's Label........arghhhhhhh....

  6. #6
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    What are you trying to do that you need the hWnd for anyway? there may be another way round.

  7. #7

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    This is my problem:

    I want to make the label respond like a hyperlink in a browser. I know there are OCX's that does this, but I want to do my own, so that i can cut down on extra files. I'm using SetCapture and ReleaseCapture API calls, and SetCapture requires the hwnd of the control. I put the label inside a picturebox, in order to get a hwnd, but now the ReleaseCapture Function does not seem to respond. I got the label to change color on mouseover, but it doesn't change back. Aaaarrghh!

    r0ach™
    Don't forget to rate the post

  8. #8
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    how are you trying to change the colour of the label when you move the mouse off it, I didnt think there was any reliable way of doing this without setting a hook, and no 100% way without a global hook, which I don't think you can do outside an old style dll, which You can't do in VB. or am I wrong again.

  9. #9

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    That's what the SetCapture and ReleaseCapture is for. In the Label's Mousemove event, there's a Call to HighlightLabel (which is a procedure I wrote), in which SetCapture is called if the X co-ords is > 0 and < then Label1.Width, and the Y co-ords is > 0 and < than Label1.Height, or ReleaseCapture is called otherwise. Then I change the color with Label1.ForeColor = HoverColor or Label1.ForeColor = LinkColor (Properties) respectively.

    It's Changing to Hovercolor, but not back to LinkColor.

    r0ach™
    Don't forget to rate the post

  10. #10
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Ahh, I don't use that method, it screws with the click and double click events. setting the hook is quite hard, I've never actually got round to doing it properly, If you can subclass then you might wanna try though, I'm doing the same thing at the moment, I'll post some code.

  11. #11

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Thumbs down

    I found this link with the SetCapture and ReleaseCapture. I tried it, but it doesn't work as planned:

    http://mskadu.freeservers.com/articl...hoverbtns.html

    Hmmmm.

    r0ach™
    Don't forget to rate the post

  12. #12
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Try This for Mouse Over

    Here is a little code I wrote to detect a MouseOver event for any control on your form. Only problem may be that detection has to occur in a timer which may hurt performance if you're testing MouseOver for a ton of controls.

    Basically, it uses Win32API to get cursor position, and then compares that position to the rectangle of the control. If the cursor position is inside the rectangle it returns TRUE.

    The MouseOver function resides in a module along with the API calls. It takes two arguments: the control you are testing and the form it resides on (the form is necessary because the position of the control rectangle changes depending on the borderstyle of it's form).

    Put this code in a module:
    Code:
    Option Explicit
    
    Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Private Function GetControlRect(ControlIn As Control, FormIn As Form) As RECT
        Dim OffsetX As Integer, _
            OffsetY As Integer
            
        If FormIn.BorderStyle = 0 Then
            OffsetX = 0
            OffsetY = 0
        Else
            OffsetX = 50
            OffsetY = 325
        End If
        
        With GetControlRect
            .Left = (ControlIn.Left + FormIn.Left + OffsetX) / Screen.TwipsPerPixelX
            .Right = (ControlIn.Left + FormIn.Left + _
                ControlIn.Width + OffsetX) / Screen.TwipsPerPixelX
            .Top = (ControlIn.Top + FormIn.Top + OffsetY) / Screen.TwipsPerPixelY
            .Bottom = (ControlIn.Top + FormIn.Top + _
                OffsetY + ControlIn.Height) / Screen.TwipsPerPixelY
        End With
    End Function
    
    Public Function MouseOver(ControlIn As Control, FormIn As Form) As Boolean
        Dim CursorPos As POINTAPI
        Dim ControlRect As RECT
    
        GetCursorPos CursorPos
        ControlRect = GetControlRect(ControlIn, FormIn)
        
        With ControlRect
            If CursorPos.X > .Left And _
                CursorPos.X < .Right And _
                CursorPos.Y > .Top And _
                CursorPos.Y < .Bottom Then
                    MouseOver = True
            Else
                MouseOver = False
            End If
        End With
    End Function
    Here is the code used to call the function. It should be in a timer, so it checks for MouseOver periodically (like every 1/2 second or less for smoothness). To use this code, you need a Timer, two Labels, and a PictureBox on your form (with the default names).
    Code:
    Option Explicit
    
    Private Sub Timer1_Timer()
        
        If MouseOver(Label1, Me) Then
            Label2 = "You're over the label"
        ElseIf MouseOver(Picture1, Me) Then
            Label2 = "You're over the picture"
        Else
            Label2 = "You aren't over any controls"
        End If
    
    End Sub
    [Edited by seaweed on 04-13-2000 at 05:02 PM]
    ~seaweed

  13. #13
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    PS

    If you want to use the code I wrote above to simulate a hyperlink, do something like this:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        With Label1
            .Font.Underline = True
            .Caption = "My Hyperlink"
        End With
    End Sub
    
    Private Sub Timer1_Timer()
        With Label1
            If MouseOver(Label1, Me) Then
                .ForeColor = vbBlue
            Else
                .ForeColor = vbButtonText
            End If
        End With
    End Sub
    [Edited by seaweed on 04-13-2000 at 05:56 PM]
    ~seaweed

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