PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] NotifyIcon and ContextMenu without using System.Windows.Forms-VBForums
Results 1 to 10 of 10

Thread: [RESOLVED] NotifyIcon and ContextMenu without using System.Windows.Forms

  1. #1

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,996

    Resolved [RESOLVED] NotifyIcon and ContextMenu without using System.Windows.Forms

    What is the alternative to use without using System.Windows.Forms?

    TIA
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,621

    Re: NotifyIcon and ContextMenu without using System.Windows.Forms

    Shell_NotifyIcon APIs? I dont have my laptop with me so no .net
    Last edited by RobDog888; Sep 30th, 2009 at 03:15 AM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Corsair H100i v2 water cooler, Geforce GTX1060, Samsung M.2 500 GB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2010, VS 2010

  3. #3

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,996

    Re: NotifyIcon and ContextMenu without using System.Windows.Forms

    So it will be okay to use the old VB6.0 Shell_NotifyIcon for it?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,621

    Re: NotifyIcon and ContextMenu without using System.Windows.Forms

    As windows have handles like forms then I dont see why not.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Corsair H100i v2 water cooler, Geforce GTX1060, Samsung M.2 500 GB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2010, VS 2010

  5. #5
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: NotifyIcon and ContextMenu without using System.Windows.Forms

    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,621

    Re: NotifyIcon and ContextMenu without using System.Windows.Forms

    Quote Originally Posted by chris128 View Post
    Awesome Chris!
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Corsair H100i v2 water cooler, Geforce GTX1060, Samsung M.2 500 GB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2010, VS 2010

  7. #7

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,996

    Re: NotifyIcon and ContextMenu without using System.Windows.Forms

    Quote Originally Posted by chris128 View Post
    I have actually seen that and tried it before starting a thread but somehow for this simple requirement I can just opt for the System.Windows.Forms equivalent rather than trying to understand how that code can be applied to my project. Somehow the contextmenu implementation is not perfect so I would prefer the System.Windows.Forms.

    Is there any problems at all if I will reference System.Windows.Forms in WPF?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,996

    Re: NotifyIcon and ContextMenu without using System.Windows.Forms

    In lieu of using System.Windows.Forms I have come up with the following class which uses API for the NotifyIcon and Balloon. You can get the source code in this WPF-based chatting system.

    csharp Code:
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Runtime.InteropServices;
    6. using System.Windows.Media;
    7. using System.Drawing;
    8. using System.Windows.Interop;
    9. using System.Windows;
    10.  
    11. namespace NetVerser
    12. {
    13.     public static class Notify
    14.     {
    15.         private static WindowHwndSource source;        
    16.         private const int NIM_ADD = 0;
    17.         private const int NIM_MODIFY = 1;
    18.         private const int NIM_DELETE = 2;
    19.         //messages to trap
    20.         public const int PK_TRAYICON = 1025;
    21.         public const int RButtonUp = 0x0205;
    22.         public const int NIN_BALLOONUSERCLICK = 1029;
    23.         public const int WM_LBUTTONDBLCLK = 515;
    24.  
    25.         [Flags]
    26.         public enum NotifyIconFlags
    27.         {
    28.             // The hIcon member is valid.
    29.             Icon = 2,
    30.             // The uCallbackMessage member is valid.
    31.             Message = 1,
    32.             // The szTip member is valid.
    33.             ToolTip = 4,
    34.             // The dwState and dwStateMask members are valid.
    35.             State = 8,
    36.             // Use a balloon ToolTip instead of a standard ToolTip. The szInfo, uTimeout, szInfoTitle, and dwInfoFlags members are valid.
    37.             Balloon = 0x10,
    38.         }
    39.  
    40.         public enum NotifyBalloonIcon
    41.         {
    42.             // No icon.
    43.             None,
    44.             // An information icon.
    45.             Info,
    46.             // A warning icon.
    47.             Warning,
    48.             // An error icon.
    49.             Error,
    50.         }
    51.  
    52.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    53.         public class NOTIFYICONDATA
    54.         {
    55.             public int cbSize = Marshal.SizeOf(typeof(NOTIFYICONDATA));
    56.             public IntPtr hWnd;
    57.             public int uID;
    58.             public int uFlags;
    59.             public int uCallbackMessage;
    60.             public IntPtr hIcon;
    61.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x80)]
    62.             public string szTip;
    63.             public int dwState;
    64.             public int dwStateMask;
    65.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
    66.             public string szInfo;
    67.             public int uTimeoutOrVersion;
    68.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x40)]
    69.             public string szInfoTitle;
    70.             public int dwInfoFlags;
    71.         }
    72.        
    73.         [DllImport("shell32", CharSet = CharSet.Auto)]
    74.         public static extern int Shell_NotifyIcon(int message, NOTIFYICONDATA pnid);
    75.  
    76.         public static IntPtr AddToTray(Window window, string stringTip)
    77.         {
    78.             //hook window
    79.             source = new WindowHwndSource((winChat)window);    
    80.        
    81.             //get icon
    82.             Icon icon = new System.Drawing.Icon(global::NetVerser.Properties.Resources.Comment, 16, 16);
    83.  
    84.             //uID is the same uID used in ShowBallon
    85.             NOTIFYICONDATA pnid = new NOTIFYICONDATA
    86.             {
    87.                 hWnd = source.Handle,
    88.                 uID = 999,
    89.                 uFlags = (int)NotifyIconFlags.Message | (int)NotifyIconFlags.ToolTip | (int)NotifyIconFlags.Icon,
    90.                 uCallbackMessage = PK_TRAYICON,
    91.                 szTip = stringTip,
    92.                 hIcon = (IntPtr)icon.Handle,
    93.             };
    94.             //add icon
    95.             Shell_NotifyIcon(NIM_ADD, pnid);
    96.  
    97.             //return source handle to be used in SetForegroundWindow
    98.             return source.Handle;
    99.         }
    100.  
    101.         public static void RemoveFromTray()
    102.         {
    103.             NOTIFYICONDATA pnid = new NOTIFYICONDATA
    104.             {
    105.                 hWnd = source.Handle,
    106.                 uID = 999
    107.             };
    108.             //remove icon from tray
    109.             Shell_NotifyIcon(NIM_DELETE, pnid);
    110.         }
    111.  
    112.         public static IntPtr ShowBallon(int timeout, string stringTip, string tipTitle, string tipText, NotifyBalloonIcon tipIcon)
    113.         {
    114.             //get icon
    115.             Icon icon = new System.Drawing.Icon(global::NetVerser.Properties.Resources.Comment, 16, 16);
    116.             //uID is the same uID used in AddToTray
    117.             NOTIFYICONDATA pnid = new NOTIFYICONDATA
    118.             {
    119.                 hWnd = source.Handle,
    120.                 uID = 999,
    121.                 uFlags = (int)NotifyIconFlags.Balloon | (int)NotifyIconFlags.Message | (int)NotifyIconFlags.ToolTip | (int)NotifyIconFlags.Icon,
    122.                 uTimeoutOrVersion = timeout,
    123.                 szInfoTitle = tipTitle,
    124.                 szInfo = tipText,
    125.                 dwInfoFlags = (int)tipIcon,
    126.                 hIcon = (IntPtr)icon.Handle,
    127.                 uCallbackMessage = PK_TRAYICON,
    128.                 szTip = stringTip,
    129.             };
    130.             //modify icon
    131.             Shell_NotifyIcon(NIM_MODIFY, pnid);
    132.             //return source handle to be used in SetForegroundWindow
    133.             return source.Handle;
    134.         }
    135.     }
    136.  
    137.     //this is to hook WPF window messages
    138.     public class WindowHwndSource : HwndSource
    139.     {
    140.         [DllImport("user32", CharSet = CharSet.Auto)]
    141.         public static extern bool PostMessage(HandleRef hwnd, int msg, IntPtr wparam, IntPtr lparam);
    142.  
    143.         private winChat _reference;
    144.         private const int Close = 0x10;
    145.  
    146.         internal WindowHwndSource(winChat component) : base(0, 0, 0, 0, 0, null, IntPtr.Zero)
    147.         {
    148.             _reference = component;
    149.             AddHook(_reference.WndProc);
    150.         }
    151.  
    152.         ~WindowHwndSource()
    153.         {
    154.             if (Handle != IntPtr.Zero)
    155.             {
    156.                 PostMessage(new HandleRef(this, Handle), Close, IntPtr.Zero, IntPtr.Zero);
    157.             }
    158.         }
    159.     }
    160. }
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  9. #9
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [RESOLVED] NotifyIcon and ContextMenu without using System.Windows.Forms

    but thats exactly what that link that I posted originally does isnt it?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  10. #10

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,996

    Re: [RESOLVED] NotifyIcon and ContextMenu without using System.Windows.Forms

    I did not check thoroughly but I have seen it uses the same API but I did not look how they have implemented it, and it is not up to my liking, for example when you press Escape while the context menu is shown then it will not go away.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width