// 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) { IntPtr 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)) { IntPtr 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?.Invoke(Color.FromArgb(red, green, blue), EventArgs.Empty); } } } } } // Always call the base class hook procedure. return(base.HookProc(hWnd, msg, wParam, lParam)); }
/// <summary> /// Sets the color of blocks subscribed to OnUpdateColor /// </summary> /// <param name="healthPercent">0 to 1 percentage to lerp between black and white.</param> private void UpdateBlockColors(float healthPercent) { //broadcast the new color to all the blocks. OnUpdateColor?.Invoke(Color.Lerp(Color.black, Color.white, healthPercent)); }