Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

A BackStyle property Frame

Hi ,

I need a frame that have a BackStyle property , So that i can make it transparent

Please help.

Remark : URGENT
  • 10
  • 8
  • 2
  • +2
1 Solution
Urgent, not an easy question and 15 points... Rights.

Try the picturebox. I think that one can be transparent.
InteqamAuthor Commented:
i need a frame .

that control you can insert other controls inside.

That's why I suggested a picture. This control has the same feature.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

InteqamAuthor Commented:
ok Mirkwood
thanks for answering but the problem is :

i have a frame that has inside a collection of combos, texts and option buttons.

i have a background for the form , but the frame is always gray , whick leaves a bad bad appearance , the label control can be transparent so that the text only appears on the background that i need , i found  that that property is named BackStyle , now i am looking for a Frame to put the same collection of controls inside , and keeps the appearance of the form ok ,

i have a frame that have a BackgroundPic property , but this frame is difficult to use and have a lot of problems .

Got the problem?

hope you did

A picturebox is containing just like a frame. What feature of the frame do you need that a picturebox does not have?

BTW: Everything is possible for the right price.
Do you want the controls to take the background color of the frame?
eg. when you have a Activex component inside a html page you can promot the Backcolor from the Activex and get the backgroundcolor from the html. when it startsup you can ask it to get the color and set the whole ocx to it.
InteqamAuthor Commented:
no i want the frame to take the background of the form

I can give you code to make your frame transparent through API calls, but it will make all controls on the frame transparent as well. I don't know, perhaps with some playing around, you might be able to fashion the code to fit exactly what you want it to do. Let mw know if you're interested.
InteqamAuthor Commented:
OK thank BerJC

Here you go...this code was originally used to make a form transparent. It's pretty simple, just call "MakeTransparent" with the frame name as a passed parameter.

Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRECT As RECT) As Long

    Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRECT As RECT) As Long

    Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2
    As Long, ByVal nCombineMode As Long) As Long

    Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal
    Y2 As Long) As Long

    Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long

    Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As
    Boolean) As Long
           Public Const RGN_AND = 1
           Public Const RGN_COPY = 5
           Public Const RGN_DIFF = 4
           Public Const RGN_OR = 2
           Public Const RGN_XOR = 3

           x As Long
           Y As Long
    End Type

    Type RECT
           Left As Long
           Top As Long
           Right As Long
           Bottom As Long
    End Type

    Public Sub MakeTransparent(frm As Frame)

           Dim rctClient As RECT, rctFrame As RECT
           Dim hClient As Long, hFrame As Long
           '     '// Grab client area and frame area
           GetWindowRect frm.hWnd, rctFrame
           GetClientRect frm.hWnd, rctClient
           '     '// Convert client coordinates to screen coordinates
           Dim lpTL As POINTAPI, lpBR As POINTAPI
           lpTL.x = rctFrame.Left
           lpTL.Y = rctFrame.Top
           lpBR.x = rctFrame.Right
           lpBR.Y = rctFrame.Bottom
           ScreenToClient frm.hWnd, lpTL
           ScreenToClient frm.hWnd, lpBR
           rctFrame.Left = lpTL.x
           rctFrame.Top = lpTL.Y
           rctFrame.Right = lpBR.x
           rctFrame.Bottom = lpBR.Y
           rctClient.Left = Abs(rctFrame.Left)
           rctClient.Top = Abs(rctFrame.Top)
           rctClient.Right = rctClient.Right + Abs(rctFrame.Left)
           rctClient.Bottom = rctClient.Bottom + Abs(rctFrame.Top)
           rctFrame.Right = rctFrame.Right + Abs(rctFrame.Left)
           rctFrame.Bottom = rctFrame.Bottom + Abs(rctFrame.Top)
           rctFrame.Top = 0
           rctFrame.Left = 0
           '     '// Convert RECT structures to region handles
           hClient = CreateRectRgn(rctClient.Left, rctClient.Top, rctClient.Right, rctClient.Bottom)
           hFrame = CreateRectRgn(rctFrame.Left, rctFrame.Top, rctFrame.Right, rctFrame.Bottom)
           '     '// Create the new "Transparent" region
           CombineRgn hFrame, hClient, hFrame, RGN_XOR
           '     '// Now lock the window's area to this created region
           SetWindowRgn frm.hWnd, hFrame, True
    End Sub
InteqamAuthor Commented:
can you supply me with an activX code for a frame that have the BackStyle property.

InteqamAuthor Commented:
hello bergJC , are you there?

