zoukankan      html  css  js  c++  java
  • 一段高深代码未解

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

    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]

  • 相关阅读:
    微信小程序开发学习--页面事件和数据绑定
    检测小程序版本更新提示
    vue-cli脚手架
    链表中倒数第K个结点
    调整数组顺序使奇数位于偶数前面
    数值的整数次方(十二)
    二进制中1的个数(十一)
    覆盖矩形(十)
    变态跳台阶(九)
    跳台阶(八)
  • 原文地址:https://www.cnblogs.com/sizzle/p/890768.html
Copyright © 2011-2022 走看看