/ Forside/ Teknologi / Udvikling / VB/Basic / Spørgsmål
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
VB/Basic
#NavnPoint
berpox 2425
pete 1435
CADmageren 1251
gibson 1230
Phylock 887
gandalf 836
AntonV 790
strarup 750
Benjamin... 700
10  tom.kise 610
Transparent form?
Fra : olaf
Vist : 609 gange
150 point
Dato : 02-03-01 14:35

Er det muligt i VB, at lave sin form transparent? Hvis ja, hvordan?

>>Olaf

 
 
Accepteret svar
Fra : pete

Modtaget 160 point
Dato : 02-03-01 15:18

Hej Olaf, prøv følgende kode :


Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_TRANSPARENT = &H20
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1

Private Const SWP_SHOWME = SWP_FRAMECHANGED Or _
SWP_NOMOVE Or SWP_NOSIZE

Private Const HWND_NOTOPMOST = -2

Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter _
As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long

Private Sub cmdTrans_Click()
' Me.ShowInTaskbar = False 'evt. skjul den i taskbar'en
Me.BorderStyle = 0

'// Lav din form transparent :
SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT

'// Læg den øverst :
SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, SWP_SHOWME

End Sub


Kommentar
Fra : pete


Dato : 02-03-01 15:29

Eller en mere avanceret metode hvor der er en subroutine du kan kalde med en form som parameter:

Option Explicit
'Create different types of regions declares
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
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
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
'POINTAPI type required for CreatePolygonRgn
Private Type POINTAPI
X As Long
Y As Long
End Type
'Sets the region
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
'Combines the region
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
'Type of combine
Const RGN_XOR = 3

Public Sub MakeTransparent(TransForm As Form)
Dim ErrorTest As Double
'In case there's an error, ignore it
On Error Resume Next

Dim Regn As Long
Dim TmpRegn As Long
Dim TmpControl As Control
Dim LinePoints(4) As POINTAPI

'Since the apis work with pixels, change the scalemode
'To pixels
TransForm.ScaleMode = 3

'You have to have a borderless form, this just makes
'sure it's borderless
If TransForm.BorderStyle <> 0 Then MsgBox "Change the borderstyle to 0!", vbCritical, "ACK!": End

'makes everything invisible
Regn = CreateRectRgn(0, 0, 0, 0)

'A loop to check every control in the form
For Each TmpControl In TransForm

'If the control is a line...
If TypeOf TmpControl Is Line Then
'Checks the slope
If Abs((TmpControl.Y1 - TmpControl.Y2) / (TmpControl.X1 - TmpControl.X2)) > 1 Then
'If it's more verticle than horizontal then
'Set the points
LinePoints(0).X = TmpControl.X1 - 1
LinePoints(0).Y = TmpControl.Y1
LinePoints(1).X = TmpControl.X2 - 1
LinePoints(1).Y = TmpControl.Y2
LinePoints(2).X = TmpControl.X2 + 1
LinePoints(2).Y = TmpControl.Y2
LinePoints(3).X = TmpControl.X1 + 1
LinePoints(3).Y = TmpControl.Y1
Else
'If it's more horizontal than verticle then
'Set the points
LinePoints(0).X = TmpControl.X1
LinePoints(0).Y = TmpControl.Y1 - 1
LinePoints(1).X = TmpControl.X2
LinePoints(1).Y = TmpControl.Y2 - 1
LinePoints(2).X = TmpControl.X2
LinePoints(2).Y = TmpControl.Y2 + 1
LinePoints(3).X = TmpControl.X1
LinePoints(3).Y = TmpControl.Y1 + 1
End If
'Creates the new polygon with the points
TmpRegn = CreatePolygonRgn(LinePoints(0), 4, 1)

'If the control is a shape...
ElseIf TypeOf TmpControl Is Shape Then

'An if that checks the type
If TmpControl.Shape = 0 Then
'It's a rectangle
TmpRegn = CreateRectRgn(TmpControl.Left, TmpControl.Top, TmpControl.Left + TmpControl.Width, TmpControl.Top + TmpControl.Height)
ElseIf TmpControl.Shape = 1 Then
'It's a square
If TmpControl.Width < TmpControl.Height Then
TmpRegn = CreateRectRgn(TmpControl.Left, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2, TmpControl.Left + TmpControl.Width, TmpControl.Top + (TmpControl.Height - TmpControl.Width) / 2 + TmpControl.Width)
Else
TmpRegn = CreateRectRgn(TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2, TmpControl.Top, TmpControl.Left + (TmpControl.Width - TmpControl.Height) / 2 + TmpControl.Height, TmpControl.Top + TmpControl.Height)
End If
ElseIf TmpControl.Shape = 2 Then
'It's an oval
TmpRegn = CreateEllipticRgn(TmpControl.Left, TmpControl.Top, TmpControl.Left + TmpControl.Width + 0.5, TmpControl.Top + TmpControl.Height + 0.5)
ElseIf TmpControl.Shape = 3 Then
'It's a circle
If TmpControl.Width < TmpControl.Height Then
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)
Else
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)
End If
ElseIf TmpControl.Shape = 4 Then
'It's a rounded rectangle
If TmpControl.Width > TmpControl.Height Then
TmpRegn = CreateRoundRectRgn(TmpControl.Left, TmpControl.Top, TmpControl.Left + TmpControl.Width + 1, TmpControl.Top + TmpControl.Height + 1, TmpControl.Height / 4, TmpControl.Height / 4)
Else
TmpRegn = CreateRoundRectRgn(TmpControl.Left, TmpControl.Top, TmpControl.Left + TmpControl.Width + 1, TmpControl.Top + TmpControl.Height + 1, TmpControl.Width / 4, TmpControl.Width / 4)
End If
ElseIf TmpControl.Shape = 5 Then
'It's a rounded square
If TmpControl.Width > TmpControl.Height Then
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)
Else
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)
End If
End If

