Solved

A BackStyle property Frame

Posted on 1998-11-22
22
451 Views
Last Modified: 2013-12-26
Hi ,

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

Please help.

Remark : URGENT
0
Comment
Question by:Inteqam
  • 10
  • 8
  • 2
  • +2
22 Comments
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Urgent, not an easy question and 15 points... Rights.

Try the picturebox. I think that one can be transparent.
0
 
LVL 7

Author Comment

by:Inteqam
Comment Utility
i need a frame .

that control you can insert other controls inside.




0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
That's why I suggested a picture. This control has the same feature.
0
 
LVL 7

Author Comment

by:Inteqam
Comment Utility
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

0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
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.
0
 

Expert Comment

by:reheuvel
Comment Utility
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.
0
 
LVL 7

Author Comment

by:Inteqam
Comment Utility
no i want the frame to take the background of the form

0
 
LVL 2

Expert Comment

by:BergJC
Comment Utility
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.
0
 
LVL 7

Author Comment

by:Inteqam
Comment Utility
OK thank BerJC


0
 
LVL 2

Expert Comment

by:BergJC
Comment Utility
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

    Type POINTAPI
           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
0
 
LVL 7

Author Comment

by:Inteqam
Comment Utility
can you supply me with an activX code for a frame that have the BackStyle property.

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 7

Author Comment

by:Inteqam
Comment Utility
hello bergJC , are you there?

0
 
LVL 7

Author Comment

by:Inteqam
Comment Utility
hello bergJC , are you there?

0
 
LVL 7

Author Comment

by:Inteqam
Comment Utility
i need an activX .

0
 
LVL 13

Expert Comment

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

0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
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

0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
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 = ""
    Label1.Refresh
    Call drawDesktop(Form1)

    Label1.Caption = Now()
    Label1.Refresh
End Sub
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
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.
 
0
 
LVL 7

Author Comment

by:Inteqam
Comment Utility
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?

0
 
LVL 7

Author Comment

by:Inteqam
Comment Utility
WHERE R U?

0
 
LVL 7

Expert Comment

by:linda101698
Comment Utility
Mirkwood,
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
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 20 total points
Comment Utility
Question answered, see comments below.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now