|
让窗口变成 Windows 新版白色窗口(仅适用 Windows 10 及以上的版本)
代码:
Option Explicit
Private Const MF_BYCOMMAND As Long = &H0&
Private Const SC_SIZE As Long = &HF000&
Private Const SC_MAXIMIZE As Long = &HF030&
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Type margins
cxLeftWidth As Long
cxRightWidth As Long
cyTopHeight As Long
cyBottomHeight As Long
End Type
Private Declare Function DwmExtendFrameIntoClientArea Lib "dwmapi.dll" (ByVal hwnd As Long, ByRef pMarInset As margins) As Long
Private Sub Form_Load()
Me.Icon = LoadPicture("")
'设置窗口样式为无边框
Me.BorderStyle = vbBSNone
'创建一个Margins结构体来指定窗口边框宽度,这里设为5像素
Dim margins As margins
margins.cxLeftWidth = 5
margins.cxRightWidth = 5
margins.cyTopHeight = 5
margins.cyBottomHeight = 5
'调用DwmExtendFrameIntoClientArea函数来扩展窗口边框,并将颜色设为红色
Call DwmExtendFrameIntoClientArea(Me.hwnd, margins)
Me.Refresh '强制重绘窗口
' 去掉系统菜单栏的大小选项
Dim hMenu As Long
hMenu = GetSystemMenu(Me.hwnd, False)
Call RemoveMenu(hMenu, SC_SIZE, MF_BYCOMMAND)
Call RemoveMenu(hMenu, SC_MAXIMIZE, MF_BYCOMMAND)
' 设置窗口BorderStyle属性为2
Me.BorderStyle = 2
Me.BackColor = &H8000000E
Me.Height = 7791 ' reset the height if user tries to resize the form
Me.Width = 11235 ' reset the width if user tries to resize the form
End Sub
Private Sub Form_Resize()
If Me.WindowState = 0 Then
Me.Height = 7791 ' reset the height if user tries to resize the form
Me.Width = 11235 ' reset the width if user tries to resize the form
End If
If Me.WindowState = 2 Then
Me.Height = 7791 ' reset the height if user tries to resize the form
Me.Width = 11235 ' reset the width if user tries to resize the form
End If
End Sub
|
|