Avatar billede akexpert Nybegynder
18. november 2001 - 13:42 Der er 3 kommentarer og
2 løsninger

Gennemsigtig form

Er der nogen der ved hvordan man kan få en gennemsigtig form ligesom i WinAmp? I WinAmp kan man vælge et skin, som er gennemsigtig...

/akExpert
Avatar billede kedde65 Praktikant
18. november 2001 - 18:36 #2
Bare lige en lille undren.....jeg kan altså ikke få deres eksempel til at virke. Er der en fejl jeg har overset.

Kedde
Avatar billede ea_data Nybegynder
18. november 2001 - 22:53 #3
Hvad er der galt med svaret ?
Avatar billede sjh Nybegynder
19. november 2001 - 01:10 #4
\'--------------------------- Form1 ---------------------------
\'Set Form1.BorderStyle = 0
\'-------------------------------------------------------------
Option Explicit

Private Declare Function ReleaseCapture Lib \"user32\" () As Long
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

Private Declare Function SetWindowRgn Lib \"user32\" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib \"gdi32\" (ByVal hObject As Long) As Long
Private Declare Function CreateCompatibleDC Lib \"gdi32\" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib \"gdi32\" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function GetObject Lib \"gdi32\" Alias \"GetObjectA\" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
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 CombineRgn Lib \"gdi32\" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function DeleteDC Lib \"gdi32\" (ByVal hdc As Long) As Long
Private Declare Function GetPixel Lib \"gdi32\" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long

Private Type BITMAP
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type

Private Function GetBitmapRegion(cPicture As StdPicture, cTransparent As Long) As Long
Dim hRgn As Long, tRgn As Long
Dim X As Integer, Y As Integer, X0 As Integer
Dim hdc As Long, BM As BITMAP

hdc = CreateCompatibleDC(0)
  If hdc Then
    SelectObject hdc, cPicture
    GetObject cPicture, Len(BM), BM
    hRgn = CreateRectRgn(0, 0, BM.bmWidth, BM.bmHeight)
    For Y = 0 To BM.bmHeight
      For X = 0 To BM.bmWidth
        While X <= BM.bmWidth And GetPixel(hdc, X, Y) <> cTransparent
          X = X + 1
            Wend
              X0 = X
            While X <= BM.bmWidth And GetPixel(hdc, X, Y) = cTransparent
          X = X + 1
        Wend
        If X0 < X Then
          tRgn = CreateRectRgn(X0, Y, X, Y + 1)
          CombineRgn hRgn, hRgn, tRgn, 4
          DeleteObject tRgn
        End If
      Next X
    Next Y
    GetBitmapRegion = hRgn
    DeleteObject SelectObject(hdc, cPicture)
  End If
DeleteDC hdc
End Function

Private Sub Form_Load()
Dim hRgn As Long
  Me.Picture = LoadPicture(\"C:\\WINDOWS\\Skrivebord\\test.bmp\") \'Load billede
  hRgn = GetBitmapRegion(Me.Picture, &HFF00FF) \'&HFF00FF< Transparent Farve
  SetWindowRgn Me.hwnd, hRgn, True
  DeleteObject hRgn
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = vbLeftButton Then
    \'--------- Move window ---------
    ReleaseCapture
    Call SendMessage(Me.hwnd, &HA1, 2, 0&)
    \'--------- Move window ---------
  End If
End Sub
\'--------------------------- Form1 ---------------------------
Avatar billede ea_data Nybegynder
20. november 2001 - 19:48 #5
\'Hvordan en form gøres gennemsigtig
\'1. Opret et modul og tilføj denne kode

Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_TRANSPARENT = &H20&
Public Const SWP_FRAMECHANGED = &H20
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_SHOWME = SWP_FRAMECHANGED Or _
SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_NOTOPMOST = -2
Declare Function SetWindowLong Lib \"user32\" _
Alias \"SetWindowLongA\" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
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 Command1_Click()
\'2. Tilføj en commandbutton med denne kode til form1
Form1.BorderStyle = 0
SetWindowLong Me.hwnd, GWL_EXSTYLE, _
WS_EX_TRANSPARENT
SetWindowPos Me.hwnd, HWND_NOTOPMOST, _
0&, 0&, 0&, 0&, SWP_SHOWME
End Sub
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester