Private Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Long, ByVal dwTime As Long, ByVal dwFlags As Long) As LongConst AW_HOR_POSITIVE = &H1 '从左到右 Const AW_HOR_NEGATIVE = &H2 '从右到左 Const AW_VER_POSITIVE = &H4 '从上到下 Const AW_VER_NEGATIVE = &H8 '从下到上 Const AW_CENTER = &H10 '从中间开始 Const AW_HIDE = &H10000 '卸载时使用 Const AW_ACTIVATE = &H20000 '打开时使用 Const AW_SLIDE = &H40000 '与前四种组合拉出样式 Const AW_BLEND = &H80000 '淡入淡出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 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 = &H1Private 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 Const HT_CAPTION = 2 Private Const WM_NCLBUTTONDOWN = &HA1Private Sub Form_DblClick() Unload Me End SubPrivate Sub Form_Load() AnimateWindow hwnd, 1000, AW_BLEND + AW_ACTIVATE Dim rtn As Long rtn = GetWindowLong(hwnd, GWL_EXSTYLE) rtn = rtn Or WS_EX_LAYERED SetWindowLong hwnd, GWL_EXSTYLE, rtn 'SetLayeredWindowAttributes hwnd, &H0, 0, LWA_COLORKEY '这样调用可以设置透明色,做不规则形状窗体 SetLayeredWindowAttributes hwnd, 0, 100, LWA_ALPHA '半透明窗体 End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) '这两句移动窗体 ReleaseCapture SendMessage hwnd, WM_NCLBUTTONDOWN, HT_CAPTION, 0& End SubPrivate Sub Form_Unload(Cancel As Integer) AnimateWindow hwnd, 1000, AW_VER_POSITIVE + AW_SLIDE + AW_HIDE Set Form1 = Nothing End Sub
Const AW_HOR_NEGATIVE = &H2 '从右到左
Const AW_VER_POSITIVE = &H4 '从上到下
Const AW_VER_NEGATIVE = &H8 '从下到上
Const AW_CENTER = &H10 '从中间开始
Const AW_HIDE = &H10000 '卸载时使用
Const AW_ACTIVATE = &H20000 '打开时使用
Const AW_SLIDE = &H40000 '与前四种组合拉出样式
Const AW_BLEND = &H80000 '淡入淡出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 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 = &H1Private 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 Const HT_CAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1Private Sub Form_DblClick()
Unload Me
End SubPrivate Sub Form_Load()
AnimateWindow hwnd, 1000, AW_BLEND + AW_ACTIVATE
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
'SetLayeredWindowAttributes hwnd, &H0, 0, LWA_COLORKEY '这样调用可以设置透明色,做不规则形状窗体
SetLayeredWindowAttributes hwnd, 0, 100, LWA_ALPHA '半透明窗体
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'这两句移动窗体
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HT_CAPTION, 0&
End SubPrivate Sub Form_Unload(Cancel As Integer)
AnimateWindow hwnd, 1000, AW_VER_POSITIVE + AW_SLIDE + AW_HIDE
Set Form1 = Nothing
End Sub
http://www.21code.com/codebase/?pos=down&id=472
http://www.21code.com/codebase/?pos=down&id=557
AnimateWindow hwnd, 1000, AW_HOR_POSITIVE + AW_SLIDE + AW_HIDE
Set Form1 = Nothing
End Sub