Skip to content

Commit

Permalink
ED
Browse files Browse the repository at this point in the history
  • Loading branch information
pieckenst committed Nov 10, 2024
1 parent 3b4d1e8 commit 13438a3
Show file tree
Hide file tree
Showing 125 changed files with 1,743 additions and 100 deletions.
Binary file modified .vs/handlerlaunch/v17/.suo
Binary file not shown.
16 changes: 8 additions & 8 deletions .vs/handlerlaunch/v17/DocumentLayout.backup.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"Version": 1,
"WorkspaceRootPath": "G:\\code\\WebLaunch\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|g:\\code\\weblaunch\\spinningwheellib\\window1.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|solutionrelative:spinningwheellib\\window1.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|g:\\code\\weblaunch\\spinningwheellib\\window1.xaml||{F11ACC28-31D1-4C80-A34B-F4E09D3D753C}",
"RelativeMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|solutionrelative:spinningwheellib\\window1.xaml||{F11ACC28-31D1-4C80-A34B-F4E09D3D753C}"
},
{
"AbsoluteMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|g:\\code\\weblaunch\\spinningwheellib\\window1.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|solutionrelative:spinningwheellib\\window1.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{6D7D239E-33BB-4509-AC21-1DC7C36D403F}|handlerlaunch\\handlerlaunch.csproj|g:\\code\\weblaunch\\handlerlaunch\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{6D7D239E-33BB-4509-AC21-1DC7C36D403F}|handlerlaunch\\handlerlaunch.csproj|solutionrelative:handlerlaunch\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
Expand Down Expand Up @@ -104,7 +104,7 @@
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 11,
"SelectedChildIndex": 13,
"Children": [
{
"$type": "Document",
Expand Down Expand Up @@ -237,13 +237,13 @@
},
{
"$type": "Document",
"DocumentIndex": 0,
"DocumentIndex": 1,
"Title": "Window1.xaml.cs",
"DocumentMoniker": "G:\\code\\WebLaunch\\SpinningWheelLib\\Window1.xaml.cs",
"RelativeDocumentMoniker": "SpinningWheelLib\\Window1.xaml.cs",
"ToolTip": "G:\\code\\WebLaunch\\SpinningWheelLib\\Window1.xaml.cs",
"RelativeToolTip": "SpinningWheelLib\\Window1.xaml.cs",
"ViewState": "AgIAAEQBAAAAAAAAAAAYwGEBAAAJAAAAAAAAAA==",
"ViewState": "AgIAAAkCAAAAAAAAAAAjwCUCAAAAAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-11-04T14:12:03.403Z",
"EditorCaption": ""
Expand All @@ -263,7 +263,7 @@
},
{
"$type": "Document",
"DocumentIndex": 1,
"DocumentIndex": 0,
"Title": "Window1.xaml",
"DocumentMoniker": "G:\\code\\WebLaunch\\SpinningWheelLib\\Window1.xaml",
"RelativeDocumentMoniker": "SpinningWheelLib\\Window1.xaml",
Expand Down
16 changes: 8 additions & 8 deletions .vs/handlerlaunch/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"Version": 1,
"WorkspaceRootPath": "G:\\code\\WebLaunch\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|g:\\code\\weblaunch\\spinningwheellib\\window1.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|solutionrelative:spinningwheellib\\window1.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|g:\\code\\weblaunch\\spinningwheellib\\window1.xaml||{F11ACC28-31D1-4C80-A34B-F4E09D3D753C}",
"RelativeMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|solutionrelative:spinningwheellib\\window1.xaml||{F11ACC28-31D1-4C80-A34B-F4E09D3D753C}"
},
{
"AbsoluteMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|g:\\code\\weblaunch\\spinningwheellib\\window1.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{1629F3CE-F4A2-42EC-ABF2-C9200EB1BD38}|SpinningWheelLib\\SpinningWheelLib.csproj|solutionrelative:spinningwheellib\\window1.xaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{6D7D239E-33BB-4509-AC21-1DC7C36D403F}|handlerlaunch\\handlerlaunch.csproj|g:\\code\\weblaunch\\handlerlaunch\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{6D7D239E-33BB-4509-AC21-1DC7C36D403F}|handlerlaunch\\handlerlaunch.csproj|solutionrelative:handlerlaunch\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
Expand Down Expand Up @@ -104,7 +104,7 @@
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 11,
"SelectedChildIndex": 13,
"Children": [
{
"$type": "Document",
Expand Down Expand Up @@ -237,13 +237,13 @@
},
{
"$type": "Document",
"DocumentIndex": 0,
"DocumentIndex": 1,
"Title": "Window1.xaml.cs",
"DocumentMoniker": "G:\\code\\WebLaunch\\SpinningWheelLib\\Window1.xaml.cs",
"RelativeDocumentMoniker": "SpinningWheelLib\\Window1.xaml.cs",
"ToolTip": "G:\\code\\WebLaunch\\SpinningWheelLib\\Window1.xaml.cs",
"RelativeToolTip": "SpinningWheelLib\\Window1.xaml.cs",
"ViewState": "AgIAAHkBAAAAAAAAAAAYwKgBAAAJAAAAAAAAAA==",
"ViewState": "AgIAAAkCAAAAAAAAAAAjwCUCAAAAAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-11-04T14:12:03.403Z",
"EditorCaption": ""
Expand All @@ -263,7 +263,7 @@
},
{
"$type": "Document",
"DocumentIndex": 1,
"DocumentIndex": 0,
"Title": "Window1.xaml",
"DocumentMoniker": "G:\\code\\WebLaunch\\SpinningWheelLib\\Window1.xaml",
"RelativeDocumentMoniker": "SpinningWheelLib\\Window1.xaml",
Expand Down
214 changes: 136 additions & 78 deletions SpinningWheelLib/Window1.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
Expand Down Expand Up @@ -113,7 +115,16 @@ public partial class Window1 : Window
public delegate IEnumerable<string> ListItemsProvider();
public delegate void ButtonClickHandler(object sender, RoutedEventArgs e);
private DispatcherTimer _autoCloseTimer;
private const uint HWND_TOP = 0;
private const uint SWP_SHOWWINDOW = 0x0040;
private const uint SWP_NOZORDER = 0x0004;

[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

private bool _needsCentering;
private double _desiredWidth;
private double _desiredHeight;

public Window1(double estimatedDurationInSeconds = 30, bool isMessageBox = false,
string customLabel = "Loading...", double? customWidth = null, double? customHeight = null,
Expand Down Expand Up @@ -244,74 +255,77 @@ public void WriteToConsole(string text, Color color)
private void ConfigureAsMessageBox(string message, string title, string icon, List<string> listItems,
string footerText, double? customWidth, double? customHeight, ListItemsProvider listItemsProvider,
RoutedEventHandler okHandler = null, RoutedEventHandler cancelHandler = null, bool hideButtons = false)
{
try
{
Console.WriteLine($"[ConfigureAsMessageBox] Start - {DateTime.Now}");

// Get full stack trace using StackTrace class
var stackTrace = new StackTrace(true);
Console.WriteLine("Full Call Stack:");
foreach (var frame in stackTrace.GetFrames() ?? Array.Empty<StackFrame>())
{
try
{
var method = frame?.GetMethod();
var fileName = frame?.GetFileName();
Console.WriteLine($" at {method?.DeclaringType}.{method?.Name} in {fileName}:line {frame?.GetFileLineNumber()}");
}
catch (Exception ex)
{
Console.WriteLine($"Error getting stack frame details: {ex.Message}");
}
}
{
Console.WriteLine($"[ConfigureAsMessageBox] Start - {DateTime.Now}");
var stackTrace = new StackTrace(true);
Console.WriteLine("Full Call Stack:");
foreach (var frame in stackTrace.GetFrames())
{
Console.WriteLine($" at {frame.GetMethod().DeclaringType}.{frame.GetMethod().Name}");
}

Console.WriteLine($"Parameters: Title={title}, Width={customWidth}, Height={customHeight}, Icon={icon}");

Title = title ?? string.Empty;
Width = customWidth ?? MessageBoxMinWidth;
Height = customHeight ?? MessageBoxMinHeight;
MinWidth = MessageBoxMinWidth;
MinHeight = MessageBoxMinHeight;

Console.WriteLine("Setting window properties");
ResizeMode = ResizeMode.NoResize;
ShowInTaskbar = true;

Console.WriteLine("Configuring visibility");
if (ProgressContent != null)
ProgressContent.Visibility = Visibility.Collapsed;
if (MessageBoxContent != null)
MessageBoxContent.Visibility = Visibility.Visible;

Console.WriteLine("Setting message content");
if (MessageIcon != null)
MessageIcon.Text = icon ?? string.Empty;
if (MessageTitle != null)
MessageTitle.Text = title ?? string.Empty;
if (MessageText != null)
MessageText.Text = message ?? string.Empty;

ConfigureMessageBoxButtons(hideButtons, okHandler, cancelHandler);
ConfigureMessageBoxList(listItems, listItemsProvider);
if (MessageFooter != null)
MessageFooter.Text = footerText ?? string.Empty;

Console.WriteLine("Setting window position");
var workArea = SystemParameters.WorkArea;
Left = (workArea.Width - Width) / 2;
Top = (workArea.Height - Height) / 2;
_positionSet = true;

Console.WriteLine($"Final window position: Left={Left}, Top={Top}, Width={Width}, Height={Height}");
Console.WriteLine($"[ConfigureAsMessageBox] End - {DateTime.Now}");
}
catch (Exception ex)
{
Console.WriteLine($"Error in ConfigureAsMessageBox: {ex.Message}");
throw;
}
Title = title;
Width = customWidth ?? MessageBoxMinWidth;
Height = customHeight ?? MessageBoxMinHeight;
MinWidth = MessageBoxMinWidth;
MinHeight = MessageBoxMinHeight;
WindowStyle = WindowStyle.SingleBorderWindow;
AllowsTransparency = false;
Background = new SolidColorBrush(Color.FromRgb(236, 233, 216));
ResizeMode = ResizeMode.NoResize;

ProgressContent.Visibility = Visibility.Collapsed;
MessageBoxContent.Visibility = Visibility.Visible;

MessageIcon.Text = icon;
MessageTitle.Text = title;
MessageText.Text = message;

ConfigureMessageBoxButtons(hideButtons, okHandler, cancelHandler);
ConfigureMessageBoxList(listItems, listItemsProvider);
MessageFooter.Text = footerText;

Console.WriteLine("Forcing window position");
WindowStartupLocation = WindowStartupLocation.Manual;
Left = 0;
Top = 0;

// Force immediate layout update
UpdateLayout();

// Now move to center
var screenWidth = SystemParameters.PrimaryScreenWidth;
var screenHeight = SystemParameters.PrimaryScreenHeight;

Left = (screenWidth - Width) / 2;
Top = (screenHeight - Height) / 2;

// Force position using Win32 if needed
try
{
var helper = new WindowInteropHelper(this);
if (helper.Handle != IntPtr.Zero)
{
SetWindowPos(helper.Handle, IntPtr.Zero,
(int)Left, (int)Top,
(int)Width, (int)Height,
SWP_NOZORDER | SWP_SHOWWINDOW);
}
}
catch (Exception ex)
{
Console.WriteLine($"Win32 positioning failed: {ex.Message}");
}

_positionSet = true;
Console.WriteLine($"Final forced position: Left={Left}, Top={Top}, Width={Width}, Height={Height}");
Console.WriteLine("Setting up deferred centering");
_needsCentering = true;
_desiredWidth = customWidth ?? MessageBoxMinWidth;
_desiredHeight = customHeight ?? MessageBoxMinHeight;
}



private void ConfigureMessageBoxButtons(bool hideButtons, RoutedEventHandler okHandler, RoutedEventHandler cancelHandler)
{
Expand Down Expand Up @@ -411,20 +425,64 @@ private void ConfigureMessageBoxList(List<string> listItems, ListItemsProvider l
}
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
Console.WriteLine($"OnSourceInitialized called, _positionSet={_positionSet}, _isMessageBox={_isMessageBox}");

if (_isMessageBox)
{
Console.WriteLine("MessageBox mode - skipping SetWindowPosition");
return;
}
{
base.OnSourceInitialized(e);
Console.WriteLine($"Initial window position: Left={Left}, Top={Top}");

SetWindowPosition();
if (_needsCentering)
{
var helper = new WindowInteropHelper(this);
var source = PresentationSource.FromVisual(this);
double dpiScale = source?.CompositionTarget?.TransformFromDevice.M11 ?? 1.0;

// Force initial position to 0,0
Left = 0;
Top = 0;
UpdateLayout();
Console.WriteLine($"Position after reset: Left={Left}, Top={Top}");

var workArea = SystemParameters.WorkArea;
double scaledWidth = ActualWidth * dpiScale;
double scaledHeight = ActualHeight * dpiScale;

// Calculate center position
double centerX = (workArea.Width - scaledWidth) / 2;
double centerY = (workArea.Height - scaledHeight) / 2;
Console.WriteLine($"Calculated center: X={centerX}, Y={centerY}");

// First position update
SetWindowPos(helper.Handle, IntPtr.Zero,
(int)centerX, (int)centerY,
(int)scaledWidth, (int)scaledHeight,
SWP_NOZORDER | SWP_SHOWWINDOW);

Console.WriteLine($"Position after first update: Left={Left}, Top={Top}");

// If not at 0,0, force it
if (Math.Abs(Left) > 0 || Math.Abs(Top) > 0)
{
Console.WriteLine("Position not at 0,0, forcing center position");
SetWindowPos(helper.Handle, IntPtr.Zero, 0, 0,
(int)scaledWidth, (int)scaledHeight,
SWP_NOZORDER | SWP_SHOWWINDOW);

// Final center calculation from 0,0
centerX = workArea.Width / 2 - scaledWidth / 2;
centerY = workArea.Height / 2 - scaledHeight / 2;

SetWindowPos(helper.Handle, IntPtr.Zero,
(int)centerX, (int)centerY,
(int)scaledWidth, (int)scaledHeight,
SWP_NOZORDER | SWP_SHOWWINDOW);
}



Console.WriteLine($"Final position: Left={Left}, Top={Top}");
}
else if (!_isMessageBox)
{
SetWindowPosition();
}
}
private void Expander_Expanded(object sender, RoutedEventArgs e)
{
var workArea = SystemParameters.WorkArea;
Expand Down
Binary file not shown.
Binary file modified SpinningWheelLib/bin/Debug/net9.0-windows7.0/SpinningWheelLib.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("SpinningWheelLib")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+48d22586120c1272eefb99abe48d9b5747a13ca4")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3b4d1e82d67fe2c8cea8fefbdce731155328f891")]
[assembly: System.Reflection.AssemblyProductAttribute("SpinningWheelLib")]
[assembly: System.Reflection.AssemblyTitleAttribute("SpinningWheelLib")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9e46fc7f389e88456512bd8e5bdbf992f8bd47cd413c6c20d87d30e3d895f6ed
81ed256b3784a11d58d1a9902bb8f9b5c872af712bf57d5d6cad61872a2532cd
Binary file not shown.
Binary file modified SpinningWheelLib/obj/Debug/net9.0-windows7.0/SpinningWheelLib.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"G:\\code\\WebLaunch\\*":"https://raw.githubusercontent.com/pieckenst/WebLaunch/48d22586120c1272eefb99abe48d9b5747a13ca4/*"}}
{"documents":{"G:\\code\\WebLaunch\\*":"https://raw.githubusercontent.com/pieckenst/WebLaunch/3b4d1e82d67fe2c8cea8fefbdce731155328f891/*"}}
Loading

0 comments on commit 13438a3

Please sign in to comment.