2008年1月20日星期日

无边框窗体系统菜单

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace NoBorderForm
...{
public partial class NoBorder : Form
...{
[DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
public static extern int GetWindowLong(HandleRef hWnd, int nIndex);

[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);

public NoBorder()
...{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
...{
int WS_SYSMENU = 0x00080000;

this.FormBorderStyle = FormBorderStyle.None;

int windowLong = (GetWindowLong(new HandleRef(this, this.Handle), -16));
SetWindowLong(new HandleRef(this, this.Handle), -16, windowLong | WS_SYSMENU);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0010)
{//屏蔽关闭消息
this.Hide();
}
else
{
base.WndProc(ref m);
}
}
}
}

Trackback:http://blog.csdn.net/hbxtlhx/archive/2007/08/01/1721061.aspx

没有评论: