好,亚历克斯从来没有与代码阐述,以及至少它不是一个插件的即插即用解决方案,但仍这主要归功于他......这除非您使用“SetParent”将它放入某种容器(例如表单或面板)中,否则就是一种错误。只是认为我会分享结果。
的Visual Basic:
Option Strict On
Public Class Form1
Const WS_BORDER As Integer = 8388608
Const WS_DLGFRAME As Integer = 4194304
Const WS_CAPTION As Integer = WS_BORDER Or WS_DLGFRAME
Const WS_SYSMENU As Integer = 524288
Const WS_THICKFRAME As Integer = 262144
Const WS_MINIMIZE As Integer = 536870912
Const WS_MAXIMIZEBOX As Integer = 65536
Const GWL_STYLE As Integer = -16&
Const GWL_EXSTYLE As Integer = -20&
Const WS_EX_DLGMODALFRAME As Integer = &H1L
Const SWP_NOMOVE As Integer = &H2
Const SWP_NOSIZE As Integer = &H1
Const SWP_FRAMECHANGED As Integer = &H20
Const MF_BYPOSITION As UInteger = &H400
Const MF_REMOVE As UInteger = &H1000
Declare Auto Function GetWindowLong Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
Declare Auto Function SetWindowLong Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Declare Auto Function SetWindowPos Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean
Public Sub MakeExternalWindowBorderless(ByVal MainWindowHandle As IntPtr)
Dim Style As Integer
Style = GetWindowLong(MainWindowHandle, GWL_STYLE)
Style = Style And Not WS_CAPTION
Style = Style And Not WS_SYSMENU
Style = Style And Not WS_THICKFRAME
Style = Style And Not WS_MINIMIZE
Style = Style And Not WS_MAXIMIZEBOX
SetWindowLong(MainWindowHandle, GWL_STYLE, Style)
Style = GetWindowLong(MainWindowHandle, GWL_EXSTYLE)
SetWindowLong(MainWindowHandle, GWL_EXSTYLE, Style Or WS_EX_DLGMODALFRAME)
SetWindowPos(MainWindowHandle, New IntPtr(0), 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_FRAMECHANGED)
End Sub
End Class
升C(C#)
using System.Runtime.InteropServices;
public class Form1
{
const int WS_BORDER = 8388608;
const int WS_DLGFRAME = 4194304;
const int WS_CAPTION = WS_BORDER | WS_DLGFRAME;
const int WS_SYSMENU = 524288;
const int WS_THICKFRAME = 262144;
const int WS_MINIMIZE = 536870912;
const int WS_MAXIMIZEBOX = 65536;
const int GWL_STYLE = -16L;
const int GWL_EXSTYLE = -20L;
const int WS_EX_DLGMODALFRAME = 0x1L;
const int SWP_NOMOVE = 0x2;
const int SWP_NOSIZE = 0x1;
const int SWP_FRAMECHANGED = 0x20;
const uint MF_BYPOSITION = 0x400;
const uint MF_REMOVE = 0x1000;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
public void MakeExternalWindowBorderless(IntPtr MainWindowHandle)
{
int Style = 0;
Style = GetWindowLong(MainWindowHandle, GWL_STYLE);
Style = Style & !WS_CAPTION;
Style = Style & !WS_SYSMENU;
Style = Style & !WS_THICKFRAME;
Style = Style & !WS_MINIMIZE;
Style = Style & !WS_MAXIMIZEBOX;
SetWindowLong(MainWindowHandle, GWL_STYLE, Style);
Style = GetWindowLong(MainWindowHandle, GWL_EXSTYLE);
SetWindowLong(MainWindowHandle, GWL_EXSTYLE, Style | WS_EX_DLGMODALFRAME);
SetWindowPos(MainWindowHandle, new IntPtr(0), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
}
}
再次感谢你亚历克斯
'公共静态INT WS_CAPTION = WS_BORDER | WS_DLGFRAME;'不正确,因为WS_DLGFRAME不是标题的一部分。参考:http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx – 2014-12-10 15:23:08