C # Determine if the mouse is on the NotifyIcon of its own program

Source: Internet
Author: User

    <summary>///    program Tray area icon Location////    </summary> public    class Iconinfo {//        <summary >///Tray handle////        </summary> public        IntPtr hWnd = IntPtr.Zero;        <summary>///x coordinates///        </summary> public        int x;        <summary>///        icons y coordinates///        </summary> public        int y;        <summary>///Icon Width///        </summary> public        int width;        <summary>///Icon Height///        </summary> public        int height;        public bool Iniconrect (point P)        {            if (p.x >= x && p.x <= x + Width && p.y >= Y &&am P P.Y <= Y + Height)            {                return true;            }            return false;        }    }

Added to the icon's MouseMove event to determine the icon position information

        Geticoninfo (); <pre name= "code" class= "CSharp" >        //Get icon position information        private void Geticoninfo ()        {            point p = cursor.position;            Myicon.hwnd = Windowfrompoint (p);            int btnsize = SendMessage (Myicon.hwnd, Tb_getbuttonsize, IntPtr.Zero, IntPtr.Zero);            Myicon.width = btnsize & 0xFFFF;            Myicon.height = (btnsize/0x10000) & 0xFFFF;            Rect rect = new rect ();            if (GetWindowRect (Myicon.hwnd, out rect))            {                if (myicon.width! = 0 && Myicon.height! = 0)                {                    myicon.x = (p.x-rect. LEFT-PY)/myicon.width * myicon.width + rect. Left + py;                    MYICON.Y = (p.y-rect. TOP-PY)/myicon.height * myicon.height + rect. Top + py;}}}        


Variables and functions used

        <summary>////different operating system offsets///</summary> private int py = 0;        Private Const int wm_user = 0x400;        Private Const int tb_getbuttonsize = Wm_user + 58;        Private Const int wm_syscommand = 0x112;        Private Const long sc_minimize = 0xf020;        Private Const int wm_mousemove = 0x0200; [DllImport ("User32.dll")] public static extern int SendMessage (INTPTR hwnd, int wmsg, IntPtr wParam, IntPtr LParam)        ;        [DllImport ("User32.dll")] private static extern bool GetWindowRect (INTPTR hwnd, out Rect lpRect);        [DllImport ("User32.dll")] private static extern IntPtr Windowfrompoint (point P);        <summary>///Icon Information///</summary> private Iconinfo Myicon = new Iconinfo ();            After the WIN7 system has a two-pixel offset program load, add the following code operatingsystem OS = environment.osversion; if (OS. Platform = = platformid.win32nt && os. Version.major >= 6) {                PY = 2; }


C # Determine if the mouse is on the NotifyIcon of its own program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.