예제 #1
0
        public void PromoteTrayItems(string exeToPromote)
        {
            var instance = new TrayNotify();

            try {
                var items  = default(List <NOTIFYITEM>);
                var legacy = useLegacyInterface();

                if (legacy)
                {
                    items = getTrayItemsWin7(instance);
                }
                else
                {
                    items = getTrayItems(instance);
                }

                exeToPromote = exeToPromote.ToLowerInvariant();

                for (int i = 0; i < items.Count; i++)
                {
                    var item    = items[i];
                    var exeName = item.exe_name.ToLowerInvariant();

                    // Ignore items not created by the specified EXE.
                    if (!exeName.Contains(exeToPromote))
                    {
                        continue;
                    }

                    // Ignore items that are not in the default state. We shouldn't overwrite the
                    // user's preference if it is to never show an item, and we don't need to overwrite
                    // the user's preference if it is to always show an item.
                    if (item.preference != NOTIFYITEM_PREFERENCE.PREFERENCE_SHOW_WHEN_ACTIVE)
                    {
                        continue;
                    }
                    item.preference = NOTIFYITEM_PREFERENCE.PREFERENCE_SHOW_ALWAYS;

                    var writable = NOTIFYITEM_Writable.fromNotifyItem(item);
                    if (legacy)
                    {
                        var notifier = (ITrayNotifyWin7)instance;
                        notifier.SetPreference(ref writable);
                    }
                    else
                    {
                        var notifier = (ITrayNotify)instance;
                        notifier.SetPreference(ref writable);
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to promote Tray icon: " + ex.ToString());
            } finally {
                Marshal.ReleaseComObject(instance);
            }
        }
예제 #2
0
        public void PromoteTrayItem(string exeToPromote)
        {
            var instance = new TrayNotify();

            try {
                var items  = default(List <NOTIFYITEM>);
                var legacy = useLegacyInterface();

                if (legacy)
                {
                    items = getTrayItemsWin7(instance);
                }
                else
                {
                    items = getTrayItems(instance);
                }

                exeToPromote = exeToPromote.ToLowerInvariant();

                for (int i = 0; i < items.Count; i++)
                {
                    var item    = items[i];
                    var exeName = item.exe_name.ToLowerInvariant();

                    if (!exeName.Contains(exeToPromote))
                    {
                        continue;
                    }

                    if (item.preference != NOTIFYITEM_PREFERENCE.PREFERENCE_SHOW_WHEN_ACTIVE)
                    {
                        continue;
                    }
                    item.preference = NOTIFYITEM_PREFERENCE.PREFERENCE_SHOW_ALWAYS;

                    var writable = NOTIFYITEM_Writable.fromNotifyItem(item);
                    if (legacy)
                    {
                        var notifier = (ITrayNotifyWin7)instance;
                        notifier.SetPreference(ref writable);
                    }
                    else
                    {
                        var notifier = (ITrayNotify)instance;
                        notifier.SetPreference(ref writable);
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to promote Tray icon: " + ex.ToString());
            } finally {
                Marshal.ReleaseComObject(instance);
            }
        }
예제 #3
0
        public void PromoteTrayItem(string exeToPromote)
        {
            TrayNotify instance = new TrayNotify();

            try
            {
                List <NOTIFYITEM> list = null;
                bool flag = useLegacyInterface();
                list = !flag?getTrayItems(instance) : getTrayItemsWin7(instance);

                exeToPromote = exeToPromote.ToLowerInvariant();
                for (int i = 0; i < list.Count; i++)
                {
                    NOTIFYITEM item = list[i];
                    if (item.exe_name.ToLowerInvariant().Contains(exeToPromote) && (item.preference == NOTIFYITEM_PREFERENCE.PREFERENCE_SHOW_WHEN_ACTIVE))
                    {
                        item.preference = NOTIFYITEM_PREFERENCE.PREFERENCE_SHOW_ALWAYS;
                        if (flag)
                        {
                            ((ITrayNotifyWin7)instance).SetPreference(ref NOTIFYITEM_Writable.fromNotifyItem(item));
                        }
                        else
                        {
                            ((ITrayNotify)instance).SetPreference(ref NOTIFYITEM_Writable.fromNotifyItem(item));
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Failed to promote Tray icon: " + exception.ToString());
            }
            finally
            {
                Marshal.ReleaseComObject(instance);
            }
        }