2011年12月12日星期一

[分享][VB6] 让窗体有阴影的代码

环境:Visual Basic 6

所需要的控件:Command1

在Form1中添加一个 Command 控件

然后在Form1中添加以下代码:

'代码开始
Option Explicit

Private Declare Function 
GetClassLong Lib "user32" Alias "GetClassLongA(ByVal hwnd As Long, ByVal nIndex As LongAs Long

Private Declare Function 
SetClassLong Lib "user32" Alias "SetClassLongA(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As LongAs Long

Const 
GCL_STYLE = ( - 26)

Const CS_DROPSHADOW As Long 131072



Private Sub Command1_Click()

    
pRemoveDropShadowStyle Me.hwnd

End Sub

Private Sub 
Form_Load()

    
Command1.Move 2730, 2205, 1000, 500



    Command1.Caption "Remove Shodow"


    pSetDropShadowStyle Me.hwnd


End Sub

Public Sub 
pSetDropShadowStyle(ByVal hwnd As Long)

    
If (GetClassLong(hwnd, GCL_STYLEAnd CS_DROPSHADOW) = Then

        
SetClassLong hwnd, GCL_STYLE, GetClassLong(hwnd, GCL_STYLEor CS_DROPSHADOW



    End If

End Sub

Public Sub 
pRemoveDropShadowStyle(ByVal hwnd As Long)

    
If GetClassLong(hwnd, GCL_STYLEAnd CS_DROPSHADOW Then

        
Me.Hide



        SetClassLong hwnd, GCL_STYLE, GetClassLong(hwnd, GCL_STYLEXor CS_DROPSHADOW


        Me.Show


    End If

End Sub
 

'代码结束


效果图:

没有评论:

发表评论