comment
IRC Chat
play_arrow
Este sitio utiliza cookies propias y de terceros. Si continúa navegando consideramos que acepta el uso de cookies. OK Más Información.

Formulario transparente con controles visibles

  • 0 Respuestas
  • 1391 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Conectado ANTRAX

  • *
  • Administrator
  • Mensajes: 5331
  • Actividad:
    60%
  • Reputación 29
  • ANTRAX
    • Ver Perfil
    • Underc0de
    • Email
  • Skype: underc0de.org
  • Twitter: @Underc0de
« en: Julio 26, 2010, 12:05:45 pm »
¡OJO! Este codigo funciona solo si el BorderStyle del form es 0...

En un modulo:

Código: Visual Basic
  1. Option Explicit
  2. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  3. Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  4. Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
  5. Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
  6. Private Type POINTAPI
  7.         X As Long
  8.         Y As Long
  9. End Type
  10. Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
  11. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
  12. Const RGN_XOR = 3
  13.  
  14. Public Sub MakeTransparent(TransForm As Form)
  15. Dim ErrorTest As Double
  16.     On Error Resume Next
  17.     Dim Regn As Long
  18.     Dim TmpRegn As Long
  19.     Dim TmpControl As Control
  20.     Dim LinePoints(4) As POINTAPI
  21.     TransForm.ScaleMode = 3
  22.     If TransForm.BorderStyle <> 0 Then MsgBox "Change the borderstyle to 0!", vbCritical, "ACK!": End
  23.     Regn = CreateRectRgn(0, 0, 0, 0)
  24.     For Each TmpControl In TransForm
  25.         If TypeOf TmpControl Is Line Then
  26.             If Abs((TmpControl.Y1 - TmpControl.Y2) / (TmpControl.X1 - TmpControl.X2)) > 1 Then
  27.                 LinePoints(0).X = TmpControl.X1 - 1
  28.                 LinePoints(0).Y = TmpControl.Y1
  29.                 LinePoints(1).X = TmpControl.X2 - 1
  30.                 LinePoints(1).Y = TmpControl.Y2
  31.                 LinePoints(2).X = TmpControl.X2 + 1
  32.                 LinePoints(2).Y = TmpControl.Y2
  33.                 LinePoints(3).X = TmpControl.X1 + 1
  34.                 LinePoints(3).Y = TmpControl.Y1
  35.             Else
  36.                 LinePoints(0).X = TmpControl.X1
  37.                 LinePoints(0).Y = TmpControl.Y1 - 1
  38.                 LinePoints(1).X = TmpControl.X2
  39.                 LinePoints(1).Y = TmpControl.Y2 - 1
  40.                 LinePoints(2).X = TmpControl.X2
  41.                 LinePoints(2).Y = TmpControl.Y2 + 1
  42.                 LinePoints(3).X = TmpControl.X1
  43.                 LinePoints(3).Y = TmpControl.Y1 + 1
  44.             End If
  45.             TmpRegn = CreatePolygonRgn(LinePoints(0), 4, 1)
  46.         ElseIf TypeOf TmpControl Is Shape Then
  47.             If TmpControl.Shape = 0 Then
  48.                 TmpRegn = CreateRectRgn(TmpControl.Left, TmpControl.Top, TmpControl.Left + TmpControl.Width, TmpControl.Top + TmpControl.Height)
  49.             ElseIf TmpControl.Shape = 1 Then
  50.                 If TmpControl.Width < TmpControl.Height Then
  51.                     TmpRegn = CreateRectRgn(TmpControl.Left, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2, TmpControl.Left + TmpControl.Width, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2 + TmpControl.Width)
  52.                 Else
  53.                     TmpRegn = CreateRectRgn(TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2, TmpControl.Top, TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2 + TmpControl.Height, TmpControl.Top + TmpControl.Height)
  54.                 End If
  55.             ElseIf TmpControl.Shape = 2 Then
  56.                 TmpRegn = CreateEllipticRgn(TmpControl.Left, TmpControl.Top, TmpControl.Left + TmpControl.Width + 0.5, TmpControl.Top + TmpControl.Height + 0.5)
  57.             ElseIf TmpControl.Shape = 3 Then
  58.                 If TmpControl.Width < TmpControl.Height Then
  59.                     TmpRegn = CreateEllipticRgn(TmpControl.Left, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2, TmpControl.Left + TmpControl.Width + 0.5, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2 + TmpControl.Width + 0.5)
  60.                 Else
  61.                     TmpRegn = CreateEllipticRgn(TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2, TmpControl.Top, TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2 + TmpControl.Height + 0.5, TmpControl.Top + TmpControl.Height + 0.5)
  62.                 End If
  63.             ElseIf TmpControl.Shape = 4 Then
  64.                 If TmpControl.Width > TmpControl.Height Then
  65.                     TmpRegn = CreateRoundRectRgn(TmpControl.Left, TmpControl.Top, TmpControl.Left + TmpControl.Width + 1, TmpControl.Top + TmpControl.Height + 1, TmpControl.Height / 4, TmpControl.Height / 4)
  66.                 Else
  67.                     TmpRegn = CreateRoundRectRgn(TmpControl.Left, TmpControl.Top, TmpControl.Left + TmpControl.Width + 1, TmpControl.Top + TmpControl.Height + 1, TmpControl.Width / 4, TmpControl.Width / 4)
  68.                 End If
  69.             ElseIf TmpControl.Shape = 5 Then
  70.                 If TmpControl.Width > TmpControl.Height Then
  71.                     TmpRegn = CreateRoundRectRgn(TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2, TmpControl.Top, TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2 + TmpControl.Height + 1, TmpControl.Top + TmpControl.Height + 1, TmpControl.Height / 4, TmpControl.Height / 4)
  72.                 Else
  73.                     TmpRegn = CreateRoundRectRgn(TmpControl.Left, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2, TmpControl.Left + TmpControl.Width + 1, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2 + TmpControl.Width + 1, TmpControl.Width / 4, TmpControl.Width / 4)
  74.                 End If
  75.             End If
  76.             If TmpControl.BackStyle = 0 Then
  77.                 CombineRgn Regn, Regn, TmpRegn, RGN_XOR
  78.                 If TmpControl.Shape = 0 Then
  79.                     TmpRegn = CreateRectRgn(TmpControl.Left + 1, TmpControl.Top + 1, TmpControl.Left + TmpControl.Width - 1, TmpControl.Top + TmpControl.Height - 1)
  80.                 ElseIf TmpControl.Shape = 1 Then
  81.                     If TmpControl.Width < TmpControl.Height Then
  82.                         TmpRegn = CreateRectRgn(TmpControl.Left + 1, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2 + 1, TmpControl.Left + TmpControl.Width - 1, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2 + TmpControl.Width - 1)
  83.                     Else
  84.                         TmpRegn = CreateRectRgn(TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2 + 1, TmpControl.Top + 1, TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2 + TmpControl.Height - 1, TmpControl.Top + TmpControl.Height - 1)
  85.                     End If
  86.                 ElseIf TmpControl.Shape = 2 Then
  87.                     TmpRegn = CreateEllipticRgn(TmpControl.Left + 1, TmpControl.Top + 1, TmpControl.Left + TmpControl.Width - 0.5, TmpControl.Top + TmpControl.Height - 0.5)
  88.                 ElseIf TmpControl.Shape = 3 Then
  89.                     If TmpControl.Width < TmpControl.Height Then
  90.                         TmpRegn = CreateEllipticRgn(TmpControl.Left + 1, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2 + 1, TmpControl.Left + TmpControl.Width - 0.5, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2 + TmpControl.Width - 0.5)
  91.                     Else
  92.                         TmpRegn = CreateEllipticRgn(TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2 + 1, TmpControl.Top + 1, TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2 + TmpControl.Height - 0.5, TmpControl.Top + TmpControl.Height - 0.5)
  93.                     End If
  94.                 ElseIf TmpControl.Shape = 4 Then
  95.                     If TmpControl.Width > TmpControl.Height Then
  96.                         TmpRegn = CreateRoundRectRgn(TmpControl.Left + 1, TmpControl.Top + 1, TmpControl.Left + TmpControl.Width, TmpControl.Top + TmpControl.Height, TmpControl.Height / 4, TmpControl.Height / 4)
  97.                     Else
  98.                         TmpRegn = CreateRoundRectRgn(TmpControl.Left + 1, TmpControl.Top + 1, TmpControl.Left + TmpControl.Width, TmpControl.Top + TmpControl.Height, TmpControl.Width / 4, TmpControl.Width / 4)
  99.                     End If
  100.                 ElseIf TmpControl.Shape = 5 Then
  101.                     If TmpControl.Width > TmpControl.Height Then
  102.                         TmpRegn = CreateRoundRectRgn(TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2 + 1, TmpControl.Top + 1, TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2 + TmpControl.Height, TmpControl.Top + TmpControl.Height, TmpControl.Height / 4, TmpControl.Height / 4)
  103.                     Else
  104.                         TmpRegn = CreateRoundRectRgn(TmpControl.Left + 1, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2 + 1, TmpControl.Left + TmpControl.Width, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2 + TmpControl.Width, TmpControl.Width / 4, TmpControl.Width / 4)
  105.                     End If
  106.                 End If
  107.             End If
  108.         Else
  109.                TmpRegn = CreateRectRgn(TmpControl.Left, TmpControl.Top, TmpControl.Left + TmpControl.Width, TmpControl.Top + TmpControl.Height)
  110.        End If
  111.             ErrorTest = 0
  112.             ErrorTest = TmpControl.Width
  113.             If ErrorTest <> 0 Or TypeOf TmpControl Is Line Then
  114.                 CombineRgn Regn, Regn, TmpRegn, RGN_XOR
  115.             End If
  116.     Next TmpControl
  117.     SetWindowRgn TransForm.hwnd, Regn, True
  118. End Sub

