当前位置: 首页>>代码示例>>C#>>正文


C# NotifyIcon.GetType方法代码示例

本文整理汇总了C#中System.Windows.Forms.NotifyIcon.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# NotifyIcon.GetType方法的具体用法?C# NotifyIcon.GetType怎么用?C# NotifyIcon.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.NotifyIcon的用法示例。


在下文中一共展示了NotifyIcon.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SysTrayApp

        public SysTrayApp()
        {
            // create vhdpath directory, if it doesnt exist
            String localVhdBasePath = Path.Combine(Application.StartupPath, Options.vhdlocalpath);
            if (!Directory.Exists(localVhdBasePath))
            {
                Directory.CreateDirectory(localVhdBasePath);
            }
            gamesLibrary = new GamesLibrary(new VhdStorage(new DirectoryInfo(localVhdBasePath)));

            lobby = new Lobby();
            lobby.Listen();

            /******************************************************************************************
             * Announce Own Games every 10s
             *****************************************************************************************/
            this.announcingTimer = new Timer();
            this.announcingTimer.Interval = Options.ANNOUNCING_INTERVAL;
            this.announcingTimer.Tick += delegate(object o, EventArgs e) {
                lobby.Send(new AnnouncementMessage(new UserInfo(Options.nickname), gamesLibrary.GetGameNames()));
            };
            this.announcingTimer.Start();

            /******************************************************************************************
             * GUI Init
             *****************************************************************************************/
            trayIcon = new NotifyIcon();
            trayIcon.Text = "vhdgamer";
            trayIcon.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);

            // Add menu to tray icon and show it.
            trayMenu = new ContextMenu();
            trayMenu.Popup += delegate { updateContextMenu(); };

            trayIcon.ContextMenu = trayMenu;
            trayIcon.MouseClick += new MouseEventHandler(trayIcon_Click);
            trayIcon.Visible = true;

            updateContextMenu();

            // info for user (if click on tooltop -> show menu)
            trayIcon.ShowBalloonTip(1000, "vhdgamer", "Click here to start or download games...", ToolTipIcon.Info);
            trayIcon.BalloonTipClicked += delegate { trayIcon.GetType().InvokeMember("ShowContextMenu", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, trayIcon, null); };
        }
开发者ID:noproblan,项目名称:npl-vhdgamer,代码行数:44,代码来源:SysTrayApp.cs

示例2: GetNotifyIconRectWindows7

        /// <summary>
        /// Returns a rectangle representing the location of the specified NotifyIcon. (Windows 7+.)
        /// </summary>
        /// <param name="notifyicon">The NotifyIcon whose location should be returned.</param>
        /// <returns>The location of the specified NotifyIcon. Null if the location could not be found.</returns>
        public static Rect? GetNotifyIconRectWindows7(NotifyIcon notifyicon)
        {
            if (Compatibility.CurrentWindowsVersion != Compatibility.WindowsVersion.Windows7Plus)
                throw new PlatformNotSupportedException("This method can only be used under Windows 7 or later. Please use GetNotifyIconRectangleLegacy() if you use an earlier operating system.");

            // get notify icon id
            FieldInfo idFieldInfo = notifyicon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance);
            int iconid = (int)idFieldInfo.GetValue(notifyicon);

            // get notify icon hwnd
            IntPtr iconhandle;
            try
            {
                FieldInfo windowFieldInfo = notifyicon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance);
                System.Windows.Forms.NativeWindow nativeWindow = (System.Windows.Forms.NativeWindow)windowFieldInfo.GetValue(notifyicon);
                iconhandle = nativeWindow.Handle;
                if (iconhandle == null || iconhandle == IntPtr.Zero)
                    return null;
            } catch {
                return null;
            }

            NativeMethods.RECT rect = new NativeMethods.RECT();
            NativeMethods.NOTIFYICONIDENTIFIER nid = new NativeMethods.NOTIFYICONIDENTIFIER()
            {
                hWnd = iconhandle,
                uID = (uint)iconid
            };
            nid.cbSize = (uint)Marshal.SizeOf(nid);

            int result = NativeMethods.Shell_NotifyIconGetRect(ref nid, out rect);

            // 0 means success, 1 means the notify icon is in the fly-out - either is fine
            if (result != 0 && result != 1)
                return null;

            // convert to System.Rect and return
            return rect;
        }
开发者ID:navhaxs,项目名称:BrightnessTray,代码行数:44,代码来源:WindowPositioning.cs

