请问各位大哥,在vb中如何实现窗体的渐隐,就像瑞星启动画面一样,请各位大哥指教,谢谢

解决方案 »

  1.   

    我们还是来看一下在VB6中的实现,VB6中实现(借助API函数SetLayeredWindowAttributes)  使用这个函数,可以轻松的控制窗体的透明度。按照微软的要求,透明窗体在创建时应使用WS_EX_LAYERED参数(用CreateWindowEx),或者在创建后设置该参数(用SetWindowLong),我选用后者。SetLayeredWindowAttributes函数,其中hwnd是透明窗体的句柄,crKey为颜色值,bAlpha是透明度,取值范围是[0,255],dwFlags是透明方式,可以取两个值:当取值为LWA_ALPHA时,crKey参数无效,bAlpha参数有效;当取值为LWA_COLORKEY时,bAlpha参数有效而窗体中的所有颜色为crKey的地方将变为透明。    Const LWA_COLORKEY = &H1    Const LWA_ALPHA = &H2    Const GWL_EXSTYLE = (-20)    Const WS_EX_LAYERED = &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 Sub Form_Load()        Dim Ret As Long        'Set the window style to 'Layered'        Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)        Ret = Ret Or WS_EX_LAYEREDSetWindowLong Me.hWnd, GWL_EXSTYLE, Ret        'Set the opacity of the layered window to 128        '我们可以设置这个数值来控制透明程度        SetLayeredWindowAttributes Me.hWnd, 0, 128, LWA_ALPHA    End Sub