AnimateWindow是一个窗口打开和关闭时产生动画效果的新函数,
声明:
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte,dwFlags As Long) As Long
注释:具体可以使用的常量及其用法
Const LWA_ALPHA=&H2 注释:表示把窗体设置成半透明样式
Const LWA_COLORKEY=&H1 注释:表示不显示窗体中的透明色
|
程序代码
修改窗体的式样,在窗体中加入:
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
Return cp
End Get
End Property
设置透明度:
1. | . |
2. |
|
3. |
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 GWL_EXSTYLE = (-20)
Public Const LWA_ALPHA = &H2
Public Const LWA_COLORKEY = &H1
SetLayeredWindowAttributes(Handle, 1, 0, Win32.ULW_ALPHA)
第二种使用方法
SetLayeredWindowAttributes (Me.Handle, &H0, 0, LWA_COLORKEY )
注释:表明不显示窗体中的透明色
注释:而第二个参数表示透明色为黑色,并且你可以用RGB函数来指定颜色
微软例子:http://support.microsoft.com/default.aspx?scid=kb;en-us;249341
Back to the top
1. | Create a new Standard EXE project in Visual Basic. Form1 is created by default. |
2. | Add the following code to the General Declarations section of Form1:
|
3. | Run the example program by pressing the F5 key. The form should look like a normal Visual Basic window. However, windows that are lower in the Z order should be partially visible through the window. It is also possible to make mouse events go through to the lower windows by changing the preceding code line to: However, the form does not remain topmost if another form is activated. See the "Reference" section for information on how to create a form that remains on top. |