(VB.net - Visual Basic) - 打开无边框记事本 Window
(VB.net - Visual Basic) - Open Notepad Borderless Window
无边框打开记事本最简单快捷的方法是什么?
我想要的是删除您在下图中看到的蓝色标记:
我目前得到的代码[打开记事本]:
Private Sub Button_StartQuiz_Click(sender As Object, e As EventArgs) Handles Button_StartQuiz.Click
Dim vPID As Object
vPID = Shell("notepad.exe", vbNormalFocus)
End Sub
此处的结果并不完美,因此您可能需要弄乱 API 参数,但这些方面的内容(this answer 的 VB.NET 端口)可能很接近.
Dim p = Process.Start("notepad.exe")
p.WaitForInputIdle()
Dim styles As WindowStyles = GetWindowLong(p.MainWindowHandle, GWL_STYLE)
styles = styles And Not (WindowStyles.WS_CAPTION Or WindowStyles.WS_THICKFRAME Or WindowStyles.WS_MINIMIZE Or WindowStyles.WS_MAXIMIZE Or WindowStyles.WS_SYSMENU)
SetWindowLong(p.MainWindowHandle, GWL_STYLE, styles)
Dim stylesex As ExtendedWindowStyles = GetWindowLong(p.MainWindowHandle, GWL_EXSTYLE)
stylesex = stylesex And Not (ExtendedWindowStyles.WS_EX_DLGMODALFRAME Or ExtendedWindowStyles.WS_EX_CLIENTEDGE Or ExtendedWindowStyles.WS_EX_STATICEDGE)
SetWindowLong(p.MainWindowHandle, GWL_EXSTYLE, stylesex)
SetWindowPos(p.MainWindowHandle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED Or SetWindowPosFlags.SWP_NOMOVE Or SetWindowPosFlags.SWP_NOSIZE Or SetWindowPosFlags.SWP_NOZORDER Or SetWindowPosFlags.SWP_NOOWNERZORDER)
<DllImport("User32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Shared Function GetWindowLong(hWnd As IntPtr, nIndex As Int16) As Int32
End Function
<DllImport("User32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Shared Function SetWindowLong(hWnd As IntPtr, nIndex As Int16, dwNewLong As Int32) As Int32
End Function
<DllImport("User32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Shared Function SetWindowPos(hWnd As IntPtr, hWndInsertAfter As IntPtr, X As Int16, Y As Int16, cx As Int16, cy As Int16, uFlags As UInt16) As Boolean
End Function
Const GWL_STYLE As Int16 = -16
Const GWL_EXSTYLE As Int16 = -20
<Flags>
Enum WindowStyles
WS_CAPTION = &HC00000
WS_THICKFRAME = &H40000
WS_MINIMIZE = &H20000000
WS_MAXIMIZE = &H1000000
WS_SYSMENU = &H80000
End Enum
<Flags>
Enum ExtendedWindowStyles
WS_EX_DLGMODALFRAME = &h00000001
WS_EX_CLIENTEDGE = &h00000200
WS_EX_STATICEDGE = &h00020000
End Enum
<Flags>
Enum SetWindowPosFlags As UInt16
SWP_FRAMECHANGED = &h0020
SWP_NOMOVE = &h0002
SWP_NOSIZE = &h0001
SWP_NOZORDER = &h0004
SWP_NOOWNERZORDER = &h0200
End Enum
结果在我的 PC 上有点古怪(蓝色是我的桌面颜色),因为菜单仍在显示并且所有内容都已移动以占用边框占据的 space,但未展开占用额外的空间。也许不同的参数可以解决这个问题?
无边框打开记事本最简单快捷的方法是什么? 我想要的是删除您在下图中看到的蓝色标记:
我目前得到的代码[打开记事本]:
Private Sub Button_StartQuiz_Click(sender As Object, e As EventArgs) Handles Button_StartQuiz.Click
Dim vPID As Object
vPID = Shell("notepad.exe", vbNormalFocus)
End Sub
此处的结果并不完美,因此您可能需要弄乱 API 参数,但这些方面的内容(this answer 的 VB.NET 端口)可能很接近.
Dim p = Process.Start("notepad.exe")
p.WaitForInputIdle()
Dim styles As WindowStyles = GetWindowLong(p.MainWindowHandle, GWL_STYLE)
styles = styles And Not (WindowStyles.WS_CAPTION Or WindowStyles.WS_THICKFRAME Or WindowStyles.WS_MINIMIZE Or WindowStyles.WS_MAXIMIZE Or WindowStyles.WS_SYSMENU)
SetWindowLong(p.MainWindowHandle, GWL_STYLE, styles)
Dim stylesex As ExtendedWindowStyles = GetWindowLong(p.MainWindowHandle, GWL_EXSTYLE)
stylesex = stylesex And Not (ExtendedWindowStyles.WS_EX_DLGMODALFRAME Or ExtendedWindowStyles.WS_EX_CLIENTEDGE Or ExtendedWindowStyles.WS_EX_STATICEDGE)
SetWindowLong(p.MainWindowHandle, GWL_EXSTYLE, stylesex)
SetWindowPos(p.MainWindowHandle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED Or SetWindowPosFlags.SWP_NOMOVE Or SetWindowPosFlags.SWP_NOSIZE Or SetWindowPosFlags.SWP_NOZORDER Or SetWindowPosFlags.SWP_NOOWNERZORDER)
<DllImport("User32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Shared Function GetWindowLong(hWnd As IntPtr, nIndex As Int16) As Int32
End Function
<DllImport("User32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Shared Function SetWindowLong(hWnd As IntPtr, nIndex As Int16, dwNewLong As Int32) As Int32
End Function
<DllImport("User32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Shared Function SetWindowPos(hWnd As IntPtr, hWndInsertAfter As IntPtr, X As Int16, Y As Int16, cx As Int16, cy As Int16, uFlags As UInt16) As Boolean
End Function
Const GWL_STYLE As Int16 = -16
Const GWL_EXSTYLE As Int16 = -20
<Flags>
Enum WindowStyles
WS_CAPTION = &HC00000
WS_THICKFRAME = &H40000
WS_MINIMIZE = &H20000000
WS_MAXIMIZE = &H1000000
WS_SYSMENU = &H80000
End Enum
<Flags>
Enum ExtendedWindowStyles
WS_EX_DLGMODALFRAME = &h00000001
WS_EX_CLIENTEDGE = &h00000200
WS_EX_STATICEDGE = &h00020000
End Enum
<Flags>
Enum SetWindowPosFlags As UInt16
SWP_FRAMECHANGED = &h0020
SWP_NOMOVE = &h0002
SWP_NOSIZE = &h0001
SWP_NOZORDER = &h0004
SWP_NOOWNERZORDER = &h0200
End Enum
结果在我的 PC 上有点古怪(蓝色是我的桌面颜色),因为菜单仍在显示并且所有内容都已移动以占用边框占据的 space,但未展开占用额外的空间。也许不同的参数可以解决这个问题?