|
-
Sep 7th, 2006, 04:59 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Academic Label Questions
From my limited knowledge about labels:
1) They are windowless (no hWnd)
2) They generate events and have numerous properties
Now, I want to get the dimensions of a Label during runtime, but I can't use GetWindowRect. A Label's Top, Left, Width, Height properties cannot be read, but can be assigned.
How can I get this information? Surely if Windows can manipulate this information, I should be able to pull out the value via an API or something, no?
-
Sep 7th, 2006, 05:01 PM
#2
Re: Academic Label Questions
 Originally Posted by Fedhax
...A Label's Top, Left, Width, Height properties cannot be read....
Sure they can.
-
Sep 7th, 2006, 05:22 PM
#3
Thread Starter
Hyperactive Member
Re: Academic Label Questions
 Originally Posted by MartinLiss
Sure they can.
Not when you unknowingly try to get the .Top property of a Timer...
-
Sep 7th, 2006, 06:32 PM
#4
Re: [RESOLVED] Academic Label Questions
[Edited by MartinLiss]
.Left, .Top, .Width and .Height properties can be read. Btw... it's not logical that they can be assigned, but cannot be read. How can you assign something when you don't know what it is, that you're asigning???
-
Sep 8th, 2006, 08:42 AM
#5
Thread Starter
Hyperactive Member
Re: [RESOLVED] Academic Label Questions
 Originally Posted by gavio
[Edited by MartinLiss].Left, .Top, .Width and .Height properties can be read. Btw... it's not logical that they can be assigned, but cannot be read. How can you assign something when you don't know what it is, that you're asigning??? 
Agreed, which is why I posed the question from the position of bewilderment. As it turned out, I was itenerating through all of the objects on my form, and I forgot that one of the objects was a Timer. As we all know, the Timer has no .Top, .Left properties.
-
Sep 8th, 2006, 09:36 AM
#6
Re: [RESOLVED] Academic Label Questions
You probably figured it out but to iterate through all the controls you could do something like
VB Code:
Dim ctl As Control
On Error Resume Next
For Each ctl In Controls
Debug.Print ctl.Name & " " & ctl.Left
Debug.Print ctl.Name & " " & ctl.Top
Next
-
Sep 8th, 2006, 09:45 AM
#7
Re: [RESOLVED] Academic Label Questions
or (if you know what control types are on the form):
VB Code:
Dim ctl As Control
For Each ctl In Controls
If Not TypeOf ctl Is Timer Then
Debug.Print ctl.Name & " " & ctl.Left
Debug.Print ctl.Name & " " & ctl.Top
End If
Next ctl
-
Sep 8th, 2006, 09:49 AM
#8
Re: [RESOLVED] Academic Label Questions
 Originally Posted by Fedhax
As we all know, the Timer has no .Top, .Left properties.
That's not quite true. It has this properties, you just can't assign theme during runtime, because it's pointless.
-
Sep 8th, 2006, 10:01 AM
#9
Re: [RESOLVED] Academic Label Questions
Well, Timer has very limited Extender object during runtime (that provides much of the default features for controls). You can make an UserControl that is similar to features of a Timer. This article is a good reading for anyone who wants to know how the controls work and why they work the way they do.
I'm not actually fully sure how a Label is implemented; it might be more of a hacked control than most others. It is drawn directly to the form, but it still does have Left and Top properties and Move... but it still ponders me how a label tells to it's parent form that it should be drawn, because apparently label drawing happens natively within the VB's form paint handling routine. Or maybe not, because a label does blink pretty badly sometimes... so that'd mean it is drawn after the default WindowProc.
Last edited by Merri; Sep 8th, 2006 at 10:06 AM.
-
Sep 8th, 2006, 10:11 AM
#10
Thread Starter
Hyperactive Member
Re: [RESOLVED] Academic Label Questions
 Originally Posted by Merri
I'm not actually fully sure how a Label is implemented; it might be more of a hacked control than most others. It is drawn directly to the form, but it still does have Left and Top properties and Move... but it still ponders me how a label tells to it's parent form that it should be drawn, because apparently label drawing happens natively within the VB's form paint handling routine. Or maybe not, because a label does blink pretty badly sometimes... so that'd mean it is drawn after the default WindowProc.
You are touching on the question that I started wondering when I made this post. If a Label isn't a window with a hWnd value, why/how the heck does it have so many properties/functions that windowed objects have? Surely, there is a way to manipulate a label via API?
-
Sep 8th, 2006, 10:21 AM
#11
Re: [RESOLVED] Academic Label Questions
My question mostly is: why do you want to manipulate a label via API? Unlike you said in the first post, you can access the Left, Top, Width and Height properties during runtime. So you can calculate a RECT for a label, if you want.
-
Sep 8th, 2006, 10:25 AM
#12
Thread Starter
Hyperactive Member
Re: [RESOLVED] Academic Label Questions
 Originally Posted by Merri
My question mostly is: why do you want to manipulate a label via API? Unlike you said in the first post, you can access the Left, Top, Width and Height properties during runtime. So you can calculate a RECT for a label, if you want.
I don't have to do it. I'm not going to do it, but then I stumbled across the question (Hence, the use of the word "Academic" in the subject line) "Can you manipulate a Label via API since it behaves like a windowed object but isn't a windowed object?"
Moving this line of thinking along, are there other controls that give you the functionality of a Label with the ability to obtain a hWnd value without using a secondary container object (Frame, PictureBox, etc)?
-
Sep 8th, 2006, 10:39 AM
#13
Re: [RESOLVED] Academic Label Questions
Do you mean a custom label or something else? On UserControl side, well, you can probably see my signature link... It does have a hWnd. Although the latest version that I'm still working on doesn't seem to have it when I set BackStyle to transparent, Spy++ just doesn't recognise the control at all. And due to subclassing it has issues with the hWnd version as well, but we can count that as an issue of Spy++.
-
Sep 8th, 2006, 10:51 AM
#14
Thread Starter
Hyperactive Member
Re: [RESOLVED] Academic Label Questions
 Originally Posted by Merri
Do you mean a custom label or something else? On UserControl side, well, you can probably see my signature link... It does have a hWnd. Although the latest version that I'm still working on doesn't seem to have it when I set BackStyle to transparent, Spy++ just doesn't recognise the control at all. And due to subclassing it has issues with the hWnd version as well, but we can count that as an issue of Spy++.
Your label would be perfect, but I'm needing either a control to be transparent or some way to be masked with the form's color. Strange how Spy++ doesn't see/recognize your control as transparent...
-
Sep 8th, 2006, 10:56 AM
#15
Re: [RESOLVED] Academic Label Questions
Well, I believe that is because there isn't any MaskPicture set so there is no real layout for it. I do the transparency by drawing to the Form after form's WM_PAINT event. However, I'm having issues with multicontrol subclassing the same hWnd, replacing the same WindowProc, which I'm still working on to workaround.
But the end result would be same: even though you probably can get the RECT with GetWindowRect, that would be pretty much all of it, unless there is no transparency involved.
-
Sep 8th, 2006, 02:26 PM
#16
Thread Starter
Hyperactive Member
Re: [RESOLVED] Academic Label Questions
 Originally Posted by Merri
But the end result would be same: even though you probably can get the RECT with GetWindowRect, that would be pretty much all of it, unless there is no transparency involved.
Why would a label cause so much trouble if Windows can use it? Is there some sort of hidden "label container" API that the VSS/Windows programmers use to make this component work as it does?
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
|