Option Explicit
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
Private Declare Function GetPixel Lib "gdi32.dll" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Form_Load()
Picture1.Move 90, 90, Me.ScaleWidth, 600
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then End
MediaPlayer1.Open CommonDialog1.FileName
Timer1.Interval = 200: Timer1.Enabled = True
End Sub
Private Sub Form_Resize()
MediaPlayer1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub
Private Sub Timer1_Timer()
Static Adjusted As Boolean
Dim hAWin As Long, hDC As Long, Color As Long
Picture1.Refresh
If Adjusted Then Exit Sub
hAWin = FindWindowEx(Me.hwnd, 0, "VideoRenderer", "ActiveMovie Window")
If hAWin = 0 Then Exit Sub
hDC = GetDC(hAWin)
Color = GetPixel(hDC, 1, 1)
DeleteDC hDC
SetParent Picture1.hwnd, hAWin
'Picture1.Move 0, 0
Picture1.BackColor = Color
Picture1.Cls
Picture1.Print "正在播放文件:" & vbCrLf & MediaPlayer1.FileName
Adjusted = True
End Sub
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Sub Command1_Click()
Dim rtn As Long
rtn = GetWindowLong(Me.hwnd, GWL_EXSTYLE) '取的窗口原先的样式
rtn = rtn Or WS_EX_LAYERED '使窗体添加上新的样式WS_EX_LAYERED
SetWindowLong Me.hwnd, GWL_EXSTYLE, rtn '把新的样式赋给窗体
SetLayeredWindowAttributes Me.hwnd, 0, 100, LWA_ALPHA '100为透明值,其范围是0-255