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]

  • 相关阅读:
    卖家必须了解的库存数据,亚马逊库存报告都帮你整理好了
    Genymotion 无法安装 APK 解决方案
    这张系统架构图画的漂亮!
    IT项目风险大全
    ElasticSearch是一个基于Lucene的搜索服务器
    商业模式的定义、商业模式的好坏
    如何实现互联网+业务与IT的融合
    UBUNTU PHP 版本切换
    Ubuntu为PHP安装SOAP扩展
    实现Linux下的ls -l命令
  • 原文地址:https://www.cnblogs.com/sizzle/p/890768.html
Copyright © 2011-2022 走看看