En el form:

Código: Visual Basic
  1. Private Declare Function ReleaseCapture Lib "user32" () As Long
  2. 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
  3. Private Const WM_SYSCOMMAND = &H112
  4.  
  5. Private Sub Form_Load()
  6.     MakeTransparent frmTrans
  7. End Sub
« Última modificación: Mayo 12, 2014, 03:10:28 pm por Expermicid »


 

¿Te gustó el post? COMPARTILO!



Llamada de un formulario mediante el nombre como string

Iniciado por ANTRAX

Respuestas: 0
Vistas: 1220
Último mensaje Julio 26, 2010, 04:08:58 pm
por ANTRAX
Como Bloquear el Boton Cerrar del Formulario

Iniciado por ANTRAX

Respuestas: 0
Vistas: 1170
Último mensaje Julio 26, 2010, 12:46:46 pm
por ANTRAX
Aplicar transparencia a un formulario

Iniciado por ANTRAX

Respuestas: 0
Vistas: 1376
Último mensaje Julio 27, 2010, 04:37:57 pm
por ANTRAX
Formulario 3D

Iniciado por ANTRAX

Respuestas: 4
Vistas: 2104
Último mensaje Julio 27, 2010, 04:33:00 pm
por ANTRAX
Como crear controles en tiempo de ejecuacion

Iniciado por ANTRAX

Respuestas: 0
Vistas: 1160
Último mensaje Julio 26, 2010, 01:21:37 pm
por ANTRAX