示例3: GetNotifyIconRectLegacy

        /// <summary>
        /// Returns a rectangle representing the location of the specified NotifyIcon. (Windows Vista and earlier.)
        /// </summary>
        /// <param name="notifyicon">The NotifyIcon whose location should be returned.</param>
        /// <returns>The location of the specified NotifyIcon.</returns>
        public static Rect? GetNotifyIconRectLegacy(NotifyIcon notifyicon)
        {
            Rect? nirect = null;

            FieldInfo idFieldInfo = notifyicon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance);
            int niid = (int)idFieldInfo.GetValue(notifyicon);

            FieldInfo windowFieldInfo = notifyicon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance);
            System.Windows.Forms.NativeWindow nativeWindow = (System.Windows.Forms.NativeWindow)windowFieldInfo.GetValue(notifyicon);
            IntPtr nihandle = nativeWindow.Handle;
            if (nihandle == null || nihandle == IntPtr.Zero)
                return null;

            // find the handle of the task bar
            IntPtr taskbarparenthandle = NativeMethods.FindWindow("Shell_TrayWnd", null);

            if (taskbarparenthandle == (IntPtr)null)
                return null;

            // find the handle of the notification area
            IntPtr naparenthandle = NativeMethods.FindWindowEx(taskbarparenthandle, IntPtr.Zero, "TrayNotifyWnd", null);

            if (naparenthandle == (IntPtr)null)
                return null;

            // make a list of toolbars in the notification area (one of them should contain the icon)
            List<IntPtr> natoolbarwindows = NativeMethods.GetChildToolbarWindows(naparenthandle);

            bool found = false;

            for (int i = 0; !found && i < natoolbarwindows.Count; i++)
            {
                IntPtr natoolbarhandle = natoolbarwindows[i];

                // retrieve the number of toolbar buttons (i.e. notify icons)
                int buttoncount = NativeMethods.SendMessage(natoolbarhandle, NativeMethods.TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero).ToInt32();

                // get notification area's process id
                uint naprocessid;
                NativeMethods.GetWindowThreadProcessId(natoolbarhandle, out naprocessid);

                // get handle to notification area's process
                IntPtr naprocesshandle = NativeMethods.OpenProcess(NativeMethods.ProcessAccessFlags.All, false, naprocessid);

                if (naprocesshandle == IntPtr.Zero)
                    return null;

                // allocate enough memory within the notification area's process to store the button info we want
                IntPtr toolbarmemoryptr = NativeMethods.VirtualAllocEx(naprocesshandle, (IntPtr)null, (uint)Marshal.SizeOf(typeof(NativeMethods.TBBUTTON)), NativeMethods.AllocationType.Commit, NativeMethods.MemoryProtection.ReadWrite);

                if (toolbarmemoryptr == IntPtr.Zero)
                    return null;

                try
                {
                    // loop through the toolbar's buttons until we find our notify icon
                    for (int j = 0; !found && j < buttoncount; j++)
                    {
                        int bytesread = -1;

                        // ask the notification area to give us information about the current button
                        NativeMethods.SendMessage(natoolbarhandle, NativeMethods.TB_GETBUTTON, new IntPtr(j), toolbarmemoryptr);

                        // retrieve that information from the notification area's process
                        NativeMethods.TBBUTTON buttoninfo = new NativeMethods.TBBUTTON();
                        NativeMethods.ReadProcessMemory(naprocesshandle, toolbarmemoryptr, out buttoninfo, Marshal.SizeOf(buttoninfo), out bytesread);

                        if (bytesread != Marshal.SizeOf(buttoninfo))
                            return null;

                        if (buttoninfo.dwData == IntPtr.Zero)
                            return null;

                        // the dwData field contains a pointer to information about the notify icon:
                        // the handle of the notify icon (an 4/8 bytes) and the id of the notify icon (4 bytes)
                        IntPtr niinfopointer = buttoninfo.dwData;

                        // read the notify icon handle
                        IntPtr nihandlenew;
                        NativeMethods.ReadProcessMemory(naprocesshandle, niinfopointer, out nihandlenew, Marshal.SizeOf(typeof(IntPtr)), out bytesread);

                        if (bytesread != Marshal.SizeOf(typeof(IntPtr)))
                            return null;

                        // read the notify icon id
                        uint niidnew;
                        NativeMethods.ReadProcessMemory(naprocesshandle, niinfopointer + Marshal.SizeOf(typeof(IntPtr)), out niidnew, Marshal.SizeOf(typeof(uint)), out bytesread);

                        if (bytesread != Marshal.SizeOf(typeof(uint)))
                            return null;

                        // if we've found a match
                        if (nihandlenew == nihandle && niidnew == niid)
                        {
                            // check if the button is hidden: if it is, return the rectangle of the 'show hidden icons' button
//.........这里部分代码省略.........
开发者ID:navhaxs,项目名称:BrightnessTray,代码行数:101,代码来源:WindowPositioning.cs

示例4: VulcanNotifyIcon

        internal VulcanNotifyIcon(StatusForm statusForm, StatusMonitor statusMonitor, BrowserIntegration browserIntegration)
        {
            this.statusForm = statusForm;
            this.browserIntegration = browserIntegration;

            this.activeIcons = Blank;
            this.currentIconIndex = 0;

            this.timer = new Timer(AnimationInterval);
            this.timer.Elapsed += new ElapsedEventHandler(this.onTimerElapsed);
            this.timer.Start();

            MenuItem[] items = new MenuItem[] {
            new MenuItem("Restore", new EventHandler(onMenuRestore)),
            new MenuItem("Go to Dashboard", new EventHandler(onMenuOpenDashboard)),
            new MenuItem("-"),
            new MenuItem("Exit", new EventHandler(onMenuExit))
              };

            items[0].DefaultItem = true;

            notifyIcon = new NotifyIcon();

            notifyIcon.ContextMenu = new ContextMenu(items);
            notifyIcon.Icon = Icons.Blank;
            notifyIcon.Text = "Vulcan Tray Notifier";
            notifyIcon.Visible = true;
            notifyIcon.DoubleClick += new EventHandler(this.onDoubleClick);

            statusMonitor.DataLoadError += new StatusMonitor.DataLoadErrorHandler(this.onLoadError);
            statusMonitor.NewBuildAvailable += new StatusMonitor.NewBuildHandler(this.onNewBuild);
            statusMonitor.DashboardStatusChanged += new StatusMonitor.DashboardStatusChangedHandler(this.onDashboardStatusChanged);

            // .NET 1.1 compat
            EventInfo balloonTipClickedEvent = notifyIcon.GetType().GetEvent("BalloonTipClicked");
            if (balloonTipClickedEvent != null)
            {
                balloonTipClickedEvent.AddEventHandler(notifyIcon, new EventHandler(this.onBalloonTipClicked));
                ballonsSupported = true;
            }
            else
            {
                ballonsSupported = false;
            }
        }
开发者ID:majianxiong,项目名称:vulcan,代码行数:45,代码来源:VulcanNotifyIcon.cs

示例5: GetNotificationIconRectangle

        public static Rectangle GetNotificationIconRectangle(NotifyIcon Icon)
        {
            FieldInfo idFieldInfo = Icon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance);
            int iconid = (int)idFieldInfo.GetValue(Icon);

            FieldInfo windowFieldInfo = Icon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance);
            System.Windows.Forms.NativeWindow nativeWindow = (System.Windows.Forms.NativeWindow)windowFieldInfo.GetValue(Icon);
            IntPtr iconHandle = nativeWindow.Handle;

            RECT rect = new RECT();
            NOTIFYICONIDENTIFIER nid = new NOTIFYICONIDENTIFIER()
            {
                hWnd = iconHandle,
                uID = (uint)iconid
            };
            nid.cbSize = (uint)Marshal.SizeOf(nid);
            int result = Shell32.Shell_NotifyIconGetRect(ref nid, out rect);

            Rectangle notifyiconrectangle = Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom);

            return notifyiconrectangle;
        }
开发者ID:iamdixon,项目名称:WpfTrayWindow,代码行数:22,代码来源:TaskBar.cs

示例6: GetNativeHandle

        /// <summary>
        /// Get the handle of the native window associated with the NotifyIcon.  This is done
        /// by reflecting in to a private member field of the icon.
        /// </summary>
        /// <param name="icon"></param>
        /// <returns></returns>
        private IntPtr GetNativeHandle(NotifyIcon icon)
        {
            FieldInfo field = icon.GetType().GetField("window",
                BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);

            NativeWindow window = field.GetValue(icon) as NativeWindow;

            return (window == null ? IntPtr.Zero : window.Handle);
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:15,代码来源:Taskbar.cs


注:本文中的System.Windows.Forms.NotifyIcon.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。