InteqamAuthor Commented:
hello bergJC , are you there?

InteqamAuthor Commented:
i need an activX .

Ok, Inteqam, consider this a gift. Regularly, I don't answer questions below 50 points. (BTW what does Inteqam mean)

Transparent Control

Here are the steps to make a control transparent.
1) Create a form1
2) Create a usercontrol
3) Create a new form2
4) Put a picture control on form2 (picture1)
5) Set backcolor property of picture to &h00fffffff
6) Set maskcolor of usercontrol to &h00ffffff
7) Set backstyle of usercontrol to 0 - transparent
8) Add the following code to the usercontrol
Private Sub UserControl_Initialize()
    Load Form2
    UserControl.Picture = Form2.Picture1
    UserControl.MaskPicture = Form2.Picture1
End Sub

Private Sub UserControl_Resize()
    Form2.Picture1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub

Private Sub UserControl_Terminate()
    Unload Form2
End Sub
9) Add usercontrol to form1

Transparent form

ption Explicit

Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Public Const SRCCOPY = &HCC0020           ' Raster Operation
Public DesktopHDC As Long    ' This variable will store the Desktop handle
Public Desktop As Long            ' This will store the Desktop device context

Public Sub drawDesktop(Dest As Form)

    Dest.Visible = False    'Need to hide the form to refresh the background

    Desktop = GetDesktopWindow()
    DesktopHDC = GetWindowDC(Desktop)
    Dest.Visible = True     'Show the form again

    Call BitBlt(Dest.hdc, 0, 0, Dest.Width / Screen.TwipsPerPixelX, Dest.Height / Screen.TwipsPerPixelY, DesktopHDC, Dest.Left / Screen.TwipsPerPixelX, Dest.Top / Screen.TwipsPerPixelY, SRCCOPY)

    Call ReleaseDC(Desktop, DesktopHDC)          'Free used resource

End Sub

-------  MODULE   END   -------

On the previously created form add the following code :

-------  FORM1 CODE START  -------

Private Sub Form_Initialize()
    Label1.Caption = now()
    Call drawDesktop(Form1)
End Sub

Private Sub Timer1_Timer()
    Label1.Caption = "" 
    Call drawDesktop(Form1)

    Label1.Caption = Now()
End Sub
Transparent bitmap

Add this code to a module:

Public Type RECT
       Left As Long
       Top As Long
       Right As Long
       Bottom As Long
End Type  <Picture>

Public 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

Public Declare Function CreateBitmap Lib "gdi32" _
         (ByVal nWidth As Long, _
          ByVal nHeight As Long,
          ByVal nPlanes As Long, _
          ByVal nBitCount As Long,
          lpBits As Any) As Long

Public Declare Function SetBkColor Lib "gdi32" _
           (ByVal hdc As Long, ByVal crColor As Long) As Long

Public Declare Function SelectObject Lib "gdi32" _
          (ByVal hdc As Long, ByVal hObject As Long) As Long

