Results 1 to 16 of 16

Thread: [RESOLVED] Academic Label Questions

  1. #1

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Resolved [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?

  2. #2

  3. #3

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Academic Label Questions

    Quote Originally Posted by MartinLiss
    Sure they can.
    Not when you unknowingly try to get the .Top property of a Timer...

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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???

  5. #5

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: [RESOLVED] Academic Label Questions

    Quote 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.

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: [RESOLVED] Academic Label Questions

    You probably figured it out but to iterate through all the controls you could do something like

    VB Code:
    1. Dim ctl As Control
    2.    
    3.     On Error Resume Next
    4.     For Each ctl In Controls
    5.         Debug.Print ctl.Name & " " & ctl.Left
    6.         Debug.Print ctl.Name & " " & ctl.Top
    7.     Next

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: [RESOLVED] Academic Label Questions

    or (if you know what control types are on the form):
    VB Code:
    1. Dim ctl As Control
    2.  
    3. For Each ctl In Controls
    4.     If Not TypeOf ctl Is Timer Then
    5.         Debug.Print ctl.Name & " " & ctl.Left
    6.         Debug.Print ctl.Name & " " & ctl.Top
    7.     End If
    8. Next ctl

  8. #8
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [RESOLVED] Academic Label Questions

    Quote 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.

  9. #9
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  10. #10

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: [RESOLVED] Academic Label Questions

    Quote 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?

  11. #11
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  12. #12

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: [RESOLVED] Academic Label Questions

    Quote 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)?

  13. #13
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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++.

  14. #14

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: [RESOLVED] Academic Label Questions

    Quote 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...

  15. #15
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  16. #16

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: [RESOLVED] Academic Label Questions

    Quote 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
  •  



Click Here to Expand Forum to Full Width