Results 1 to 29 of 29

Thread: Transparent frame possible?? [resolved (on a alternative way) :)]

Threaded View

  1. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Transparent frame possible?? [resolved (on a alternative way) :)]

    You can use BitBlt and some other APIs to mimic transparent frame.
    Here is a sample but you'll need to work with caption a little more to make it pefect.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const BDR_SUNKENOUTER = &H2
    4. Private Const BDR_RAISEDINNER = &H4
    5. Private Const DT_EDITCONTROL = &H2000&
    6. Private Const EDGE_ETCHED = (BDR_SUNKENOUTER Or BDR_RAISEDINNER)
    7. Private Const BF_BOTTOM = &H8
    8. Private Const BF_LEFT = &H1
    9. Private Const BF_RIGHT = &H4
    10. Private Const BF_TOP = &H2
    11. Private Const BF_RECT = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
    12. Private Const DT_LEFT = &H0
    13. Private Const DT_TOP = &H0
    14.  
    15. Private Type RECT
    16.         Left As Long
    17.         Top As Long
    18.         Right As Long
    19.         Bottom As Long
    20. End Type
    21.  
    22. Private Declare Function BitBlt Lib "gdi32" (ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    23. Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
    24. Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
    25. Private Declare Function DrawCaption Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long, pcRect As RECT, ByVal un As Long) As Long
    26. Private Declare Function DrawEdge Lib "user32" (ByVal hdc As Long, qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As Long
    27. Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    28.  
    29. Private Sub Command1_Click()
    30. '============================
    31. Static blnTrans As Boolean
    32. Dim MyRect As RECT
    33. Dim X1&, Y1&, X2&, Y2&
    34. Dim strText As String
    35. Dim TempDC As Long
    36.  
    37.     blnTrans = Not blnTrans 'toggle transparency
    38.    
    39.     With Frame1
    40.         If blnTrans Then
    41.             Me.Cls
    42.             Me.ScaleMode = vbPixels
    43.             X1 = .Left - 2
    44.             Y1 = .Top - 2
    45.             X2 = X1 + .Width + 4
    46.             Y2 = Y1 + .Height + 4
    47.             SetRect MyRect, X1, Y1, X2, Y2
    48.            
    49.             SetRect MyRect, X1, Y1, X2, Y2
    50.             DrawEdge Me.hdc, MyRect, EDGE_ETCHED, BF_RECT
    51.            
    52.             strText = .Caption
    53.             SetRect MyRect, X1 + 10, Y1 - 5, X2, Y2
    54.             DrawText Me.hdc, strText, Len(strText), MyRect, DT_LEFT Or DT_TOP
    55.            
    56.             TempDC = GetDC(.hWnd)
    57.             BitBlt TempDC, 0, 0, .Width, .Height, .Parent.hdc, .Left, .Top, vbSrcCopy
    58.         Else
    59.             Me.Cls
    60.             .Refresh
    61.         End If
    62.     End With
    63.  
    64. End Sub
    65.  
    66. Private Sub Form_Load()
    67.     Me.AutoRedraw = True
    68. End Sub
    69.  
    70. Private Sub Frame1_Click()
    71.     MsgBox "You've just clicked transparent frame control."
    72. End Sub

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