Public Declare Function CreateCompatibleBitmap Lib "gdi32" _
          (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long

Public Declare Function CreateCompatibleDC Lib "gdi32" _
       (ByVal hdc As Long)As Long

Public Declare Function DeleteDC Lib "gdi32" _
       (ByVal hdc As Long) As Long

Public Declare Function DeleteObject Lib "gdi32" _
       (ByVal hObject As Long) As Long

Start a new project, and to the form add a command button and a picture box to make transparent as shown in the illustration.
Set the picture box picture property to a bitmap that has various colours on white background, and it's ScaleMode property to 3 - Pixel.
Side Effects:None
returns: null

Add this following code to the form:

Private Sub Command1_Click()

       Dim R As RECT
       With R
       .Left = 0
       .Top = 0
       .Right = Picture1.ScaleWidth
       .Bottom = Picture1.ScaleHeight
End With

TransparentBlt Form1.hdc, Form1.hdc, Picture1.hdc, R, 20, 20, vbWhite
End Sub

Private Sub TransparentBlt(OutDstDC As Long, _

       DstDC As Long, SrcDC As Long, SrcRect As RECT, _
       DstX As Integer, DstY As Integer, TransColor As Long)
       '     DstDC- Device context into which image must be drawn transparently
       '     OutDstDC- Device context into image is actually drawn, even though
       '     it is made transparent in terms of DstDC
       '     Src- Device context of source to be made transparent in color TransColor
       '     SrcRect- Rectangular region within SrcDC to be made transparent in terms of
       '     DstDC, and drawn to OutDstDC
       'DstX, DstY - Coordinates in OutDstDC (and DstDC) where the transparent bitmap m
       '     ust go
       '     In most cases, OutDstDC and DstDC will be the same
       Dim nRet As Long, W As Integer, H As Integer
       Dim MonoMaskDC As Long, hMonoMask As Long
       Dim MonoInvDC As Long, hMonoInv As Long
       Dim ResultDstDC As Long, hResultDst As Long
       Dim ResultSrcDC As Long, hResultSrc As Long
       Dim hPrevMask As Long, hPrevInv As Long
       Dim hPrevSrc As Long, hPrevDst As Long
       W = SrcRect.Right - SrcRect.Left + 1
       H = SrcRect.Bottom - SrcRect.Top + 1
       '     create monochrome mask and inverse masks
       MonoMaskDC = CreateCompatibleDC(DstDC)
       MonoInvDC = CreateCompatibleDC(DstDC)
       hMonoMask = CreateBitmap(W, H, 1, 1, ByVal 0&)
       hMonoInv = CreateBitmap(W, H, 1, 1, ByVal 0&)
       hPrevMask = SelectObject(MonoMaskDC, hMonoMask)
       hPrevInv = SelectObject(MonoInvDC, hMonoInv)
       '     create keeper DCs and bitmaps
       ResultDstDC = CreateCompatibleDC(DstDC)
       ResultSrcDC = CreateCompatibleDC(DstDC)
       hResultDst = CreateCompatibleBitmap(DstDC, W, H)
       hResultSrc = CreateCompatibleBitmap(DstDC, W, H)
       hPrevDst = SelectObject(ResultDstDC, hResultDst)
       hPrevSrc = SelectObject(ResultSrcDC, hResultSrc)
       '     copy src to monochrome mask
       Dim OldBC As Long
       OldBC = SetBkColor(SrcDC, TransColor)
       nRet = BitBlt(MonoMaskDC, 0, 0, W, H, SrcDC, SrcRect.Left, SrcRect.Top, vbSrcCopy)
       TransColor = SetBkColor(SrcDC, OldBC)
       '     create inverse of mask
       nRet = BitBlt(MonoInvDC, 0, 0, W, H, MonoMaskDC, 0, 0, vbNotSrcCopy)
       '     get background
       nRet = BitBlt(ResultDstDC, 0, 0, W, H, DstDC, DstX, DstY, vbSrcCopy)
       '     AND with Monochrome mask
       nRet = BitBlt(ResultDstDC, 0, 0, W, H, MonoMaskDC, 0, 0, vbSrcAnd)
       '     get overlapper
       nRet = BitBlt(ResultSrcDC, 0, 0, W, H, SrcDC, SrcRect.Left, SrcRect.Top, vbSrcCopy)
       '     AND with inverse monochrome mask
       nRet = BitBlt(ResultSrcDC, 0, 0, W, H, MonoInvDC, 0, 0, vbSrcAnd)
       '     XOR these two
       nRet = BitBlt(ResultDstDC, 0, 0, W, H, ResultSrcDC, 0, 0, vbSrcInvert)
       '     output results
       nRet = BitBlt(OutDstDC, DstX, DstY, W, H, ResultDstDC, 0, 0, vbSrcCopy)
       '     clean up
       hMonoMask = SelectObject(MonoMaskDC, hPrevMask)
       DeleteObject hMonoMask
       hMonoInv = SelectObject(MonoInvDC, hPrevInv)
       DeleteObject hMonoInv
       hResultDst = SelectObject(ResultDstDC, hPrevDst)
       DeleteObject hResultDst
       hResultSrc = SelectObject(ResultSrcDC, hPrevSrc)
       DeleteObject hResultSrc
       DeleteDC MonoMaskDC
       DeleteDC MonoInvDC
       DeleteDC ResultDstDC
       DeleteDC ResultSrcDC
End Sub

Run the project, and press the command button. The bitmap will be copied onto the form, and the white background will be transparent.
InteqamAuthor Commented:
hi MirkWood , sory for being late , but i have some problems ,

when trying to create a transparent control , there is no MaskColor property in the PictureBoc control , this is the first problem ,

secondly , How Can i use the steps you told me to create a transparent FRAME , so that this frame will have the same color of the form it is included in ,
do you understand me?

InteqamAuthor Commented:

Please post an answer so this question can be saved.  I will add the points back to Inteqam's account since it did not solve his problem but want to save it since it has solved other customer's problems.

Linda Gardner
Customer Service @ Experts Exchange
Question answered, see comments below.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 8
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now