I think it always makes code more understandable if you take the time to declare enums and structures. For example, you cold define an enum for the DWMATTRIBUTES and other variables specified in the documentation for the DwmSetAttributes function. You can also take advantage of function overloading and default parameters to simplify/clarify the code.
For example,
Public Enum DWMWINDOWATTRIBUTE As Integer
DWMWA_NCRENDERING_ENABLED = 1 ' [get] Is non-client rendering enabled/disabled
DWMWA_NCRENDERING_POLICY ' [set] DWMNCRENDERINGPOLICY - Non-client rendering policy
DWMWA_TRANSITIONS_FORCEDISABLED ' [set] Potentially enable/forcibly disable transitions
DWMWA_ALLOW_NCPAINT ' [set] Allow contents rendered In the non-client area To be visible On the DWM-drawn frame.
DWMWA_CAPTION_BUTTON_BOUNDS ' [get] Bounds Of the caption button area In window-relative space.
DWMWA_NONCLIENT_RTL_LAYOUT ' [set] Is non-client content RTL mirrored
DWMWA_FORCE_ICONIC_REPRESENTATION ' [set] Force this window To display iconic thumbnails.
DWMWA_FLIP3D_POLICY ' [set] Designates how Flip3D will treat the window.
DWMWA_EXTENDED_FRAME_BOUNDS ' [get] Gets the extended frame bounds rectangle In screen space
DWMWA_HAS_ICONIC_BITMAP ' [set] Indicates an available bitmap When there Is no better thumbnail representation.
DWMWA_DISALLOW_PEEK ' [set] Don't invoke Peek on the window.
DWMWA_EXCLUDED_FROM_PEEK ' [set] LivePreview exclusion information
DWMWA_CLOAK ' [set] Cloak Or uncloak the window
DWMWA_CLOAKED ' [get] Gets the cloaked state Of the window
DWMWA_FREEZE_REPRESENTATION ' [set] BOOL, Force this window To freeze the thumbnail without live update
DWMWA_PASSIVE_UPDATE_MODE ' [set] BOOL, Updates the window only When desktop composition runs For other reasons
DWMWA_USE_HOSTBACKDROPBRUSH ' [set] BOOL, Allows the use Of host backdrop brushes For the window.
DWMWA_USE_IMMERSIVE_DARK_MODE = 20 ' [set] BOOL, Allows a window To either use the accent color, Or dark according To the user Color Mode preferences.
DWMWA_WINDOW_CORNER_PREFERENCE = 33 ' [set] WINDOW_CORNER_PREFERENCE, Controls the policy that rounds top-level window corners
DWMWA_BORDER_COLOR ' [set] COLORREF, The color Of the thin border around a top-level window
DWMWA_CAPTION_COLOR ' [set] COLORREF, The color Of the caption
DWMWA_TEXT_COLOR ' [set] COLORREF, The color Of the caption text
DWMWA_VISIBLE_FRAME_BORDER_THICKNESS ' [get] UINT, width Of the visible border around a thick frame window
DWMWA_SYSTEMBACKDROP_TYPE ' [get, Set] SYSTEMBACKDROP_TYPE, Controls the system-drawn backdrop material Of a window, including behind the non-client area.
DWMWA_REDIRECTIONBITMAP_ALPHA ' [set] BOOL, GDI redirection bitmap containspremultiplied alpha
DWMWA_LAST
End Enum
Public Enum WINDOW_CORNER_PREFERENCE As Integer
DWMWCP_DEFAULT = 0
DWMWCP_DONOTROUND = 1
DWMWCP_ROUND = 2
DWMWCP_ROUNDSMALL = 3
End Enum
and also
<DllImport("dwmapi.dll", ExactSpelling:=True, SetLastError:=False)>
Public Shared Function DwmSetWindowAttribute(hwnd As IntPtr,
dwAttribute As DWMWINDOWATTRIBUTE,
<MarshalAs(UnmanagedType.Bool)>
ByRef attribute As Boolean,
Optional cbattribute As Integer = 4) As Integer
End Function
<DllImport("dwmapi.dll", ExactSpelling:=True, SetLastError:=False)>
Public Shared Function DwmSetWindowAttribute(hwnd As IntPtr,
dwAttribute As DWMWINDOWATTRIBUTE,
ByRef attribute As Integer,
Optional cbattribute As Integer = 4) As Integer
End Function
Many of the attributes are set by passing the address of a Win32 BOOL. So the first overload allows you to specify a VB True/False. Since its marshaled to unmanaged code as a 4 byte integer the size uses a default value of 4 bytes. No need to call Marshal.SizeOF for every function call. Same for any other call that sets a 4 byte integer value. If circumstances require you can specify the required size of the passed data in the call's cbattribute parameter instead of accepting the default.