如果用自带的form,必须show后再hide,不是很好用,用以下代码即可。
public class NotifierNativeWindow : NativeWindow
{
const string WindowName = "MessageOnlyWindow";
const int WM_USER = 0x0400;
const int WM_MYMSG = WM_USER + 1;
public NotifierNativeWindow()
{
CreateParams cp = new CreateParams();
cp.Style = 0;
cp.ExStyle = 0;
cp.ClassStyle = 0;
cp.Caption = WindowName;
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
cp.Parent = (IntPtr)(-3);
CreateHandle(cp);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_MYMSG + 1)
{
return;
}
base.WndProc(ref m);
}
}