protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
        {
            if (msg != 307)
            {
                return(base.HookProc(hWnd, msg, wparam, lparam));
            }

            if (_editWindows == null)
            {
                var mainWindow = GetAncestor(hWnd, 2);
                if (!mainWindow.Equals(IntPtr.Zero))
                {
                    _editWindows = new List <ApiWindow>((new WindowsEnumerator()).GetChildWindows(mainWindow, "Edit"));
                }
            }
            else if (_editWindows != null && _editWindows.Count == 6)
            {
                var strRed   = WindowsEnumerator.WindowText(_editWindows[3].HWnd);
                var strGreen = WindowsEnumerator.WindowText(_editWindows[4].HWnd);
                var strBlue  = WindowsEnumerator.WindowText(_editWindows[5].HWnd);

                int red;
                if (!int.TryParse(strRed, out red))
                {
                    return(base.HookProc(hWnd, msg, wparam, lparam));
                }
                int green;
                if (!int.TryParse(strGreen, out green))
                {
                    return(base.HookProc(hWnd, msg, wparam, lparam));
                }
                int blue;
                if (int.TryParse(strBlue, out blue))
                {
                    PreviewColorChangedEvent(red, green, blue);
                }
            }
            return(base.HookProc(hWnd, msg, wparam, lparam));
        }
Exemplo n.º 2
0
 // Overrides the base class hook procedure...
 //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
 protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
 {
     if (msg == WM_INITDIALOG)
     {
         var mainWindow = GetAncestor(hWnd, GA_ROOT);
         if (!mainWindow.Equals(IntPtr.Zero))
         {
             EditWindows = new List <ApiWindow>(new WindowsEnumerator().GetChildWindows(mainWindow, "Edit"));
         }
     }
     else if (msg == WM_CTLCOLOREDIT)
     {
         if (EditWindows == null)
         {
             var mainWindow = GetAncestor(hWnd, GA_ROOT);
             if (!mainWindow.Equals(IntPtr.Zero))
             {
                 EditWindows = new List <ApiWindow>(new WindowsEnumerator().GetChildWindows(mainWindow, "Edit"));
             }
         }
         if (EditWindows != null && EditWindows.Count == 6)
         {
             byte red = 0, green = 0, blue = 0;
             if (byte.TryParse(WindowsEnumerator.WindowText(EditWindows[3].hWnd), out red))
             {
                 if (byte.TryParse(WindowsEnumerator.WindowText(EditWindows[4].hWnd), out green))
                 {
                     if (byte.TryParse(WindowsEnumerator.WindowText(EditWindows[5].hWnd), out blue))
                     {
                         OnUpdateColor(Color.FromArgb(red, green, blue), EventArgs.Empty);
                     }
                 }
             }
         }
     }
     // Always call the base class hook procedure.
     return(base.HookProc(hWnd, msg, wParam, lParam));
 }