- Fix resize courser showing when windows are not in edit mode.

- Add more logging
- Implement some IntelliSense suggestions
This commit is contained in:
Stone-Red-Code
2021-10-26 23:16:38 +02:00
parent d75aef7460
commit b69bba68bb
11 changed files with 130 additions and 118 deletions
@@ -113,18 +113,18 @@ namespace DesktopMagic
{
listBox.Items.Clear();
CalendarItems calendarItem = new CalendarItems();
calendarItem.eventname = "Termine: ";
calendarItem.font = MainWindow.Theme.Font;
calendarItem.color = MainWindow.Theme.PrimaryColor.ToString();
calendarItem.Eventname = "Termine: ";
calendarItem.Font = MainWindow.Theme.Font;
calendarItem.Color = MainWindow.Theme.PrimaryColor.ToString();
listBox.Items.Add(calendarItem);
for (int i = 0; i < upcomingEventNames.Count; i++)
{
calendarItem = new CalendarItems();
calendarItem.eventname = upcomingEventNames[i];
calendarItem.dateTime = DateTime.Now.ToString("dd-MM-yyyy");
calendarItem.font = MainWindow.Theme.Font;
calendarItem.color = MainWindow.Theme.PrimaryBrush.ToString();
calendarItem.Eventname = upcomingEventNames[i];
calendarItem.DateTime = DateTime.Now.ToString("dd-MM-yyyy");
calendarItem.Font = MainWindow.Theme.Font;
calendarItem.Color = MainWindow.Theme.PrimaryBrush.ToString();
if (DateTime.Now < DateTime.Today.AddMonths(12) || upcomingEventTimes[i] == "-")
{
@@ -40,7 +40,7 @@ namespace DesktopMagic
cpuCounter.InstanceName = "_Total";
Timer t = new Timer();
t.Interval = 500;
t.Interval = 100;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
@@ -75,12 +75,16 @@ namespace DesktopMagic
if (MainWindow.EditMode)
{
panel.Visibility = Visibility.Visible;
tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
WindowPos.SetIsLocked(this, false);
ResizeMode = ResizeMode.CanResize;
}
else
{
panel.Visibility = Visibility.Collapsed;
tileBar.CaptionHeight = 0;
WindowPos.SetIsLocked(this, true);
ResizeMode = ResizeMode.NoResize;
}
textBlock.Background = MainWindow.Theme.BackgroundBrush;
@@ -58,12 +58,16 @@ namespace DesktopMagic
if (MainWindow.EditMode)
{
panel.Visibility = Visibility.Visible;
tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
WindowPos.SetIsLocked(this, false);
ResizeMode = ResizeMode.CanResize;
}
else
{
panel.Visibility = Visibility.Collapsed;
tileBar.CaptionHeight = 0;
WindowPos.SetIsLocked(this, true);
ResizeMode = ResizeMode.NoResize;
}
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
@@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Timers;
@@ -61,13 +62,13 @@ namespace DesktopMagic
key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName);
Top = double.Parse(key.GetValue("MusicVisualizerWindowTop", 100).ToString());
Top = double.Parse(key.GetValue("MusicVisualizerWindowTop", 100).ToString(), CultureInfo.InvariantCulture);
Left = double.Parse(key.GetValue("MusicVisualizerWindowLeft", 100).ToString());
Left = double.Parse(key.GetValue("MusicVisualizerWindowLeft", 100).ToString(), CultureInfo.InvariantCulture);
Height = double.Parse(key.GetValue("MusicVisualizerWindowHeight", 200).ToString());
Height = double.Parse(key.GetValue("MusicVisualizerWindowHeight", 200).ToString(), CultureInfo.InvariantCulture);
Width = double.Parse(key.GetValue("MusicVisualizerWindowWidth", 500).ToString());
Width = double.Parse(key.GetValue("MusicVisualizerWindowWidth", 500).ToString(), CultureInfo.InvariantCulture);
IsEnabled = false;
}
@@ -78,7 +79,7 @@ namespace DesktopMagic
//Set the window style to noactivate.
WindowInteropHelper helper = new WindowInteropHelper(this);
WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
_ = WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE,
WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
}
@@ -89,21 +90,18 @@ namespace DesktopMagic
if (MainWindow.EditMode)
{
panel.Visibility = Visibility.Visible;
tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
WindowPos.SetIsLocked(this, false);
ResizeMode = ResizeMode.CanResize;
}
else
{
panel.Visibility = Visibility.Collapsed;
tileBar.CaptionHeight = 0;
WindowPos.SetIsLocked(this, true);
ResizeMode = ResizeMode.NoResize;
}
if (!IsLoaded)
{
calculate = false;
}
else
{
calculate = true;
}
calculate = IsLoaded;
backgroundGrid.Background = MainWindow.Theme.BackgroundBrush;
});
}
@@ -134,7 +132,7 @@ namespace DesktopMagic
}
List<double> fft = new List<double>();
for (int i = 0; i < e.Result.Length / 2 - 70; i++)
for (int i = 0; i < (e.Result.Length / 2) - 70; i++)
{
int v = i;
if (v < 20)
@@ -142,7 +140,7 @@ namespace DesktopMagic
v = 20;
}
int multiplier = 100 - MainWindow.AmplifierLevel * 2;
int multiplier = 100 - (MainWindow.AmplifierLevel * 2);
multiplier = multiplier == 0 ? 1 : multiplier;
fft.Add(Math.Abs(e.Result[i].Y * v / multiplier));
}
@@ -173,7 +171,7 @@ namespace DesktopMagic
{
double temp = 0;
int j;
for (j = i * count; j < count + i * count; j++)
for (j = i * count; j < count + (i * count); j++)
{
temp += fft[j];
}
@@ -229,7 +227,7 @@ namespace DesktopMagic
{
Stopwatch sw = new Stopwatch();
sw.Start();
Bitmap bm = new Bitmap(885, 300);
Bitmap bm = new Bitmap(880, 300);
int offset = 0;
if (!MainWindow.MirrorMode && MainWindow.SpectrumMode != 1)
@@ -263,8 +261,8 @@ namespace DesktopMagic
if (!fftIndexReverse)
{
points[pointIndex + 1] = new PointF(bm.Width - 4 * pointIndex, bm.Height / 2 + value);
points[points.Length / 2 + pointIndex + 1] = new PointF(bm.Width - 4 * pointIndex, bm.Height / 2 - value);
points[pointIndex + 1] = new PointF(bm.Width - (4 * pointIndex), (bm.Height / 2) + value);
points[(points.Length / 2) + pointIndex + 1] = new PointF(bm.Width - (4 * pointIndex), (bm.Height / 2) - value);
}
break;
@@ -297,15 +295,9 @@ namespace DesktopMagic
SetPoints(points, bm.Width, bm.Height, offset);
Brush brush;
if (MainWindow.MusicVisualzerColor.HasValue)
{
brush = new SolidBrush(MainWindow.MusicVisualzerColor.Value);
}
else
{
brush = new SolidBrush(MainWindow.Theme.PrimaryColor);
}
Brush brush = MainWindow.MusicVisualzerColor.HasValue
? new SolidBrush(MainWindow.MusicVisualzerColor.Value)
: new SolidBrush(MainWindow.Theme.PrimaryColor);
if (MainWindow.LineMode)
{
@@ -325,10 +317,10 @@ namespace DesktopMagic
}
}
Dispatcher.BeginInvoke((Action)delegate
{
image.Source = BitmapToImageSource(bm);
});
_ = Dispatcher.BeginInvoke((Action)delegate
{
image.Source = BitmapToImageSource(bm);
});
}
catch { }
}
@@ -342,7 +334,7 @@ namespace DesktopMagic
points[^1] = new PointF(0, height / 2);
points[points.Length / 2] = new PointF(width, height / 2);
points[points.Length / 2 - 1] = new PointF(0, height / 2);
points[(points.Length / 2) - 1] = new PointF(0, height / 2);
break;
case 2:
@@ -31,7 +31,7 @@ namespace DesktopMagic
w.Hide();
Timer t = new Timer();
t.Interval = 500;
t.Interval = 100;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();
@@ -60,12 +60,16 @@ namespace DesktopMagic
if (MainWindow.EditMode)
{
panel.Visibility = Visibility.Visible;
tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
WindowPos.SetIsLocked(this, false);
ResizeMode = ResizeMode.CanResize;
}
else
{
panel.Visibility = Visibility.Collapsed;
tileBar.CaptionHeight = 0;
WindowPos.SetIsLocked(this, true);
ResizeMode = ResizeMode.NoResize;
}
textBlock.Background = MainWindow.Theme.BackgroundBrush;
+2 -1
View File
@@ -5,4 +5,5 @@
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "Windows only application")]
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "Windows only application")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "No need to")]
@@ -83,9 +83,9 @@ namespace DesktopMagic
internal class CalendarItems
{
public string eventname { get; set; }
public string dateTime { get; set; }
public string font { get; set; }
public string color { get; set; }
public string Eventname { get; set; }
public string DateTime { get; set; }
public string Font { get; set; }
public string Color { get; set; }
}
}
+20 -15
View File
@@ -541,7 +541,7 @@ namespace DesktopMagic
public static extern int GetSystemMetrics(int abc);
[DllImport("user32.dll", EntryPoint = "GetWindowDC")]
public static extern IntPtr GetWindowDC(Int32 ptr);
public static extern IntPtr GetWindowDC(int ptr);
[DllImport("user32.dll")]
public static extern bool IsWindowVisible(IntPtr hWnd);
@@ -559,7 +559,7 @@ namespace DesktopMagic
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, IntPtr lParam);
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr windowHandle, uint Msg, IntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags flags, uint timeout, out IntPtr result);
@@ -590,7 +590,7 @@ namespace DesktopMagic
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern Int32 SystemParametersInfo(UInt32 action, UInt32 uParam, string vParam, UInt32 winIni);
public static extern int SystemParametersInfo(uint action, uint uParam, string vParam, uint winIni);
[StructLayout(LayoutKind.Sequential)]
public struct BbStruct //Blur Behind Structure
@@ -642,37 +642,37 @@ namespace DesktopMagic
public int X
{
get { return Left; }
get => Left;
set { Right -= (Left - value); Left = value; }
}
public int Y
{
get { return Top; }
get => Top;
set { Bottom -= (Top - value); Top = value; }
}
public int Height
{
get { return Bottom - Top; }
set { Bottom = value + Top; }
get => Bottom - Top;
set => Bottom = value + Top;
}
public int Width
{
get { return Right - Left; }
set { Right = value + Left; }
get => Right - Left;
set => Right = value + Left;
}
public System.Drawing.Point Location
{
get { return new System.Drawing.Point(Left, Top); }
get => new System.Drawing.Point(Left, Top);
set { X = value.X; Y = value.Y; }
}
public System.Drawing.Size Size
{
get { return new System.Drawing.Size(Width, Height); }
get => new System.Drawing.Size(Width, Height);
set { Width = value.Width; Height = value.Height; }
}
@@ -703,10 +703,15 @@ namespace DesktopMagic
public override bool Equals(object obj)
{
if (obj is RECT)
return Equals((RECT)obj);
else if (obj is System.Drawing.Rectangle)
return Equals(new RECT((System.Drawing.Rectangle)obj));
if (obj is RECT rECT)
{
return Equals(rECT);
}
else if (obj is System.Drawing.Rectangle rectangle)
{
return Equals(new RECT(rectangle));
}
return false;
}
+10 -11
View File
@@ -29,8 +29,8 @@ namespace DesktopMagic
int cy,
uint uFlags);
private const UInt32 SWP_NOSIZE1 = 0x0001;
private const UInt32 SWP_NOMOVE1 = 0x0002;
private const uint SWP_NOSIZE1 = 0x0001;
private const uint SWP_NOMOVE1 = 0x0002;
private static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
@@ -42,7 +42,7 @@ namespace DesktopMagic
public static void SendWpfWindowBack(Window window)
{
var hWnd = new WindowInteropHelper(window).Handle;
IntPtr hWnd = new WindowInteropHelper(window).Handle;
SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE1 | SWP_NOMOVE1);
}
@@ -62,12 +62,12 @@ namespace DesktopMagic
private static void IsLocked_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var window = (Window)d;
var isHooked = d.GetValue(IsHookedProperty) != null;
Window window = (Window)d;
bool isHooked = d.GetValue(IsHookedProperty) != null;
if (!isHooked)
{
var hook = new WindowLockHook(window);
WindowLockHook hook = new WindowLockHook(window);
d.SetValue(IsHookedProperty, hook);
}
}
@@ -82,10 +82,9 @@ namespace DesktopMagic
public WindowLockHook(Window window)
{
this.Window = window;
Window = window;
var source = PresentationSource.FromVisual(window) as HwndSource;
if (source == null)
if (PresentationSource.FromVisual(window) is not HwndSource source)
{
// If there is no hWnd, we need to wait until there is
window.SourceInitialized += Window_SourceInitialized;
@@ -98,7 +97,7 @@ namespace DesktopMagic
private void Window_SourceInitialized(object sender, EventArgs e)
{
var source = (HwndSource)PresentationSource.FromVisual(Window);
HwndSource source = (HwndSource)PresentationSource.FromVisual(Window);
source.AddHook(WndProc);
}
@@ -106,7 +105,7 @@ namespace DesktopMagic
{
if (msg == WM_WINDOWPOSCHANGING && GetIsLocked(Window))
{
var wp = Marshal.PtrToStructure<WINDOWPOS>(lParam);
WINDOWPOS wp = Marshal.PtrToStructure<WINDOWPOS>(lParam);
wp.flags |= SWP_NOMOVE | SWP_NOSIZE;
Marshal.StructureToPtr(wp, lParam, false);
}
+47 -44
View File
@@ -4,9 +4,12 @@ using DesktopMagic.Plugins;
using Microsoft.Win32;
using Stone_Red_Utilities.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -81,7 +84,7 @@ namespace DesktopMagic
}
}
#region load
#region Load
private void Window_Loaded(object sender, RoutedEventArgs e)
{
@@ -105,8 +108,6 @@ namespace DesktopMagic
}
App.Logger.Log("Created layouts.save file", "Main");
_ = optionsComboBox.Items.Add(new Tuple<string, int>((string)FindResource("musicVisualizer"), 0));
//Write To Log File and Load Elements
App.Logger.Log("Loading Plugin names", "Main");
@@ -121,7 +122,8 @@ namespace DesktopMagic
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
_ = MessageBox.Show(ex.ToString());
}
}
@@ -137,7 +139,10 @@ namespace DesktopMagic
_ = Directory.CreateDirectory(PluginsPath + "\\" + PluginName);
File.Move(fileName, $"{PluginsPath}\\{PluginName}\\{PluginName}.dll");
}
catch { }
catch (Exception ex)
{
App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
}
}
foreach (string directory in Directory.GetDirectories(PluginsPath))
@@ -182,7 +187,7 @@ namespace DesktopMagic
}
}
#endregion load
#endregion Load
#region Windows
@@ -334,7 +339,7 @@ namespace DesktopMagic
#endregion Windows
#region options
#region Options
private void AmplifierLevelSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
@@ -658,7 +663,7 @@ namespace DesktopMagic
window?.Exit();
}
#endregion options
#endregion Options
private void TextBlock_Loaded(object sender, RoutedEventArgs e)
{
@@ -684,10 +689,6 @@ namespace DesktopMagic
}
}
private void ColorHexTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void ChangePrimaryColorButton_Click(object sender, RoutedEventArgs e)
{
ColorDialog colorDialog = new ColorDialog("Set Primary Color", Theme.PrimaryColor);
@@ -705,7 +706,6 @@ namespace DesktopMagic
private void ChangeSecondaryColorButton_Click(object sender, RoutedEventArgs e)
{
ColorDialog colorDialog = new ColorDialog("Set Secondary Color", Theme.SecondaryColor);
if (colorDialog.ShowDialog() == true)
{
Theme.SecondaryBrush = colorDialog.ResultBrush;
@@ -837,14 +837,14 @@ namespace DesktopMagic
string name = line[(line.LastIndexOf(";", StringComparison.InvariantCulture) + 1)..];
_ = layoutsComboBox.Items.Add(name);
}
layoutsComboBox.SelectedIndex = int.Parse(key.GetValue("SelectedLayout", "0").ToString());
layoutsComboBox.SelectedIndex = int.Parse(key.GetValue("SelectedLayout", "0").ToString(), CultureInfo.InvariantCulture);
}
private void LoadLayout(bool minimize = true)
{
Theme.Font = key.GetValue("Font", "Segoe UI").ToString();
spectrumModeComboBox.SelectedIndex = int.Parse(key.GetValue("SpectrumMode", "0").ToString());
amplifierLevelSlider.Value = int.Parse(key.GetValue("AmplifierLevel", "0").ToString());
spectrumModeComboBox.SelectedIndex = int.Parse(key.GetValue("SpectrumMode", "0").ToString(), CultureInfo.InvariantCulture);
amplifierLevelSlider.Value = int.Parse(key.GetValue("AmplifierLevel", "0").ToString(), CultureInfo.InvariantCulture);
mirrorModeCheckBox.IsChecked = bool.Parse(key.GetValue("MirrorMode", "false").ToString());
lineModeCheckBox.IsChecked = bool.Parse(key.GetValue("LineMode", "false").ToString());
musicVisualizerColorTextBox.Text = key.GetValue("MusicVisualizerColor", "").ToString();
@@ -890,6 +890,9 @@ namespace DesktopMagic
blockWindowsClosing = true;
Windows.Clear();
WindowNames.Clear();
optionsComboBox.Items.Clear();
_ = optionsComboBox.Items.Add(new Tuple<string, int>((string)FindResource("musicVisualizer"), 0));
IEnumerable<CheckBox> list = stackPanel.Children.OfType<CheckBox>();
bool showWindow = true;
@@ -914,7 +917,7 @@ namespace DesktopMagic
catch (Exception ex)
{
App.Logger.Log(ex.ToString(), "Main");
MessageBox.Show(ex.ToString());
_ = MessageBox.Show(ex.ToString());
}
}
}
@@ -941,16 +944,16 @@ namespace DesktopMagic
private void UpdatePluginsButton_Click(object sender, RoutedEventArgs e)
{
LoadPlugins();
Task.Run(() =>
{
foreach (Window window in Windows.ToArray())
{
if (window.GetType() == typeof(PluginWindow))
{
((PluginWindow)window).UpdatePluginWindow();
}
}
});
_ = Task.Run(() =>
{
foreach (Window window in Windows.ToArray())
{
if (window.GetType() == typeof(PluginWindow))
{
((PluginWindow)window).UpdatePluginWindow();
}
}
});
}
private void OpenPluginsFolderButton_Click(object sender, RoutedEventArgs e)
@@ -973,27 +976,11 @@ namespace DesktopMagic
Visibility = Visibility.Visible;
SystemCommands.RestoreWindow(this);
Topmost = true;
Activate();
_ = Activate();
Topmost = false;
}
}
private void SetLanguageDictionary()
{
ResourceDictionary dict = new ResourceDictionary();
string currentCulture = Thread.CurrentThread.CurrentUICulture.ToString();
if (currentCulture.Contains("de"))
{
dict.Source = new Uri("..\\Resources\\StringResources.de.xaml", UriKind.Relative);
}
else
{
dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative);
}
Resources.MergedDictionaries.Add(dict);
}
private void GithubButton_Click(object sender, RoutedEventArgs e)
{
string uri = "https://github.com/Stone-Red-Code/DesktopMagic";
@@ -1011,5 +998,21 @@ namespace DesktopMagic
psi.FileName = uri;
_ = Process.Start(psi);
}
private void SetLanguageDictionary()
{
ResourceDictionary dict = new ResourceDictionary();
string currentCulture = Thread.CurrentThread.CurrentUICulture.ToString();
if (currentCulture.Contains("de"))
{
dict.Source = new Uri("..\\Resources\\StringResources.de.xaml", UriKind.Relative);
}
else
{
dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative);
}
Resources.MergedDictionaries.Add(dict);
}
}
}
@@ -283,7 +283,7 @@ namespace DesktopMagic
}
}
private BitmapSource BitmapToImageSource(Bitmap bitmap)
private static BitmapSource BitmapToImageSource(Bitmap bitmap)
{
BitmapData bitmapData = bitmap.LockBits(
new Rectangle(0, 0, bitmap.Width, bitmap.Height),