Solved

Making white area's of Bitmaps see-through

Posted on 1998-12-09
3
168 Views
Last Modified: 2010-05-03
Is it possible to make the white parts of a bitmap (or other image) see through, so that I can see things behind them. Is it possible with the standard controls in Visual Basic 5, or is a new control needed?
0
Comment
Question by:Tree120998
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
kswinney earned 50 total points
ID: 1449027
You can do this with a combination of several lengthy API calls.

If you have access to the owner's area of the Visual Basic site at microsoft.com, there's a sample called "pnttools" which shows exactly how to do what you're after.

If you don't have access to the site, I can send you the sample (if you're a registered user of VB).

Cheers!

0
 
LVL 14

Expert Comment

by:waty
ID: 1449028
Here is a complete sample :

' #VBIDEUtils#************************************************************
' * Programmer Name  : Thomas Detoux
' * Web Site         : http://www.vbasic.org/
' * E-Mail           : Detoux@hol.Fr
' * Date             : 8/12/98
' * Time             : 14:41
' * Module Name      : WingWang_Module
' * Module Filename  : YingYang.bas
' **********************************************************************
' * Comments         : CREATION DE FEUILLES EN FORME DE YING ET DE YANG
' *  Sample of call
' *    Call YingYang(Me)
' *
' *
' **********************************************************************

Option Explicit

'Créé une region en forme de rectangle entre les points (X1,Y1) et (X2,Y2)
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

'Créé une région en forme d'éllipse entre les points (X1,Y1) et (X2,Y2)
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

'Combine deux régions pour en créer unr troisième selon le mode nCombineMode
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long

'Supprime un objet et libère de la mémoire
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

'Créé une feuille ayant la forme d'une région
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

'Constantes pour CombineRgn
Private Const RGN_AND = 1        'Intersection des deux régions
Private Const RGN_OR = 2         'Addition des deux régions
Private Const RGN_XOR = 3        'Difficile à décrire ... essayez
'En fait, c'est un XOR : l'addition des 2 régions
'en retirant les parties communes aux 2 régions
Private Const RGN_DIFF = 4       'Soustraction de la région 2 à la région 1
Private Const RGN_COPY = 5       'Copie la région 1

Private YY As Long

Public Sub YingYang(obj As Form)
   
   'Déclaration des différents "handles" des différentes "régions" de la feuille, qui, réunies, formeront le Ying Yang
   Dim Cercle        As Long
   Dim Rect          As Long
   Dim PCercleH      As Long
   Dim PCercleB      As Long
   Dim HCercle       As Long
   Dim Cadre         As Long
   Dim TrouB         As Long
   Dim TrouH         As Long
   Dim CercleBis     As Long
   Dim HCercleBis    As Long
   Dim CercleBisBis  As Long
   Dim Ying_Yang     As Long
   Dim YYang         As Long
   
   Dim H             As Long
   Dim L             As Long
   Dim HBord         As Long
   Dim LBord         As Long
   Dim HT            As Long
   Dim LT            As Long
   
   H = obj.Height / Screen.TwipsPerPixelY
   L = obj.Width / Screen.TwipsPerPixelX
   
   HBord = Int(H / 100)
   LBord = Int(L / 100)
   
   HT = Int(H / 10)
   LT = Int(L / 10)
   
   'Création des différentes "régions", et combinaisons entre elles
   'Attention : pour réaliser une combinaison, la variable-région de destination
   'doit déjà avoir été intialisée en lui affectant une région auparavant.
   
   HCercle = CreateEllipticRgn(((L - (2 * LBord)) / 4) + LBord, ((H - (2 * HBord)) / 2) + HBord, 3 * (((L - (2 * LBord)) / 4) + LBord), (H - HBord))
   Cercle = CreateEllipticRgn(LBord, HBord, L - LBord, H - HBord)
   Rect = CreateRectRgn(L / 2, 0, L, H)
   CombineRgn HCercle, Cercle, Rect, RGN_DIFF
   
   HCercleBis = CreateEllipticRgn(LBord, HBord, L - LBord, H - HBord)
   PCercleB = CreateEllipticRgn(((L - (2 * LBord)) / 4) + LBord, ((H - (2 * HBord)) / 2) + HBord, 3 * (((L - (2 * LBord)) / 4) + LBord), (H - HBord))
   CombineRgn HCercleBis, HCercle, PCercleB, RGN_DIFF
   
   CercleBis = CreateEllipticRgn(LBord, HBord, L - LBord, H - HBord)
   PCercleH = CreateEllipticRgn(((L - (2 * LBord)) / 4) + LBord, HBord, 3 * (((L - (2 * LBord)) / 4) + LBord), ((H - (2 * HBord)) / 2) + HBord)
   CombineRgn CercleBis, Cercle, PCercleH, RGN_DIFF
   
   CercleBisBis = CreateEllipticRgn(LBord, HBord, L - LBord, H - HBord)
   HCercle = CreateEllipticRgn(0, 0, L, H)
   CombineRgn CercleBisBis, CercleBis, HCercleBis, RGN_DIFF
   
   Ying_Yang = CreateEllipticRgn(0, 0, L, H)
   Cadre = CreateEllipticRgn(0, 0, L, H)
   CombineRgn Ying_Yang, Cadre, CercleBisBis, RGN_DIFF
   
   YYang = CreateEllipticRgn(0, 0, L, H)
   TrouB = CreateEllipticRgn(((L - (2 * LBord)) / 2) + LBord - (LT / 2), ((3 * (H - (2 * HBord)) / 4)) + HBord - (HT / 2), ((L - (2 * LBord)) / 2) + LBord + (LT / 2), ((3 * (H - (2 * HBord)) / 4)) + HBord + (HT / 2))
   CombineRgn YYang, Ying_Yang, TrouB, RGN_OR
   
   YY = CreateEllipticRgn(0, 0, L, H)
   TrouH = CreateEllipticRgn(((L - (2 * LBord)) / 2) + LBord - (LT / 2), ((H - (2 * HBord)) / 4) + HBord - (HT / 2), ((L - (2 * LBord)) / 2) + LBord + (LT / 2), ((H - (2 * HBord)) / 4) + HBord + (HT / 2))
   CombineRgn YY, YYang, TrouH, RGN_DIFF
   
   SetWindowRgn obj.hwnd, YY, True 'Applique la région finale à la feuille
   
   'Suppression des régions
   DeleteObject Cercle
   DeleteObject Rect
   DeleteObject PCercleH
   DeleteObject PCercleB
   DeleteObject HCercle
   DeleteObject Cadre
   DeleteObject TrouB
   DeleteObject TrouH
   DeleteObject CercleBis
   DeleteObject HCercleBis
   DeleteObject CercleBisBis
   DeleteObject Ying_Yang
   DeleteObject YYang

End Sub

0
 
LVL 14

Expert Comment

by:waty
ID: 1449029
Did you tried my solution?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

825 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