惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - 许明会

异步编程,采用WorkgroupWorker,async和await关键字 OCR图像识别技术-Asprise OCR 关于委托,事件和类的设计准则 JavaScript能干什么? C#泛型代理、泛型接口、泛型类型、泛型方法 Delegate, Method as Parameter. DES对称性加密 利用委托实现异步调用 通过Windows组策略限制证书组织流氓软件的安装运行 枚举\位域\结构综合实验 - 许明会 - 博客园 public static void Invoke (Action action) C#的互操作性:缓冲区、结构、指针 SQLServer异步调用,批量复制 Python体验(10)-图形界面之计算器 Python体验(09)-图形界面之Pannel和Sizer Python体验(08)-图形界面之工具栏和状态栏 Python体验(07)-图形界面之菜单 C#利用WIN32实现按键注册 Javascript猜数字游戏
C#编写WIN32系统托盘程序
许明会 · 2016-03-25 · via 博客园 - 许明会

基本功能概述:

  1. 程序运行后驻留系统托盘,左键呼出,右键退出。后续可加右键菜单。
  2. 注册系统案件WIN+F10,呼出程序。
  3. 重写系统消息,最小化和关闭按钮隐藏程序
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public enum HotkeyModifiers
{
    Alt = 1,
    Control = 2,
    Shift = 4,
    Win = 8
}

public class MyForm:Form
{
    [DllImport ("user32.dll")]
    private static extern bool RegisterHotKey (IntPtr hWnd, int id, int modifiers, Keys vk);

    [DllImport ("user32.dll")]
    private static extern bool UnregisterHotKey (IntPtr hWnd, int id);

    const int WM_HOTKEY = 0x312;
    const int WM_SYSCOMMAND = 0X112;
    const int SC_MAXMIZE = 0xf030;
    const int SC_MINMIZE = 0xf020;
    const int SC_CLOSE = 0xf060;

    public MyForm ()
    {
        NotifyIcon ni = new NotifyIcon (){ Icon = this.Icon, Visible = true };
        //RegisterHotKey
        bool bOK = RegisterHotKey (this.Handle, 0, (int)HotkeyModifiers.Win, Keys.F10);

        this.Closing += delegate {
            UnregisterHotKey (this.Handle, 0);
        };

        ni.MouseDown += (sender, e) => {
            if (e.Button == MouseButtons.Left) {
                this.Activate ();
                this.Visible = true;
            }
            if (e.Button == MouseButtons.Right) {
                if (DialogResult.Yes==MessageBox.Show("Quit? Realy?","Quit",MessageBoxButtons.YesNo)) {
                    this.Close ();
                }
            }
        };
    }

    //WndProc
    protected override void WndProc (ref Message m)
    {
        switch (m.Msg) {
        case WM_SYSCOMMAND:
            int code = m.WParam.ToInt32 ();
            if (code == SC_CLOSE || code == SC_MINMIZE) {
                this.Visible = false;
                return;//Must Prevent WndProc
            }
            break; //others, such as SC_MAXMIZE must in WndProc.
        case WM_HOTKEY:
            this.Text = DateTime.Now.ToString ();
            this.Activate ();
            this.Visible = true;
            break;
        }
        base.WndProc (ref m);
    }
}

public class MyClass
{
    public static void Main ()
    {
        MyForm form = new MyForm ();
        Application.Run (form);
    }
}