Exemple #1
0
        // ========================================
        // method
        // ========================================
        private ContextMenuStrip CreateNotifyIconContextMenu()
        {
            var items = new List <ToolStripItem>(16);

            var newMemo = new ToolStripMenuItem();

            newMemo.Text   = "ノートを作成(&N)";
            newMemo.Click += (sender, e) => {
                CreateMemo();
            };
            items.Add(newMemo);

            var newFusenMemo = new ToolStripMenuItem();

            newFusenMemo.Text   = "付箋ノートを作成(&F)";
            newFusenMemo.Click += (sender, e) => {
                CreateFusenMemo();
            };
            items.Add(newFusenMemo);

            var clipMemo = new ToolStripMenuItem();

            clipMemo.Text   = "ノートにクリップ(&C)";
            clipMemo.Click += (sender, e) => {
                var mainForm = _app.MainForm;
                var hWnd     = User32PI.GetWindow(
                    mainForm.Handle,
                    GetWindowCmd.GW_HWNDFIRST
                    );
                hWnd = User32Util.GetNextWindow(
                    hWnd,
                    handle => {
                    if (User32PI.IsWindowVisible(handle) && !User32Util.IsOwnedWindow(handle))
                    {
                        var cname = User32Util.GetWindowClassName(handle);
                        return
                        (!string.Equals(cname, "Shell_TrayWnd", StringComparison.OrdinalIgnoreCase) &&
                         !string.Equals(cname, "NotifyIconOverflowWindow", StringComparison.OrdinalIgnoreCase));
                    }
                    else
                    {
                        return(false);
                    }
                }
                    );

                var oldTopMost = mainForm.TopMost;
                mainForm.TopMost = false;
                if (hWnd != IntPtr.Zero)
                {
                    User32Util.ActivateWindow(hWnd);
                    Thread.Sleep(1000);
                }
                _app.ClipAndCreateMemo();
                mainForm.TopMost = oldTopMost;
            };
            items.Add(clipMemo);

            var capture = new ToolStripMenuItem();

            capture.Text   = "画面を取り込み(&D)";
            capture.Click += (sender, e) => {
                Thread.Sleep(500);
                _app.CaptureAndCreateMemo();
            };
            items.Add(capture);

            items.Add(new ToolStripSeparator());

            var searchMemo = new ToolStripMenuItem();

            searchMemo.Text   = "ノートを検索(&S)";
            searchMemo.Click += (sender, e) => {
                _app.ShowMainForm();
                _app.ActivateMainForm();
                var form = _app.MainForm;
                if (form != null)
                {
                    form.FocusConditionTextBox();
                }
            };
            items.Add(searchMemo);

            var activate = new ToolStripMenuItem();

            activate.Text   = "アクティブにする(&A)";
            activate.Click += (sender, e) => {
                ShowMainForm();
            };
            items.Add(activate);

            var showAllFusens = new ToolStripMenuItem();

            showAllFusens.Text   = "付箋ノートを表示(&F)";
            showAllFusens.Click += (sender, e) => {
                ShowFusenForms(false);
            };
            items.Add(showAllFusens);

            items.Add(new ToolStripSeparator());

            var action = new ToolStripMenuItem();

            action.Text = "アイコンの動作(&A)";
            items.Add(action);

            {
                var click = new ToolStripMenuItem();
                click.Text = "クリック(&C)";
                action.DropDown.Items.Add(click);
                InitClickSetting(click);
            }
            {
                var dclick = new ToolStripMenuItem();
                dclick.Text = "ダブルクリック(&D)";
                action.DropDown.Items.Add(dclick);

                InitDoubleClickSetting(dclick);
            }

            items.Add(new ToolStripSeparator());

            var exitItem = new ToolStripMenuItem();

            exitItem.Text   = "終了(&X)";
            exitItem.Click += (sender, e) => {
                _app.Exit();
            };
            items.Add(exitItem);

            var ret = new ContextMenuStrip();

            ret.SuspendLayout();
            ret.Items.AddRange(items.ToArray());
            ret.ResumeLayout();
            return(ret);
        }