Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

pinvoke - VB.NET disable fade-in for forms

I want to disable the form fade-in effect for a window. I think I found the right function

<DllImport("dwmapi.dll", PreserveSig:=True)> _
Private Shared Function DwmSetWindowAttribute(ByVal hwnd As IntPtr, ByVal attr As Integer, ByRef attrValue As Integer, ByVal attrSize As Integer) As Integer
End Function

and the flag should be

DWMWA_TRANSITIONS_FORCEDISABLED

But I don't know how to call it from VB.NET. This is what I have so far:

Imports System.Runtime.InteropServices

Public Class Form1

Public Enum DWMWINDOWATTRIBUTE
    DWMWA_ALLOW_NCPAINT = 4
    DWMWA_CAPTION_BUTTON_BOUNDS = 5
    DWMWA_FLIP3D_POLICY = 8
    DWMWA_FORCE_ICONIC_REPRESENTATION = 7
    DWMWA_LAST = 9
    DWMWA_NCRENDERING_ENABLED = 1
    DWMWA_NCRENDERING_POLICY = 2
    DWMWA_NONCLIENT_RTL_LAYOUT = 6
    DWMWA_TRANSITIONS_FORCEDISABLED = 3
End Enum

<DllImport("dwmapi.dll", PreserveSig:=True)> _
Private Shared Function DwmSetWindowAttribute(ByVal hwnd As IntPtr, ByVal attr As Integer, ByRef attrValue As Integer, ByVal attrSize As Integer) As Integer
End Function

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Environment.OSVersion.Version.Major >= 6 Then
        DwmSetWindowAttribute Me.Handle, 'here I don't know how to go on...
    End If
End Sub
End Class

Thank you very much for the help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The documentation for DWMWA_TRANSITIONS_FORCEDISABLED reads:

Use with DwmSetWindowAttribute. Enables or forcibly disables DWM transitions. The pvAttribute parameter points to a value of TRUE to disable transitions or FALSE to enable transitions.

The macros TRUE and FALSE are declared as:

#define FALSE 0
#define TRUE  1

So you need to pass 1 for the attrValue parameter.

The boolean type that Windows uses natively is BOOL. This is declared like this:

typedef int BOOL;

And since sizeof(int) is 4, the attrSize you need to pass is 4.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...