From e5890648b98371b522269ff25fc0b29de5965725 Mon Sep 17 00:00:00 2001 From: seerge Date: Fri, 24 Feb 2023 17:17:12 +0100 Subject: [PATCH] Added OSD notifications --- Fans.Designer.cs | 16 - Fans.cs | 8 +- OSDBase.cs | 483 +++++++++++++++++++++++++++++++ Program.cs | 72 ++--- Properties/Resources.Designer.cs | 10 + Properties/Resources.resx | 7 +- Resources/icons8-fan-head-96.png | Bin 0 -> 1856 bytes Settings.Designer.cs | 211 +++++++------- Settings.cs | 34 +-- ToastForm.Designer.cs | 85 ------ ToastForm.cs | 108 ++++--- ToastForm.resx | 60 ---- 12 files changed, 707 insertions(+), 387 deletions(-) create mode 100644 OSDBase.cs create mode 100644 Resources/icons8-fan-head-96.png delete mode 100644 ToastForm.Designer.cs delete mode 100644 ToastForm.resx diff --git a/Fans.Designer.cs b/Fans.Designer.cs index a0ffadde..71edd27c 100644 --- a/Fans.Designer.cs +++ b/Fans.Designer.cs @@ -29,11 +29,7 @@ private void InitializeComponent() { System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); chartCPU = new System.Windows.Forms.DataVisualization.Charting.Chart(); buttonApply = new Button(); buttonReset = new Button(); @@ -46,14 +42,8 @@ // chartArea1.Name = "ChartArea1"; chartCPU.ChartAreas.Add(chartArea1); - legend1.Name = "Legend1"; - chartCPU.Legends.Add(legend1); chartCPU.Location = new Point(16, 13); chartCPU.Name = "chartCPU"; - series1.ChartArea = "ChartArea1"; - series1.Legend = "Legend1"; - series1.Name = "Series1"; - chartCPU.Series.Add(series1); chartCPU.Size = new Size(900, 446); chartCPU.TabIndex = 0; chartCPU.Text = "chartCPU"; @@ -80,14 +70,8 @@ // chartArea2.Name = "ChartArea1"; chartGPU.ChartAreas.Add(chartArea2); - legend2.Name = "Legend1"; - chartGPU.Legends.Add(legend2); chartGPU.Location = new Point(16, 477); chartGPU.Name = "chartGPU"; - series2.ChartArea = "ChartArea1"; - series2.Legend = "Legend1"; - series2.Name = "Series1"; - chartGPU.Series.Add(series2); chartGPU.Size = new Size(900, 448); chartGPU.TabIndex = 3; chartGPU.Text = "chart1"; diff --git a/Fans.cs b/Fans.cs index 8d16ae54..c701b293 100644 --- a/Fans.cs +++ b/Fans.cs @@ -18,7 +18,7 @@ namespace GHelper if (device == 1) title = "GPU Fan Profile"; - else + else title = "CPU Fan Profile"; if (Program.settingsForm.perfName.Length > 0) @@ -34,7 +34,9 @@ namespace GHelper chart.ChartAreas[0].AxisX.Interval = 10; chart.ChartAreas[0].AxisY.Minimum = 0; chart.ChartAreas[0].AxisY.Maximum = 100; - chart.Legends[0].Enabled = false; + + if (chart.Legends.Count > 0) + chart.Legends[0].Enabled = false; } @@ -74,7 +76,7 @@ namespace GHelper { SetChart(chartCPU, 0); - SetChart(chartGPU, 0); + SetChart(chartGPU, 1); LoadProfile(seriesCPU, 0); LoadProfile(seriesGPU, 1); diff --git a/OSDBase.cs b/OSDBase.cs new file mode 100644 index 00000000..46b066be --- /dev/null +++ b/OSDBase.cs @@ -0,0 +1,483 @@ +using System.Drawing.Drawing2D; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; + +namespace OSD +{ + + class OSDNativeForm : NativeWindow, IDisposable + { + + private bool _disposed = false; + private byte _alpha = 250; + private Size _size = new Size(350, 50); + private Point _location = new Point(50, 50); + + + protected virtual void PerformPaint(PaintEventArgs e) + { + } + + protected internal void Invalidate() + { + this.UpdateLayeredWindow(); + } + private void UpdateLayeredWindow() + { + Bitmap bitmap1 = new Bitmap(this.Size.Width, this.Size.Height, PixelFormat.Format32bppArgb); + using (Graphics graphics1 = Graphics.FromImage(bitmap1)) + { + Rectangle rectangle1; + SIZE size1; + POINT point1; + POINT point2; + BLENDFUNCTION blendfunction1; + rectangle1 = new Rectangle(0, 0, this.Size.Width, this.Size.Height); + PerformPaint(new PaintEventArgs(graphics1, rectangle1)); + IntPtr ptr1 = User32.GetDC(IntPtr.Zero); + IntPtr ptr2 = Gdi32.CreateCompatibleDC(ptr1); + IntPtr ptr3 = bitmap1.GetHbitmap(Color.FromArgb(0)); + IntPtr ptr4 = Gdi32.SelectObject(ptr2, ptr3); + size1.cx = this.Size.Width; + size1.cy = this.Size.Height; + point1.x = this.Location.X; + point1.x = this.Location.X; + point1.y = this.Location.Y; + point2.x = 0; + point2.y = 0; + blendfunction1 = new BLENDFUNCTION(); + blendfunction1.BlendOp = 0; + blendfunction1.BlendFlags = 0; + blendfunction1.SourceConstantAlpha = this._alpha; + blendfunction1.AlphaFormat = 1; + User32.UpdateLayeredWindow(base.Handle, ptr1, ref point1, ref size1, ptr2, ref point2, 0, ref blendfunction1, 2); //2=ULW_ALPHA + Gdi32.SelectObject(ptr2, ptr4); + User32.ReleaseDC(IntPtr.Zero, ptr1); + Gdi32.DeleteObject(ptr3); + Gdi32.DeleteDC(ptr2); + } + } + + public virtual void Show() + { + if (base.Handle == IntPtr.Zero) //if handle don't equal to zero - window was created and just hided + this.CreateWindowOnly(); + User32.ShowWindow(base.Handle, User32.SW_SHOWNOACTIVATE); + } + + + public virtual void Hide() + { + if (base.Handle == IntPtr.Zero) + return; + User32.ShowWindow(base.Handle, User32.SW_HIDE); + this.DestroyHandle(); + } + + + public virtual void Close() + { + this.Hide(); + this.Dispose(); + } + + private void CreateWindowOnly() + { + + CreateParams params1 = new CreateParams(); + params1.Caption = "FloatingNativeWindow"; + int nX = this._location.X; + int nY = this._location.Y; + Screen screen1 = Screen.FromHandle(base.Handle); + if ((nX + this._size.Width) > screen1.Bounds.Width) + { + nX = screen1.Bounds.Width - this._size.Width; + } + if ((nY + this._size.Height) > screen1.Bounds.Height) + { + nY = screen1.Bounds.Height - this._size.Height; + } + this._location = new Point(nX, nY); + Size size1 = this._size; + Point point1 = this._location; + params1.X = nX; + params1.Y = nY; + params1.Height = size1.Height; + params1.Width = size1.Width; + params1.Parent = IntPtr.Zero; + uint ui = User32.WS_POPUP; + params1.Style = (int)ui; + params1.ExStyle = User32.WS_EX_TOPMOST | User32.WS_EX_TOOLWINDOW | User32.WS_EX_LAYERED | User32.WS_EX_NOACTIVATE | User32.WS_EX_TRANSPARENT; + this.CreateHandle(params1); + this.UpdateLayeredWindow(); + } + + + + protected virtual void SetBoundsCore(int x, int y, int width, int height) + { + if (((this.X != x) || (this.Y != y)) || ((this.Width != width) || (this.Height != height))) + { + if (base.Handle != IntPtr.Zero) + { + int num1 = 20; + if ((this.X == x) && (this.Y == y)) + { + num1 |= 2; + } + if ((this.Width == width) && (this.Height == height)) + { + num1 |= 1; + } + User32.SetWindowPos(base.Handle, IntPtr.Zero, x, y, width, height, (uint)num1); + } + else + { + this.Location = new Point(x, y); + this.Size = new Size(width, height); + } + } + } + + + + + #region # Properties # + /// + /// Get or set position of top-left corner of floating native window in screen coordinates + /// + public virtual Point Location + { + get { return this._location; } + set + { + if (base.Handle != IntPtr.Zero) + { + this.SetBoundsCore(value.X, value.Y, this._size.Width, this._size.Height); + RECT rect = new RECT(); + User32.GetWindowRect(base.Handle, ref rect); + this._location = new Point(rect.left, rect.top); + this.UpdateLayeredWindow(); + } + else + { + this._location = value; + } + } + } + /// + /// Get or set size of client area of floating native window + /// + public virtual Size Size + { + get { return this._size; } + set + { + if (base.Handle != IntPtr.Zero) + { + this.SetBoundsCore(this._location.X, this._location.Y, value.Width, value.Height); + RECT rect = new RECT(); + User32.GetWindowRect(base.Handle, ref rect); + this._size = new Size(rect.right - rect.left, rect.bottom - rect.top); + this.UpdateLayeredWindow(); + } + else + { + this._size = value; + } + } + } + /// + /// Gets or sets the height of the floating native window + /// + public int Height + { + get { return this._size.Height; } + set + { + this._size = new Size(this._size.Width, value); + } + } + /// + /// Gets or sets the width of the floating native window + /// + public int Width + { + get { return this._size.Width; } + set + { + this._size = new Size(value, this._size.Height); + } + } + /// + /// Get or set x-coordinate of top-left corner of floating native window in screen coordinates + /// + public int X + { + get { return this._location.X; } + set + { + this.Location = new Point(value, this.Location.Y); + } + } + /// + /// Get or set y-coordinate of top-left corner of floating native window in screen coordinates + /// + public int Y + { + get { return this._location.Y; } + set + { + this.Location = new Point(this.Location.X, value); + } + } + /// + /// Get rectangle represented client area of floating native window in client coordinates(top-left corner always has coord. 0,0) + /// + public Rectangle Bound + { + get + { + return new Rectangle(new Point(0, 0), this._size); + } + } + /// + /// Get or set full opacity(255) or full transparency(0) or any intermediate state for floating native window transparency + /// + public byte Alpha + { + get { return this._alpha; } + set + { + if (this._alpha == value) return; + this._alpha = value; + this.UpdateLayeredWindow(); + } + } + #endregion + + #region IDisposable Members + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + private void Dispose(bool disposing) + { + if (!this._disposed) + { + this.DestroyHandle(); + this._disposed = true; + } + } + #endregion + } + + #region # Win32 # + internal struct PAINTSTRUCT + { + public IntPtr hdc; + public int fErase; + public Rectangle rcPaint; + public int fRestore; + public int fIncUpdate; + public int Reserved1; + public int Reserved2; + public int Reserved3; + public int Reserved4; + public int Reserved5; + public int Reserved6; + public int Reserved7; + public int Reserved8; + } + [StructLayout(LayoutKind.Sequential)] + internal struct POINT + { + public int x; + public int y; + } + [StructLayout(LayoutKind.Sequential)] + internal struct RECT + { + public int left; + public int top; + public int right; + public int bottom; + } + [StructLayout(LayoutKind.Sequential)] + internal struct SIZE + { + public int cx; + public int cy; + } + [StructLayout(LayoutKind.Sequential)] + internal struct TRACKMOUSEEVENTS + { + public uint cbSize; + public uint dwFlags; + public IntPtr hWnd; + public uint dwHoverTime; + } + [StructLayout(LayoutKind.Sequential)] + internal struct MSG + { + public IntPtr hwnd; + public int message; + public IntPtr wParam; + public IntPtr lParam; + public int time; + public int pt_x; + public int pt_y; + } + [StructLayout(LayoutKind.Sequential, Pack = 1)] + internal struct BLENDFUNCTION + { + public byte BlendOp; + public byte BlendFlags; + public byte SourceConstantAlpha; + public byte AlphaFormat; + } + internal class User32 + { + public const uint WS_POPUP = 0x80000000; + public const int WS_EX_TOPMOST = 0x8; + public const int WS_EX_TOOLWINDOW = 0x80; + public const int WS_EX_LAYERED = 0x80000; + public const int WS_EX_TRANSPARENT = 0x20; + public const int WS_EX_NOACTIVATE = 0x08000000; + public const int SW_SHOWNOACTIVATE = 4; + public const int SW_HIDE = 0; + public const uint AW_HOR_POSITIVE = 0x1; + public const uint AW_HOR_NEGATIVE = 0x2; + public const uint AW_VER_POSITIVE = 0x4; + public const uint AW_VER_NEGATIVE = 0x8; + public const uint AW_CENTER = 0x10; + public const uint AW_HIDE = 0x10000; + public const uint AW_ACTIVATE = 0x20000; + public const uint AW_SLIDE = 0x40000; + public const uint AW_BLEND = 0x80000; + // Methods + private User32() + { + } + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool AnimateWindow(IntPtr hWnd, uint dwTime, uint dwFlags); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT pt); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool DispatchMessage(ref MSG msg); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool DrawFocusRect(IntPtr hWnd, ref RECT rect); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr GetDC(IntPtr hWnd); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr GetFocus(); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern ushort GetKeyState(int virtKey); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool GetMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr GetParent(IntPtr hWnd); + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] + public static extern bool GetClientRect(IntPtr hWnd, [In, Out] ref RECT rect); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern int GetWindowLong(IntPtr hWnd, int nIndex); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr GetWindow(IntPtr hWnd, int cmd); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool HideCaret(IntPtr hWnd); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool InvalidateRect(IntPtr hWnd, ref RECT rect, bool erase); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr LoadCursor(IntPtr hInstance, uint cursor); + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] + public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] ref RECT rect, int cPoints); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, uint wFlag); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool PostMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool ReleaseCapture(); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool ScreenToClient(IntPtr hWnd, ref POINT pt); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern uint SendMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr SetCursor(IntPtr hCursor); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr SetFocus(IntPtr hWnd); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int newLong); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndAfter, int X, int Y, int Width, int Height, uint flags); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool ShowCaret(IntPtr hWnd); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool SetCapture(IntPtr hWnd); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern int ShowWindow(IntPtr hWnd, short cmdShow); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int bRetValue, uint fWinINI); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool TrackMouseEvent(ref TRACKMOUSEEVENTS tme); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool TranslateMessage(ref MSG msg); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool UpdateWindow(IntPtr hwnd); + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool WaitMessage(); + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] + public static extern bool AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle); + } + + internal class Gdi32 + { + // Methods + private Gdi32() + { + } + [DllImport("gdi32.dll", CharSet = CharSet.Auto)] + internal static extern int CombineRgn(IntPtr dest, IntPtr src1, IntPtr src2, int flags); + [DllImport("gdi32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr CreateBrushIndirect(ref LOGBRUSH brush); + [DllImport("gdi32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr CreateCompatibleDC(IntPtr hDC); + [DllImport("gdi32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr CreateRectRgnIndirect(ref RECT rect); + [DllImport("gdi32.dll", CharSet = CharSet.Auto)] + internal static extern bool DeleteDC(IntPtr hDC); + [DllImport("gdi32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr DeleteObject(IntPtr hObject); + [DllImport("gdi32.dll", CharSet = CharSet.Auto)] + internal static extern int GetClipBox(IntPtr hDC, ref RECT rectBox); + [DllImport("gdi32.dll", CharSet = CharSet.Auto)] + internal static extern bool PatBlt(IntPtr hDC, int x, int y, int width, int height, uint flags); + [DllImport("gdi32.dll", CharSet = CharSet.Auto)] + internal static extern int SelectClipRgn(IntPtr hDC, IntPtr hRgn); + [DllImport("gdi32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject); + } + [StructLayout(LayoutKind.Sequential)] + public struct LOGBRUSH + { + public uint lbStyle; + public uint lbColor; + public uint lbHatch; + } + + #endregion +} diff --git a/Program.cs b/Program.cs index 00e19d22..61edc9b3 100644 --- a/Program.cs +++ b/Program.cs @@ -1,8 +1,8 @@ using Microsoft.Win32; using System.Diagnostics; using System.Management; +using System.Runtime.InteropServices; using System.Security.Principal; -using System.Text; using System.Text.Json; @@ -84,81 +84,49 @@ public class AppConfig public class HardwareMonitor { + public static float? cpuTemp = -1; + public static float? batteryDischarge = -1; - public float? cpuTemp = -1; - public float? gpuTemp = -1; - public float? batteryDischarge = -1; - public float? batteryCharge = -1; - public static bool IsAdministrator() + public static void ReadSensors() { - return (new WindowsPrincipal(WindowsIdentity.GetCurrent())) - .IsInRole(WindowsBuiltInRole.Administrator); - } - - public HardwareMonitor() - { - - } - - public void ReadSensors() - { - cpuTemp = -1; - gpuTemp = -1; batteryDischarge = -1; try { + var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true); + cpuTemp = ct.NextValue() - 273; + ct.Dispose(); - if (cpuTemp < 0) - { - var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true); - cpuTemp = ct.NextValue() - 273; - ct.Dispose(); - } - - if (batteryDischarge < 0) - { - var ct = new PerformanceCounter("Power Meter", "Power", "Power Meter (0)", true); - batteryDischarge = ct.NextValue() / 1000; - ct.Dispose(); - } - - - } catch + var cb = new PerformanceCounter("Power Meter", "Power", "Power Meter (0)", true); + batteryDischarge = ct.NextValue() / 1000; + cb.Dispose(); + } + catch { Debug.WriteLine("Failed reading sensors"); } - - - } - - public void StopReading() - { - //computer.Close(); } } - - namespace GHelper { static class Program { public static NotifyIcon trayIcon = new NotifyIcon - { - Text = "G-Helper", - Icon = Properties.Resources.standard, - Visible = true - }; + { + Text = "G-Helper", + Icon = Properties.Resources.standard, + Visible = true + }; public static ASUSWmi wmi = new ASUSWmi(); public static AppConfig config = new AppConfig(); - + public static SettingsForm settingsForm = new SettingsForm(); - public static HardwareMonitor hwmonitor = new HardwareMonitor(); + public static ToastForm toast = new ToastForm(); // The main entry point for the application public static void Main() @@ -186,7 +154,7 @@ namespace GHelper SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; - IntPtr dummy = settingsForm.Handle; + IntPtr ds = settingsForm.Handle; Application.Run(); diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index adae0f25..3658fd96 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -80,6 +80,16 @@ namespace GHelper.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap icons8_fan_head_96 { + get { + object obj = ResourceManager.GetObject("icons8-fan-head-96", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index b4dac885..da1bf2d1 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -133,6 +133,9 @@ ..\Resources\icons8-speed-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icons8-speed-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\icons8-video-card-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -142,7 +145,7 @@ ..\Resources\icons8-laptop-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icons8-speed-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icons8-fan-head-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/Resources/icons8-fan-head-96.png b/Resources/icons8-fan-head-96.png new file mode 100644 index 0000000000000000000000000000000000000000..e22b816a055778b5beae4cf4a69926d76c8856a5 GIT binary patch literal 1856 zcmV-G2fz4aKV}J^-5yTjbza$3R;#La95>b=Vs)<#pv|}bYFL`<1 zci(+8XO{OmUvmDm_su z0vHBxjAWSp)CU;3$K^ z^U3c3-ULtwAT^N(qXNKE00%4>J(u(WSVFo?sA*;efS(*1K3k+N_mgfV4LJw*dth*p zL*zo>&}tQFNj8Q`mz~um%0Sp+vf45I-Lb=5Sx0`}>C+5-VWB@N2)@3(8JlmO+BUSIBHNo8A6{92e1*_+0PUz z{?M?VTVWYDSunl;a5s~_Pg&6QdRRi0rI7M*Mpy4qOK+={bmt07Pyb#1>jRh#upTaVs}0Nu-u7J3aTZ6bpIAmgtX70;nVUP zw@W(DQAZjQ=q5Knzj$DD72OlV)m-{U9=*;5@RtY1j*>Rc0qE9LMlzV+rDTZ=5w8WX zhr-NpzZ(HCHAb)H3cCDD>x+!vY$VxCdxd=ZIN3;6Yx>b!W1@u@0{A%3@8zK7!s3KF z$bo#FriDp)GJE$jx!ZCur+@+V8cIBn&|PeeY2(kB0j#Cah@2w7&GFkO^1MY+sAS?a zNd~qyR9H6Si|I zfLp+aW{m+@&!NCBLsL%_a{2JR08WEDie=RFmPB@PD6miA#*!+cf){eMcSFRr*8pfC zcQ5MyoS3gT0MdKZh6>qA^W(He2K>Wt|Pxa-IjDSGqE=2zB2Qb&D>Z_-iUNrb#RA* z9sYr%0np*`qz!iuxq&j=kcrj;atO;Z{x_oOm(O-J04h_Ej7pk9UCezYQ7jWJ5u8$0 znoF&#DM)1zKB7P)ECjFS$RTHEqP~u}u1VwEgOf#A#SIm7Hp~=K6e91S%}!H<@#iqV zotL?CLsd3nf(FjyTM&myF%OR1)T!WMR~s>vP()f}AdCz10ZdMKZDSt2E>Oq_4!8DAxC-^fK^$0g0$?RAlbs0 zi06zPzfDVP!a;b%bvSw|6S3(aQTO7K6sOSi@fLu;6SliZgOs}iz(p|w_>K<=889C^ z9i#R-Gg5-v>5SQNW(M_{2?lbEQj{{}@eqKg0erx4rht>%8oT{>DI*EuPMaL*CZ{+y z%=N(7B4V?5t;dv_8#xD{ii%gbHhM2@zHTcZq%fJ75H|H3HcujjJI-&%sE@-1OYZ!I5RY-&-_LIaVwQ*EwC6m6@%%t16x!+p-(FO}0 zYA&)jR+0&F7!+JG$Up*CMx)^~xSblh-DSb} z<33c{Z8O}-2Nhi9RhABC7ec`|hBB(FX|khj2{LMBL}CBlg5jln=1a*kP*oG%b7Ufq z{74CtONpaXOKi1;6l(a@lHmmf_gvBCb7Gq3mC*&0^wR_2C1#fRAoK$`51!-f9F)Lf zmwm2k!>O(byFDR8n}ijW%-}F6NqLl0RaI40RaI40RaI4V8DOKUB7}k9AC8n0000 0) - cpuTemp = ": " + Math.Round((decimal)Program.hwmonitor.cpuTemp).ToString() + "°C - "; + if (HardwareMonitor.cpuTemp > 0) + cpuTemp = ": " + Math.Round((decimal)HardwareMonitor.cpuTemp).ToString() + "°C - "; - if (Program.hwmonitor.gpuTemp > 0) - gpuTemp = ": " + Math.Round((decimal)Program.hwmonitor.gpuTemp).ToString() + "°C - "; - - if (Program.hwmonitor.batteryDischarge > 0) - battery = "Discharging: " + Math.Round((decimal)Program.hwmonitor.batteryDischarge, 1).ToString() + "W"; - - if (Program.hwmonitor.batteryCharge > 0) - battery = "Charging: " + Math.Round((decimal)Program.hwmonitor.batteryCharge, 1).ToString() + "W"; + if (HardwareMonitor.batteryDischarge > 0) + battery = "Discharging: " + Math.Round((decimal)HardwareMonitor.batteryDischarge, 1).ToString() + "W"; Program.settingsForm.BeginInvoke(delegate { Program.settingsForm.labelCPUFan.Text = "CPU" + cpuTemp + cpuFan; - Program.settingsForm.labelGPUFan.Text = "GPU" + gpuTemp + gpuFan; Program.settingsForm.labelBattery.Text = battery; }); } @@ -382,7 +367,7 @@ namespace GHelper { InitScreen(); - this.Left = Screen.FromControl(this).Bounds.Width - 10 - this.Width; + this.Left = Screen.FromControl(this).WorkingArea.Width - 10 - this.Width; this.Top = Screen.FromControl(this).WorkingArea.Height - 10 - this.Height; this.Activate(); @@ -393,7 +378,6 @@ namespace GHelper else { aTimer.Enabled = false; - Program.hwmonitor.StopReading(); } } @@ -435,7 +419,11 @@ namespace GHelper if (fans != null && fans.Text != "") fans.LoadFans(); - } + if (notify) { + Program.toast.RunToast(perfName); + } + +} public void CyclePerformanceMode() diff --git a/ToastForm.Designer.cs b/ToastForm.Designer.cs deleted file mode 100644 index b7bc2cf2..00000000 --- a/ToastForm.Designer.cs +++ /dev/null @@ -1,85 +0,0 @@ -namespace GHelper -{ - partial class ToastForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.pictureIcon = new System.Windows.Forms.PictureBox(); - this.labelMode = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.pictureIcon)).BeginInit(); - this.SuspendLayout(); - // - // pictureIcon - // - this.pictureIcon.BackgroundImage = global::GHelper.Properties.Resources.icons8_speed_96; - this.pictureIcon.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.pictureIcon.Location = new System.Drawing.Point(21, 21); - this.pictureIcon.Name = "pictureIcon"; - this.pictureIcon.Size = new System.Drawing.Size(82, 80); - this.pictureIcon.TabIndex = 0; - this.pictureIcon.TabStop = false; - // - // labelMode - // - this.labelMode.AutoSize = true; - this.labelMode.Font = new System.Drawing.Font("Segoe UI", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.labelMode.Location = new System.Drawing.Point(127, 32); - this.labelMode.Name = "labelMode"; - this.labelMode.Size = new System.Drawing.Size(195, 59); - this.labelMode.TabIndex = 1; - this.labelMode.Text = "Balanced"; - this.labelMode.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // ToastForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.ClientSize = new System.Drawing.Size(356, 122); - this.Controls.Add(this.labelMode); - this.Controls.Add(this.pictureIcon); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; - this.MaximizeBox = false; - this.MdiChildrenMinimizedAnchorBottom = false; - this.MinimizeBox = false; - this.Name = "ToastForm"; - this.ShowIcon = false; - this.ShowInTaskbar = false; - this.Text = "ToastForm"; - this.TopMost = true; - ((System.ComponentModel.ISupportInitialize)(this.pictureIcon)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private PictureBox pictureIcon; - private Label labelMode; - } -} \ No newline at end of file diff --git a/ToastForm.cs b/ToastForm.cs index e1f168fa..d3ea8367 100644 --- a/ToastForm.cs +++ b/ToastForm.cs @@ -1,68 +1,94 @@ -using System.Runtime.InteropServices; +using System.Drawing.Drawing2D; +using OSD; namespace GHelper { - public partial class ToastForm : Form + + static class Drawing { - private System.Windows.Forms.Timer timer = default!; - - private const int SW_SHOWNOACTIVATE = 4; - private const int HWND_TOPMOST = -1; - private const uint SWP_NOACTIVATE = 0x0010; - - [DllImport("user32.dll", EntryPoint = "SetWindowPos")] - static extern bool SetWindowPos( - int hWnd, // Window handle - int hWndInsertAfter, // Placement-order handle - int X, // Horizontal position - int Y, // Vertical position - int cx, // Width - int cy, // Height - uint uFlags); // Window positioning flags - - [DllImport("user32.dll")] - static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); - - static void ShowInactiveTopmost(Form frm) + public static GraphicsPath RoundedRect(Rectangle bounds, int radius) { - ShowWindow(frm.Handle, SW_SHOWNOACTIVATE); - SetWindowPos(frm.Handle.ToInt32(), HWND_TOPMOST, - frm.Left, frm.Top, frm.Width, frm.Height, - SWP_NOACTIVATE); + int diameter = radius * 2; + Size size = new Size(diameter, diameter); + Rectangle arc = new Rectangle(bounds.Location, size); + GraphicsPath path = new GraphicsPath(); + + if (radius == 0) + { + path.AddRectangle(bounds); + return path; + } + + path.AddArc(arc, 180, 90); + arc.X = bounds.Right - diameter; + path.AddArc(arc, 270, 90); + arc.Y = bounds.Bottom - diameter; + path.AddArc(arc, 0, 90); + arc.X = bounds.Left; + path.AddArc(arc, 90, 90); + path.CloseFigure(); + return path; } - public ToastForm() + public static void FillRoundedRectangle(this Graphics graphics, Brush brush, Rectangle bounds, int cornerRadius) { - InitializeComponent(); + using (GraphicsPath path = RoundedRect(bounds, cornerRadius)) + { + graphics.FillPath(brush, path); + } + } + } + + class ToastForm : OSDNativeForm + { + + protected static string toastText = "Balanced"; + protected static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); + + protected override void PerformPaint(PaintEventArgs e) + { + Brush brush = new SolidBrush(Color.FromArgb(150,Color.Black)); + Drawing.FillRoundedRectangle(e.Graphics, brush, this.Bound, 10); + + StringFormat format = new StringFormat(); + format.LineAlignment = StringAlignment.Center; + format.Alignment = StringAlignment.Center; + + e.Graphics.DrawString(toastText, + new Font("Segoe UI", 16f, FontStyle.Bold), + new SolidBrush(Color.White), + new PointF(this.Bound.Width/2, this.Bound.Height / 2), + format); } public void RunToast(string text) { - Top = Screen.FromControl(this).WorkingArea.Height - this.Height - 100; - Left = (Screen.FromControl(this).Bounds.Width - this.Width) / 2; + toastText = text; + Screen screen1 = Screen.FromHandle(base.Handle); - ShowInactiveTopmost(this); + Width = 300; + Height = 100; + X = (screen1.Bounds.Width - this.Width)/2; + Y = screen1.Bounds.Height - 300 - this.Height; - labelMode.Text = text; + Show(); - timer = new System.Windows.Forms.Timer(); - timer.Tick += new EventHandler(timer_Tick); + timer.Stop(); + timer.Tick -= timer_Tick; + + timer.Tick += timer_Tick; timer.Enabled = true; - timer.Interval = 1000; + timer.Interval = 2000; timer.Start(); } - private void ToastForm_Show(object? sender, EventArgs e) - { - } - - private void timer_Tick(object sender, EventArgs e) + private void timer_Tick(object? sender, EventArgs e) { timer.Stop(); - Close(); + Hide(); } } } diff --git a/ToastForm.resx b/ToastForm.resx deleted file mode 100644 index f298a7be..00000000 --- a/ToastForm.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file