Results 1 to 23 of 23

Thread: Invisible Form BUT...

  1. #1

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702

    Invisible Form BUT...

    OK how can I make the form totally invisible but have the objects such as picture boxes and labels still visible on it.

  2. #2
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    It's called transparency and it's a very difficult thing to accomplish in VB. You may search Google.com or planetsoursecode.com for ready to go samples.
    McGenius

  3. #3

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    Originally posted by McGenius
    It's called transparency and it's a very difficult thing to accomplish in VB. You may search Google.com or planetsoursecode.com for ready to go samples.
    Oh! Transparency does make the form totally invisible? I thot it just made it see through.... well anyway im gonna go check PSC

  4. #4

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    Originally posted by duc
    Oh! Transparency does make the form totally invisible? I thot it just made it see through.... well anyway im gonna go check PSC
    Well I found an example and I was right. It only makes it transparent. I want the FORM totally invisible but the objects such as pics and labels not invisible.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Clue me in.... I don't get it.... you want the form invisible, but not transparent.... but yet you want objects on the form visible... can you show an example? The way I read it is that you want the back ground of the formto show through so that the objects on the form appear to float over what ever is behind it it.... is that not what you want?
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    Originally posted by techgnome
    Clue me in.... I don't get it.... you want the form invisible, but not transparent.... but yet you want objects on the form visible... can you show an example? The way I read it is that you want the back ground of the formto show through so that the objects on the form appear to float over what ever is behind it it.... is that not what you want?
    OK, my plan is to make the form totally invisible but the picture boxes and labels visible. The reason I am doing this is becasue im to lazy to learn how to shape forms so I thought I would just draw my own form in PhotoShop and put it into VB. :-p confuzing

  7. #7
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Try this:
    VB Code:
    1. Private Const GWL_EXSTYLE = (-20)
    2. Private Const WS_EX_TRANSPARENT = &H20&
    3. Private Const SWP_FRAMECHANGED = &H20
    4. Private Const SWP_NOMOVE = &H2
    5. Private Const SWP_NOSIZE = &H1
    6. Private Const SWP_SHOWME = SWP_FRAMECHANGED Or _
    7. SWP_NOMOVE Or SWP_NOSIZE
    8. Private Const HWND_NOTOPMOST = -2
    9.  
    10. Private Declare Function SetWindowLong Lib "user32" _
    11. Alias "SetWindowLongA" _
    12. (ByVal hwnd As Long, ByVal nIndex As Long, _
    13. ByVal dwNewLong As Long) As Long
    14.  
    15. Private Declare Function SetWindowPos Lib "user32" _
    16. (ByVal hwnd As Long, ByVal hWndInsertAfter _
    17. As Long, ByVal x As Long, ByVal y As Long, _
    18. ByVal cx As Long, ByVal cy As Long, _
    19. ByVal wFlags As Long) As Long
    20.  
    21. Private Sub Command1_Click()
    22.     SetWindowLong Me.hwnd, GWL_EXSTYLE, _
    23.     WS_EX_TRANSPARENT
    24.     SetWindowPos Me.hwnd, HWND_NOTOPMOST, _
    25.     0&, 0&, 0&, 0&, SWP_SHOWME
    26. End Sub
    Last edited by seaweed; Apr 2nd, 2003 at 07:09 PM.
    ~seaweed

  8. #8
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    In the 2 cents department....

    I experimented with transparent forms to display microscope images (code almost identical to Seaweed's - it is btw exactly what you asked for), but man is it quirky.

    You can paint on the transparent form, the controls are visible, but its a bear trying to keep it transparent.

    You might be better off shaping the form.www.vbwm.com had a pretty good tutorial on doing it.

  9. #9

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    Originally posted by seaweed
    Try this:
    VB Code:
    1. Private Const GWL_EXSTYLE = (-20)
    2. Private Const WS_EX_TRANSPARENT = &H20&
    3. Private Const SWP_FRAMECHANGED = &H20
    4. Private Const SWP_NOMOVE = &H2
    5. Private Const SWP_NOSIZE = &H1
    6. Private Const SWP_SHOWME = SWP_FRAMECHANGED Or _
    7. SWP_NOMOVE Or SWP_NOSIZE
    8. Private Const HWND_NOTOPMOST = -2
    9.  
    10. Private Declare Function SetWindowLong Lib "user32" _
    11. Alias "SetWindowLongA" _
    12. (ByVal hwnd As Long, ByVal nIndex As Long, _
    13. ByVal dwNewLong As Long) As Long
    14.  
    15. Private Declare Function SetWindowPos Lib "user32" _
    16. (ByVal hwnd As Long, ByVal hWndInsertAfter _
    17. As Long, ByVal x As Long, ByVal y As Long, _
    18. ByVal cx As Long, ByVal cy As Long, _
    19. ByVal wFlags As Long) As Long
    20.  
    21. Private Sub Command1_Click()
    22.     SetWindowLong Me.hwnd, GWL_EXSTYLE, _
    23.     WS_EX_TRANSPARENT
    24.     SetWindowPos Me.hwnd, HWND_NOTOPMOST, _
    25.     0&, 0&, 0&, 0&, SWP_SHOWME
    26. End Sub
    Works perfctly! THX! But for some reason the form still looks like its their unless u move anothers programs form over it and then it disappears. But good enuff

  10. #10
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Take a look at this site...it shows you how to make an irregular shaped form, including putting holes in it!

    http://www.thescarms.com/vbasic/IrregularForms.asp
    ~seaweed

  11. #11

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    Originally posted by seaweed
    Take a look at this site...it shows you how to make an irregular shaped form, including putting holes in it!

    http://www.thescarms.com/vbasic/IrregularForms.asp
    lol thanx

  12. #12

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    Originally posted by duc
    Works perfctly! THX! But for some reason the form still looks like its their unless u move anothers programs form over it and then it disappears. But good enuff
    Actually thats not good enuff lol

    All that does is make the Title Bar disappear. The app does appear after you move another window over it though.


  13. #13

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    *bump*

  14. #14
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    He only wants controls visible, so no form or nothing is shown. Just like floating controls

  15. #15
    Hyperactive Member Q_Me's Avatar
    Join Date
    Dec 2001
    Posts
    327
    You want a hole in the form but the form is covered by the entire hole (which is you can click stuff behind it as if it wasn't there) right?
    53323737 15 743 313402 05 740313063. 17 15 4150 743 313402 05 140393403437 5203 743 30210.


  16. #16

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    Form = Not there

    Buttons and images = there


  17. #17

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    Originally posted by Q_Me
    You want a hole in the form but the form is covered by the entire hole (which is you can click stuff behind it as if it wasn't there) right?
    I guess....lol. I think thats what I want. So there is no form. But anything that i put on the form is visible.

  18. #18
    Hyperactive Member Q_Me's Avatar
    Join Date
    Dec 2001
    Posts
    327
    *Ponders*

    hmmmmm....

    Anybody got a code to wrap the hole around the buttons? I know that one is out there, they make smiley faces with those iregular forms, I'm sure there's a way to wrap it arround each object.
    53323737 15 743 313402 05 740313063. 17 15 4150 743 313402 05 140393403437 5203 743 30210.


  19. #19

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    *big bump*

    I want to be able to put buttons and images on the form but when the program starts, you dont see the form, all you see is the buttons and graphics placed on top of it. thanks!!1 This mustve been the 93rd time i described it lol

    -duc
    Last edited by duc; Dec 20th, 2003 at 02:44 PM.

  20. #20
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by duc
    Actually thats not good enuff lol

    All that does is make the Title Bar disappear. The app does appear after you move another window over it though.

    Have you tried setting the BorderStyle to None? I think that works.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  21. #21

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    I think that works. I will give it a try when I get back to my house.

  22. #22
    Fanatic Member doofusboy's Avatar
    Join Date
    Apr 2003
    Posts
    526
    Here's code for a completely transparent form containing a textbox and 2 command buttons:

    VB Code:
    1. Option Explicit
    2. Private Declare Function CreateRectRgn Lib _
    3.     "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, _
    4.     ByVal X2 As Long, ByVal Y2 As Long) As Long
    5. Private Declare Function CombineRgn Lib _
    6.     "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, _
    7.     ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    8. Private Declare Function SetWindowRgn Lib _
    9.     "user32" (ByVal hWnd As Long, ByVal hRgn As Long, _
    10.     ByVal bRedraw As Boolean) As Long
    11. Private Declare Function DeleteObject Lib _
    12.     "gdi32" (ByVal hObject As Long) As Long
    13.  
    14. ' Constants used by the CombineRgn function
    15. Private Const RGN_AND = 1
    16. Private Const RGN_OR = 2
    17. Private Const RGN_XOR = 3
    18. Private Const RGN_DIFF = 4
    19. Private Const RGN_COPY = 5
    20.  
    21. Private Sub Form_Activate()
    22.     Dim rgnForm As Long, rgnCombined As Long
    23.     Dim rgnControl As Long, x As Long
    24.     Dim formWidth As Single, formHeight As Single
    25.     Dim borderWidth As Single, titleHeight As Single
    26.     Dim ctlLeft As Single, ctlTop As Single
    27.     Dim ctlWidth As Single, ctlHeight As Single
    28.     Dim ctl As Control
    29.  
    30.     ' Calculate the form area
    31.     borderWidth = (Me.Width - Me.ScaleWidth) / 2
    32.     titleHeight = Me.Height - Me.ScaleHeight - borderWidth
    33.     ' Convert to Pixels
    34.     borderWidth = ScaleX(borderWidth, vbTwips, vbPixels)
    35.     titleHeight = ScaleY(titleHeight, vbTwips, vbPixels)
    36.     formWidth = ScaleX(Me.Width, vbTwips, vbPixels)
    37.     formHeight = ScaleY(Me.Height, vbTwips, vbPixels)
    38.    
    39.     ' Create a region for the whole form
    40.     rgnForm = CreateRectRgn(0, 0, formWidth, formHeight)
    41.    
    42.     rgnCombined = CreateRectRgn(0, 0, 0, 0)
    43.     ' Make the graphical area transparent by combining the two regions
    44.     x = CombineRgn(rgnCombined, rgnForm, rgnForm, RGN_DIFF)
    45.  
    46.     ' Make the controls visible
    47.     For Each ctl In Controls
    48.         ' Make the regions of controls whose container is the form visible
    49.         If TypeOf ctl.Container Is Form Then
    50.             ctlLeft = ScaleX(ctl.Left, vbTwips, vbPixels) + borderWidth
    51.             ctlTop = ScaleX(ctl.Top, vbTwips, vbPixels) + titleHeight
    52.             ctlWidth = ScaleX(ctl.Width, vbTwips, vbPixels) + ctlLeft
    53.             ctlHeight = ScaleX(ctl.Height, vbTwips, vbPixels) + ctlTop
    54.             rgnControl = CreateRectRgn(ctlLeft, ctlTop, ctlWidth, ctlHeight)
    55.             x = CombineRgn(rgnCombined, rgnCombined, rgnControl, RGN_OR)
    56.         End If
    57.     Next ctl
    58.    
    59.  
    60.     ' Set the clipping area of the window using the resulting region
    61.     SetWindowRgn hWnd, rgnCombined, True
    62.     ' Tidy up
    63.     x = DeleteObject(rgnCombined)
    64.     x = DeleteObject(rgnControl)
    65.     x = DeleteObject(rgnForm)
    66. End Sub
    67. Private Sub Command2_Click()
    68. Unload Me
    69. End Sub


    ...only wish I could remember where I got this to give proper credit...
    Do canibals not eat clowns because they taste funny?

  23. #23

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    Soooo close. When I add an imagebox or picturebox the the form the form becomes visible again. Also how can I make the background of a picturbox transparent. Thx.

    -duc

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