Results 1 to 19 of 19

Thread: VB6 - Glass Form

  1. #1

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

    VB6 - Glass Form

    Attached are a couple of examples of creating transparent windows with visible controls, but that don't allow the clicks to pass through.

    Since SetLayeredWindowAttributes API won't let you set the Alpha for just one particular colour - you have to make use of two forms.

    Glass Form.zip
    Very simple example of creating a glass form. Although this (and the following example) use two forms, all the code and controls are contained on one form - with the fEvents object being used to manage events on the transparent parts.

    Tracing App.zip - updated
    This example is a bit more complex (and actually has function!). This app acts a sheet of glass which youu can move around and draw on. Here's my tracing of a monkey:


    (if you think that's bad then imagine what it would've been like if I'd drawn it free hand!)

    The bottom-right circle can be used for resizing. The top and bottom left are for moving the form. And the three buttons in the top-right do their usual things. Click on the block of colour to change the colour and use the dropdown to change the pen width. The save button will allow you to save your picture, but the background will be Cyan and not transparent (although you could implement saving with transparency if you wanted)

    In order to stop the taskbar button changing (from checked to unchecked) everytime you clicked on a transparent part of the form, the app finds the button and ensure's it stays checked - I've avoided using subclassing at all.

    When the form gets big the drawing time really slows down - there are probably much better ways of drawing on the form - but since I know very little about graphics, I haven't attempted them.


    I can't really think of real world application for this code - but it's pretty cool

    Any bugs, comments or suggestions then post them here.

    As with anything using SetLayeredWindowAttributes, this will only work on 2000 and later
    If you find that the clicks are passing through then try increasing the number in the SetTrans fEvents, 1 line in Form_Load - see posts #9, #10 & #11


    Attached Files Attached Files

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: VB6 - Glass Form

    Nice effect on the Glass form.

    But, I don't understand how to use the Tracing app.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3

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

    Re: VB6 - Glass Form

    Quote Originally Posted by iPrank
    But, I don't understand how to use the Tracing app.
    what bits don't you understand?

    hold the left mouse button down and move it to draw.

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: VB6 - Glass Form

    Quote Originally Posted by bushmobile
    what bits don't you understand?

    hold the left mouse button down and move it to draw.
    More confused.

    The tracing from is transparent. When I click left button, the background form gets focus. There is no canvas to draw on.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  5. #5

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

    Re: VB6 - Glass Form

    Quote Originally Posted by iPrank
    The tracing from is transparent. When I click left button, the background form gets focus. There is no canvas to draw on.
    Now I'm confused.

    Are you saying it doesn't work for you? If you click and drag somewhere within the rectangle created by the four corner circles does it not draw a line?

  6. #6
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: VB6 - Glass Form

    Quote Originally Posted by bushmobile
    Now I'm confused.

    Are you saying it doesn't work for you? If you click and drag somewhere within the rectangle created by the four corner circles does it not draw a line?
    Nope. It just makes the form transparent. (like regioning)

    On second check, the glass form acts same. It is not acting as a GLASS.

    WinXP-SP2, Classic Theme, VB6 (no SP).
    Attached Images Attached Images  
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  7. #7
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: VB6 - Glass Form

    It works fine for me.

    Bugs:

    Run-time error '5':
    Invalid procedure call or argument.

    Cause:
    No minimum form size.

    Fix:
    Declare module-level variables MinWidth and MinHeight, assign values in Form_Load event. In picSize_MouseMove event procedure, declare variable for new left, top, width and height values. Test new width and height against minimums. If dragging from top left (Case 0), keep previous top and/or left values to prevent moving of form if height and/or width are forced to minimum.


    Run-time error '384':
    A form cannot be moved or sized while minimized or maximized.

    Cause:
    No means to prevent resize while maximized.

    Fix:
    In picSize_MouseDown event procedure, do nothing if WindowState <> vbNormal

  8. #8
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: VB6 - Glass Form

    Keith's code too is not working for me.

    Anyone else having similar problem ?
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  9. #9

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

    Re: VB6 - Glass Form

    @Logophobic:

    First bug: yeah i know that happens - I just couldn't be bothered to modify it - how lazy is that

    Second bug: good spot - i'll change that later.

    @iPrank:
    well the problem seems to be with the alpha - try changing the number on this line
    VB Code:
    1. SetTrans fEvents, [B]1[/B]
    set it to 150 or something an see what you get.

    perhaps try implementing the SetLayeredWindowAttributes on just a simple form

  10. #10
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: VB6 - Glass Form

    SetLayeredWindowAttributes Me.hWnd, 0, 5, LWA_ALPHA

    For any values lessthan 5, the form becomes ClickThrough.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11

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

    Re: VB6 - Glass Form

    strange

    oh well, glad it's working now. make it
    VB Code:
    1. SetTrans fEvents, 5
    and you should be fine

  12. #12
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: VB6 - Glass Form

    Thanks. It is working now.
    And this is really cool code.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  13. #13

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

    Re: VB6 - Glass Form

    Quote Originally Posted by iPrank
    Thanks. It is working now.
    And this is really cool code.
    Thanks

    I've fixed the bugs and added a save button - Tracing App.zip updated in post #1

  14. #14
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: VB6 - Glass Form

    Nice Effect

  15. #15
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Re: VB6 - Glass Form

    Now this is a cool app!

    I have no idea what I could possibly use it for other than to just mess around (getting absolutely NO work done at all). I guess more code should be written in just the name of fun.

    Well done!

  16. #16
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Re: VB6 - Glass Form

    I Found an EXCELLENT use for the app:
    Attached Images Attached Images  

  17. #17

  18. #18
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: VB6 - Glass Form

    Nice tracer!!!

  19. #19
    New Member
    Join Date
    Sep 2007
    Location
    Tappahannock, VA
    Posts
    1

    Re: VB6 - Glass Form USE

    Very nice program. One good use for the program is for screen mark-up when you are doing an LCD presentation. It works almost perfectly for this. My only request is, how about semi-transparent ink for the mark up. As it stands now, the ink is opaque and so obliterates what is written in a window beneath. I prefer to have more of a highliter look to the ink so you can see through to the writing below.

    Can you add transparency 10% 25% 50% 75% 90% or something like that?

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