|
-
Apr 13th, 2000, 12:33 AM
#1
Thread Starter
Fanatic Member
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
-
Apr 13th, 2000, 12:34 AM
#2
You can't. When you run your project, the contents of the Label are being printed directly on the form.
-
Apr 13th, 2000, 12:40 AM
#3
Thread Starter
Fanatic Member
Aaaaaaaaaaarrrggghhhh!!
Thanks anyway.
r0ach™
Don't forget to rate the post
-
Apr 13th, 2000, 01:42 AM
#4
Frenzied Member
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.
-
Apr 13th, 2000, 01:45 AM
#5
Not VB's Label........arghhhhhhh....
-
Apr 13th, 2000, 01:59 AM
#6
Frenzied Member
What are you trying to do that you need the hWnd for anyway? there may be another way round.
-
Apr 13th, 2000, 02:00 AM
#7
Thread Starter
Fanatic Member
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
-
Apr 13th, 2000, 02:24 AM
#8
Frenzied Member
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.
-
Apr 13th, 2000, 02:35 AM
#9
Thread Starter
Fanatic Member
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
-
Apr 13th, 2000, 03:08 AM
#10
Frenzied Member
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.
-
Apr 13th, 2000, 03:18 AM
#11
Thread Starter
Fanatic Member
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
-
Apr 13th, 2000, 03:30 AM
#12
Frenzied Member
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]
-
Apr 13th, 2000, 06:32 AM
#13
Frenzied Member
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]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|