• 一段高深代码未解


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

    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]

  • 相关阅读:
    前端css实现最基本的时间轴
    前端css实现最基本的时间轴
    那些年遇见的奇葩编程书籍封面
    那些年遇见的奇葩编程书籍封面
    2018年国内就业薪资高的7大编程语言排行
    乡愁
    乡愁
    微光系列之青春无敌美少女
    1287 矩阵乘法
    一些关于DP的知识
  • 原文地址:https://www.cnblogs.com/sizzle/p/890768.html
Copyright © 2020-2023  润新知