Results 1 to 9 of 9

Thread: invisble form with buttons

  1. #1

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    22

    invisble form with buttons

    How do I make a form look like this


    ?

    The form is invisable but the things showing seem to be labels? Correct me if I'm wrong. How do I do this?

  2. #2
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: invisble form with buttons

    what are you tryoing to do? i know how to make the form invisible and show only the controls on it.
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: invisble form with buttons

    I have to ask... would you WANT to make your form look like that?

    In any case, the technique in use looks like regioning. Do a search on the forums for examples.

  4. #4
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: invisble form with buttons

    This will only make the controls show on the screen, with the rest of the form being invisible. Currently it only works with square items but can be easily modified for other shapes.
    VB Code:
    1. 'To use this code, you'll need to put controls on the form. Make sure that one control can unload
    2. 'form or you won't be able to close it
    3.  
    4. Const RGN_And = 1
    5. Const RGN_COPY = 5
    6. Const RGN_Or = 2
    7. Const RGN_Xor = 3
    8. Const RGN_DIFF = 4
    9. Private Const CCHILDREN_TITLEBAR = 5
    10. Private Type RECT
    11.     Left As Long
    12.     Top As Long
    13.     Right As Long
    14.     Bottom As Long
    15. End Type
    16. Private Type TITLEBARINFO
    17.     cbSize As Long
    18.     rcTitleBar As RECT
    19.     rgstate(CCHILDREN_TITLEBAR) As Long
    20. End Type
    21. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    22. Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    23. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    24. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    25. Private Declare Function SetWindowRgn Lib "User32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    26. Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    27. Private Declare Sub ReleaseCapture Lib "User32" ()
    28. Const WM_NCLBUTTONDOWN = &HA1
    29. Const HTCAPTION = 2
    30. Private Declare Function GetTitleBarInfo Lib "user32.dll" (ByVal hwnd As Long, ByRef pti As TITLEBARINFO) As Long
    31.  
    32. Private Sub Form_Load()
    33. Me.ScaleMode = vbPixels 'APIs work in pixels
    34.  
    35. Dim tb As TITLEBARINFO
    36. Dim rgn1 As Long
    37. Dim rgn As Long
    38. Dim ctrl As Control
    39.  
    40.     tb.cbSize = Len(tb)
    41.     GetTitleBarInfo Me.hwnd, tb
    42.     tbh = tb.rcTitleBar.Bottom - tb.rcTitleBar.Top + 2.5    'The Bar Height
    43.  
    44.     rgn = CreateRectRgn(Me.Left, Me.Top + tbh, Me.Left + Me.Width, Me.Top + Me.Height + tbh)   'This is the form region
    45.  
    46.  
    47.     For Each ctrl In Me
    48.         rgn1 = CreateRectRgn(ctrl.Left + 2.5, ctrl.Top + tbh, ctrl.Left + ctrl.Width + 2.5, ctrl.Top + ctrl.Height + tbh)   'Every control's region is taken
    49.         CombineRgn rgn, rgn, rgn1, RGN_Xor                                                                                  'away from the main region
    50.     Next
    51.  
    52.     SetWindowRgn Me.hwnd, rgn, True 'Set the form's shape to the region made
    53.  
    54.  
    55.     DeleteObject rgn    'cleanup
    56.     DeleteObject rgn1
    57. End Sub

  5. #5
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Re: invisble form with buttons

    You can make the form invisible using the follwong code.

    This goes in the general section

    VB Code:
    1. Public Const GWL_EXSTYLE = (-20)
    2. Public Const WS_EX_TRANSPARENT = &H20&
    3. Public Const SWP_FRAMECHANGED = &H20
    4. Public Const SWP_NOMOVE = &H2
    5. Public Const SWP_NOSIZE = &H1
    6. Public Const SWP_SHOWME = SWP_FRAMECHANGED Or _
    7. SWP_NOMOVE Or SWP_NOSIZE
    8. Public Const HWND_NOTOPMOST = -2
    9.  
    10. Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal
    11. hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    12.  
    13. Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal
    14. hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As
    15. Long, ByVal cy As Long, ByVal wFlags As Long) As Long

    And this on the form

    VB Code:
    1. Private Sub Form1_Load( )
    2.  
    3. SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT
    4. SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, SWP_SHOWME
    5.  
    6. End If

    If you add a picture box, you should be able to see it.
    It should work. If any problems, post here.

    _________

    If this post was helpful, please rate it

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: invisble form with buttons

    Quote Originally Posted by khanjan_a2k
    You can make the form invisible using the follwong code.

    This goes in the general section

    VB Code:
    1. Public Const GWL_EXSTYLE = (-20)
    2. Public Const WS_EX_TRANSPARENT = &H20&
    3. Public Const SWP_FRAMECHANGED = &H20
    4. Public Const SWP_NOMOVE = &H2
    5. Public Const SWP_NOSIZE = &H1
    6. Public Const SWP_SHOWME = SWP_FRAMECHANGED Or _
    7. SWP_NOMOVE Or SWP_NOSIZE
    8. Public Const HWND_NOTOPMOST = -2
    9.  
    10. Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal
    11. hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    12.  
    13. Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal
    14. hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As
    15. Long, ByVal cy As Long, ByVal wFlags As Long) As Long

    And this on the form

    VB Code:
    1. Private Sub Form1_Load( )
    2.  
    3. SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT
    4. SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, SWP_SHOWME
    5.  
    6. End If

    If you add a picture box, you should be able to see it.
    It should work. If any problems, post here.

    _________

    If this post was helpful, please rate it
    There is one issue with this approach. I've used this before, and encountered that fact that Labels will not show up when the form is made transparent. I've had no other problems with any other controls. I got "around" the problem by using a textbox as a label.

  7. #7
    Addicted Member Dayjo's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    130

    Re: invisble form with buttons

    Quote Originally Posted by Hack
    There is one issue with this approach. I've used this before, and encountered that fact that Labels will not show up when the form is made transparent. I've had no other problems with any other controls. I got "around" the problem by using a textbox as a label.
    If you can keep frames opaque, could you not put the label in a frame?

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: invisble form with buttons

    Quote Originally Posted by Dayjo
    If you can keep frames opaque, could you not put the label in a frame?
    I don't believe I tried that. Give it a shot and see what happens.

  9. #9
    Addicted Member Dayjo's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    130

    Re: invisble form with buttons

    Well I couldn't seem to get that to work actually, it just seems to crash, no error just go all glitchy etc.

    The fist example works fine though, with labels etc.

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