'If the control is a shape with a transparent background
If TmpControl.BackStyle = 0 Then

'Combines the regions in memory and makes a new one
CombineRgn Regn, Regn, TmpRegn, RGN_XOR

If TmpControl.Shape = 0 Then
'Rectangle
TmpRegn = CreateRectRgn(TmpControl.Left + 1, TmpControl.Top + 1, TmpControl.Left + TmpControl.Width - 1, TmpControl.Top + TmpControl.Height - 1)
ElseIf TmpControl.Shape = 1 Then
'Square
If TmpControl.Width < TmpControl.Height Then
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)
Else
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)
End If
ElseIf TmpControl.Shape = 2 Then
'Oval
TmpRegn = CreateEllipticRgn(TmpControl.Left + 1, TmpControl.Top + 1, TmpControl.Left + TmpControl.Width - 0.5, TmpControl.Top + TmpControl.Height - 0.5)
ElseIf TmpControl.Shape = 3 Then
'Circle
If TmpControl.Width < TmpControl.Height Then
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)
Else
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)
End If
ElseIf TmpControl.Shape = 4 Then
'Rounded rectangle
If TmpControl.Width > TmpControl.Height Then
TmpRegn = CreateRoundRectRgn(TmpControl.Left + 1, TmpControl.Top + 1, TmpControl.Left + TmpControl.Width, TmpControl.Top + TmpControl.Height, TmpControl.Height / 4, TmpControl.Height / 4)
Else
TmpRegn = CreateRoundRectRgn(TmpControl.Left + 1, TmpControl.Top + 1, TmpControl.Left + TmpControl.Width, TmpControl.Top + TmpControl.Height, TmpControl.Width / 4, TmpControl.Width / 4)
End If
ElseIf TmpControl.Shape = 5 Then
'Rounded square
If TmpControl.Width > TmpControl.Height Then
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)
Else
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)
End If
End If
End If
Else
'Create a rectangular region with its parameters
TmpRegn = CreateRectRgn(TmpControl.Left, TmpControl.Top, TmpControl.Left + TmpControl.Width, TmpControl.Top + TmpControl.Height)

End If

'Checks to make sure that the control has a width
'or else you'll get some weird results
ErrorTest = 0
ErrorTest = TmpControl.Width
If ErrorTest <> 0 Or TypeOf TmpControl Is Line Then
'Combines the regions
CombineRgn Regn, Regn, TmpRegn, RGN_XOR
End If

Next TmpControl

'Make the regions
SetWindowRgn TransForm.hwnd, Regn, True


End Sub

Kommentar
Fra : Nyhedsbruger


Dato : 02-03-01 22:08

Hej Olaf

> Er det muligt i VB, at lave sin form transparent? Hvis ja, hvordan?

Det kan lade sig gøre, men kun i WIndows 2000 eller Windows ME. Du kan finde
et eksempel på hvordan det kan gøres på www.vbthunder.com

Hilsen/Best regards
Kim Pedersen, vbCode Magician Host
http://hjem.get2net.dk/vcoders/cm
ICQ: 62990889



Kommentar
Fra : Nyhedsbruger


Dato : 03-03-01 10:55

Her er et glimrende program for VB5 og 6 i windows 95/98/2000/ME

http://www.fortunecity.com./skyscraper/motorola/153/

Se etter programmet: VB SHAPED FORM CREATOR i javamenyen på venstre
side under programmering.


Beste hilsen Håkon Helgesen
VB Hobbyist






On Fri, 02 Mar 2001 13:33:51 GMT, "olaf" <olaf.news@kandu.dk> wrote:

>Er det muligt i VB, at lave sin form transparent? Hvis ja, hvordan?
>
>>>Olaf
>
>
>Leveret af:
>http://www.kandu.dk/
>"Vejen til en hurtig løsning"
>


Kommentar
Fra : Nyhedsbruger


Dato : 05-03-01 00:33

Hej Olaf

Hvis du med transparent form mener at kunne se hvad der ligger bag dit
vindue
kan det kun lade sig gøre i Windows2000 og WindowsME.
Du skal da bruge funktioner som SetLayeredWindowAttributes og
SetWindowLong (læs Microsoft Platform SDK).

Hvis du mener en 'non-rectangular' form så se evt. www.moontown.net.
Med FunnyFormX kan du let lave 'non-rectangular' forms baseret på et
bitmap billede, samt putte et ikon i System-Tray.

Med venlig hilsen
Thomas J.
thomas@moontown.net


"olaf" <olaf.news@kandu.dk> skrev i en meddelelse
news:3jNn6.13417$dD.629340@twister.sunsite.dk...
> Er det muligt i VB, at lave sin form transparent? Hvis ja, hvordan?
>
> >>Olaf
>
>
> Leveret af:
> http://www.kandu.dk/
> "Vejen til en hurtig løsning"
>



Godkendelse af svar
Fra : olaf


Dato : 05-03-01 10:12

Tak for svaret pete. Det var lige hvad jeg manglede.
                        

Du har følgende muligheder
Eftersom du ikke er logget ind i systemet, kan du ikke skrive et indlæg til dette spørgsmål.

Hvis du ikke allerede er registreret, kan du gratis blive medlem, ved at trykke på "Bliv medlem" ude i menuen.
Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408914
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste