一段高深代码--未解

以下代码是一个关于窗体显示的代码,其目的是实现窗体最初的隐藏,但看了一遍不明所以。贴出来以后继续研究,也请各位不吝赐教。

This is the code I'm using to do that, I saw a post today that do not
require P/invoke but I havent test it yet

using System.Runtime.InteropServices;

[DllImport("user32.dll",EntryPoint="SetForegroundWindow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool MessageBeep(int type);
[DllImport("user32.dll")]
public static extern int SetWindowLong( IntPtr window, int index, int
value);
[DllImport("user32.dll")]
public static extern int GetWindowLong( IntPtr window, int index);
[DllImport("winmm.dll")]
public static extern int sndPlaySound(string lpszSoundName , int uFlags)
;


const int GWL_EXSTYLE = -20;
const int WS_EX_TOOLWINDOW = 0x00000080;
const int WS_EX_APPWINDOW = 0x00040000;

//This is the icon when there are no orders in the system
Icon normalIcon;


public Form1()
{
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);

// The Icon property sets the icon that will appear
// in the systray for this application.
notifyIcon1.Icon = normalIcon;

// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
notifyIcon1.ContextMenu = this.contextMenu1;

// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon.
notifyIcon1.Text = "the text";
notifyIcon1.Visible = true;


//Remove from the taskbar and also from alt+tab
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Visible = false;
this.ShowInTaskbar = false;

int windowStyle = GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDOW);
}

>>>>
I suggest also to the the "System.Security.SupressUnmanagedCodeSecurity"
for better performance.

So change the attributes to:
[DllImport("xxx.dll"), System.Security.SupressUnmanagedCodeSecurity]

posted on 2007-09-12 15:12  sizzle  阅读(293)  评论(0编辑  收藏  举报