AnimateWindow是一個(gè)窗口打開和關(guān)閉時(shí)產(chǎn)生動(dòng)畫效果的新函數(shù),因?yàn)槭且粋€(gè)新的函數(shù), 所以在 API Viewer中是找不到的,必需自己定義:
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
注釋:具體可以使用的常量及其用法
Const LWA_ALPHA=&H2 注釋:表示把窗體設(shè)置成半透明樣式
Const LWA_COLORKEY=&H1 注釋:表示不顯示窗體中的透明色
具體例子
程序代碼
Module1
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Const WS_EX_LAYERED = &H80000
Public Const GWL_EXSTYLE = (-20)
Public Const LWA_ALPHA = &H2
Public Const LWA_COLORKEY = &H1
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Form1
Private Sub Form_Load()
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, 192, LWA_ALPHA
注釋:把窗體設(shè)置成半透明樣式,第二個(gè)參數(shù)表示透明程度
注釋:取值范圍0--255,為0時(shí)就是一個(gè)全透明的窗體了
End Sub
第二種使用方法
SetLayeredWindowAttributes Me.hWnd, &H0, 0, LWA_COLORKEY
注釋:表明不顯示窗體中的透明色
注釋:而第二個(gè)參數(shù)表示透明色為黑色,并且你可以用RGB函數(shù)來(lái)指定顏色值