Skip to content

Commit 9b97048

Browse files
committed
Issues #10 Added new CLI switches
1 parent fbc4da9 commit 9b97048

File tree

5 files changed

+68
-8
lines changed

5 files changed

+68
-8
lines changed

SmartContextMenu/Forms/MainForm.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,19 @@ public partial class MainForm : Form
3636
private List<DimForm> _dimForms;
3737
private IDictionary<IntPtr, Window> _windows;
3838

39-
public MainForm(ApplicationSettings settings)
39+
public MainForm(ApplicationSettings settings, params Window[] windows)
4040
{
4141
InitializeComponent();
4242
_settings = settings;
4343
_systemTrayMenu = new SystemTrayMenu();
4444
_menu = new ContextMenuStrip();
45-
_windows = new Dictionary<IntPtr, Window>();
4645
_dimHandle = IntPtr.Zero;
4746
_dimForms = new List<DimForm>();
47+
_windows = new Dictionary<IntPtr, Window>();
48+
foreach (var window in windows)
49+
{
50+
_windows.Add(window.Handle, window);
51+
}
4852
}
4953

5054
protected override void OnLoad(EventArgs e)

SmartContextMenu/Native/Structs/Rect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace SmartContextMenu.Native.Structs
44
{
55
[StructLayout(LayoutKind.Sequential)]
6-
struct Rect
6+
public struct Rect
77
{
88
public int Left;
99
public int Top;

SmartContextMenu/Program.cs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void Main(string[] args)
4444
return;
4545
}
4646

47-
ProcessCommandLine(commandLineParser, settings);
47+
var windows = ProcessCommandLine(commandLineParser, settings);
4848

4949
if (commandLineParser.HasToggle("n") || commandLineParser.HasToggle("nogui"))
5050
{
@@ -60,10 +60,10 @@ static void Main(string[] args)
6060

6161
Application.EnableVisualStyles();
6262
Application.SetCompatibleTextRenderingDefault(false);
63-
Application.Run(new MainForm(settings));
63+
Application.Run(new MainForm(settings, windows.ToArray()));
6464
}
6565

66-
static void ProcessCommandLine(CommandLineParser сommandLineParser, ApplicationSettings settings)
66+
static ICollection<Window> ProcessCommandLine(CommandLineParser сommandLineParser, ApplicationSettings settings)
6767
{
6868
// Delay
6969
if (сommandLineParser.HasToggle("d") || сommandLineParser.HasToggle("delay"))
@@ -128,11 +128,17 @@ static void ProcessCommandLine(CommandLineParser сommandLineParser, Application
128128
windowHandles.AddRange(handles);
129129
}
130130

131+
var windows = new Dictionary<IntPtr, Window>();
131132
var languageManager = new LanguageManager(settings.LanguageName);
132133
foreach (var windowHandle in windowHandles.Where(x => x != IntPtr.Zero && User32.GetParent(x) == IntPtr.Zero))
133134
{
134135
var window = new Window(windowHandle, languageManager);
135136

137+
if (!windows.ContainsKey(window.Handle))
138+
{
139+
windows.Add(window.Handle, window);
140+
}
141+
136142
// Set a Window monitor
137143
if (сommandLineParser.HasToggle("m") || сommandLineParser.HasToggle("monitor"))
138144
{
@@ -287,6 +293,47 @@ static void ProcessCommandLine(CommandLineParser сommandLineParser, Application
287293
window.SendToBottom();
288294
}
289295

296+
// Roll Up
297+
if (сommandLineParser.HasToggle("r") || сommandLineParser.HasToggle("rollup"))
298+
{
299+
window.RollUpDown();
300+
}
301+
302+
// Borderless
303+
if (сommandLineParser.HasToggle("b") || сommandLineParser.HasToggle("borderless"))
304+
{
305+
window.MakeBorderless();
306+
}
307+
308+
// Hide
309+
if (сommandLineParser.HasToggle("hide"))
310+
{
311+
var hideString = сommandLineParser.GetToggleValueOrDefault("hide", string.Empty).ToLower();
312+
313+
if (hideString == "on")
314+
{
315+
User32.ShowWindow(window.Handle, (int)WindowShowStyle.Hide);
316+
}
317+
318+
if (hideString == "off")
319+
{
320+
User32.ShowWindow(window.Handle, (int)WindowShowStyle.Show);
321+
}
322+
}
323+
324+
// System Menu
325+
if (сommandLineParser.HasToggle("systemmenu"))
326+
{
327+
var systemmenuString = сommandLineParser.GetToggleValueOrDefault("systemmenu", string.Empty).ToLower();
328+
switch (systemmenuString)
329+
{
330+
case "restore": window.Restore(); break;
331+
case "minimize": window.Minimize(); break;
332+
case "maximize": window.Maximize(); break;
333+
case "close": window.Close(); break;
334+
}
335+
}
336+
290337
// Open File In Explorer
291338
if (сommandLineParser.HasToggle("o") || сommandLineParser.HasToggle("openinexplorer"))
292339
{
@@ -383,6 +430,8 @@ static void ProcessCommandLine(CommandLineParser сommandLineParser, Application
383430
}
384431
}
385432
}
433+
434+
return windows.Values;
386435
}
387436

388437
static void OnCurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
@@ -428,14 +477,21 @@ static string BuildHelpString() =>
428477
normal,
429478
belownormal,
430479
idle]
480+
--systemmenu [restore,
481+
minimize,
482+
maximize,
483+
close]
431484
--transparency [0 ... 100]
432485
--alwaysontop [on, off]
433486
-g --aeroglass [on, off]
487+
--hide [on, off]
434488
--hidealttab [on, off]
435489
--clickthrough [on, off]
436490
--minimizebutton [on, off]
437491
--maximizebutton [on, off]
438492
--sendtobottom Send To Bottom
493+
-b --borderless Borderless
494+
-r --rollup Roll Up
439495
-o --openinexplorer Open File In Explorer
440496
-c --copytoclipboard Copy Window Text To Clipboard
441497
--copyscreenshot Copy Screenshot To Clipboard

SmartContextMenu/Window.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace SmartContextMenu
1818
{
19-
class Window : IDisposable
19+
public class Window : IDisposable
2020
{
2121
private bool _isManaged;
2222
private bool _suspended;

SmartContextMenu/WindowDetails.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SmartContextMenu
66
{
7-
class WindowDetails
7+
public class WindowDetails
88
{
99
public string GetWindowText { get; set; }
1010

0 commit comments

Comments
 (0)