从aygshell.dll,coredll引入api函数
class
WinAPI
... {
...
[DllImport("aygshell.dll")]
private static extern bool SHDoneButton(
IntPtr hWnd,
UInt32 dwState);
[DllImport("coredll.dll")]
public static extern UInt32 SetWindowLong(
IntPtr hWnd,
int nIndex,
UInt32 dwNewLong);
[DllImport("coredll.dll")]
public static extern UInt32 GetWindowLong(
IntPtr hWnd,
int nIndex);
... {
...
[DllImport("aygshell.dll")]
private static extern bool SHDoneButton(
IntPtr hWnd,
UInt32 dwState);
[DllImport("coredll.dll")]
public static extern UInt32 SetWindowLong(
IntPtr hWnd,
int nIndex,
UInt32 dwNewLong);
[DllImport("coredll.dll")]
public static extern UInt32 GetWindowLong(
IntPtr hWnd,
int nIndex);
[DllImport("coredll.dll")]
public static extern IntPtr GetForegroundWindow();
...
}
public static extern IntPtr GetForegroundWindow();
...
}
class
WinAPI
... {
...
public const UInt32 SHDB_SHOW = 0x0001;
public const UInt32 SHDB_HIDE = 0x0002;
public const int GWL_STYLE = -16;
public const UInt32 WS_NONAVDONEBUTTON = 0x00010000;
public static void HideDoneButton(IntPtr hWnd)
...{
SHDoneButton(hWnd, SHDB_HIDE);
}
public static void HideXButton(IntPtr hWnd)
...{
UInt32 dwStyle = GetWindowLong(hWnd, GWL_STYLE);
if ((dwStyle & WS_NONAVDONEBUTTON) == 0)
SetWindowLong(hWnd, GWL_STYLE, dwStyle | WS_NONAVDONEBUTTON);
}
...
}
... {
...
public const UInt32 SHDB_SHOW = 0x0001;
public const UInt32 SHDB_HIDE = 0x0002;
public const int GWL_STYLE = -16;
public const UInt32 WS_NONAVDONEBUTTON = 0x00010000;
public static void HideDoneButton(IntPtr hWnd)
...{
SHDoneButton(hWnd, SHDB_HIDE);
}
public static void HideXButton(IntPtr hWnd)
...{
UInt32 dwStyle = GetWindowLong(hWnd, GWL_STYLE);
if ((dwStyle & WS_NONAVDONEBUTTON) == 0)
SetWindowLong(hWnd, GWL_STYLE, dwStyle | WS_NONAVDONEBUTTON);
}
...
}
自定义重绘事件
public
class
MyForm : System.Windows.Forms.Form
... {
private void MyForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
...{
... {
private void MyForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
...{
IntPtr hWnd =GetForegroundWindow();
WinAPI.HideDoneButton(hWnd);
WinAPI.HideXButton(hWnd);
}
}
WinAPI.HideDoneButton(hWnd);
WinAPI.HideXButton(hWnd);
}
}