+Log exception in ShowInactiveTopmost
This commit is contained in:
Markus Hofknecht 2019-08-03 09:27:33 +02:00
parent 35f219b528
commit ae919586aa
8 changed files with 548 additions and 510 deletions

View file

@ -1,484 +1,504 @@
using Clearcove.Logging; using Clearcove.Logging;
using IWshRuntimeLibrary; using IWshRuntimeLibrary;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.Drawing.Imaging;
using System.Linq; using System.IO;
using System.Runtime.InteropServices; using System.Linq;
using System.Text; using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Text;
using SystemTrayMenu.Helper; using System.Windows.Forms;
using TAFactory.IconPack; using SystemTrayMenu.Helper;
using TAFactory.IconPack;
namespace SystemTrayMenu.Controls
{ namespace SystemTrayMenu.Controls
public class RowData : IDisposable {
{ public class RowData : IDisposable
public FileInfo FileInfo; {
public Icon Icon; public FileInfo FileInfo;
public bool ContainsMenu; public Icon Icon;
public bool IsContextMenuOpen; public bool ContainsMenu;
public bool ResolvedFileNotFound; public bool IsContextMenuOpen;
public string WorkingDirectory; public bool ResolvedFileNotFound;
public string Arguments; public string WorkingDirectory;
public string Arguments;
public bool IsResolvedLnk;
public string TargetFilePath; public bool IsResolvedLnk;
public string Text; public string TargetFilePath;
public string Text;
public Menu SubMenu;
public int RowIndex; public Menu SubMenu;
public int RowIndex;
public bool IsSelected;
public bool IsSelectedByKeyboard; public bool IsSelected;
public bool IsSelectedByKeyboard;
/// <summary> /// <summary>
/// Loads the icon /// Loads the icon
/// </summary> /// </summary>
/// <param name="isDirectory">True = directory, false = file</param> /// <param name="isDirectory">True = directory, false = file</param>
/// <param name="resolvedLnkPath">Discovered path when functions returns true</param> /// <param name="resolvedLnkPath">Discovered path when functions returns true</param>
/// <returns>True when linking to a different directory, otherwise false</returns> /// <returns>True when linking to a different directory, otherwise false</returns>
public bool ReadIcon(bool isDirectory, ref string resolvedLnkPath) public bool ReadIcon(bool isDirectory, ref string resolvedLnkPath)
{ {
bool isLnkDirectory = false; bool isLnkDirectory = false;
Logger log = new Logger(nameof(RowData)); Logger log = new Logger(nameof(RowData));
if (string.IsNullOrEmpty(TargetFilePath)) if (string.IsNullOrEmpty(TargetFilePath))
{ {
log.Warn($"ReadIcon called but TargetFilePath not set."); log.Warn($"ReadIcon called but TargetFilePath not set.");
return isLnkDirectory; return isLnkDirectory;
} }
if (isDirectory) if (isDirectory)
{ {
Icon = IconReader.GetFolderIcon(TargetFilePath, Icon = IconReader.GetFolderIcon(TargetFilePath,
IconReader.FolderType.Closed, false); IconReader.FolderType.Closed, false);
} }
else else
{ {
bool handled = false; bool handled = false;
string fileExtension = Path.GetExtension(TargetFilePath); string fileExtension = Path.GetExtension(TargetFilePath);
if (fileExtension == ".lnk") if (fileExtension == ".lnk")
{ {
handled = SetLnk(log, ref isLnkDirectory, handled = SetLnk(log, ref isLnkDirectory,
ref resolvedLnkPath); ref resolvedLnkPath);
} }
else if (fileExtension == ".url") else if (fileExtension == ".url")
{ {
handled = SetUrl(log); handled = SetUrl(log);
} }
else if (fileExtension == ".sln") else if (fileExtension == ".sln")
{ {
handled = SetSln(log); handled = SetSln(log);
} }
if (!handled) if (!handled)
{ {
try try
{ {
Icon = IconReader.GetFileIcon(TargetFilePath, false); Icon = IconReader.GetFileIcon(TargetFilePath, false);
// other project -> fails sometimes // other project -> fails sometimes
//icon = IconHelper.ExtractIcon(TargetFilePath, 0); //icon = IconHelper.ExtractIcon(TargetFilePath, 0);
// standard way -> fails sometimes // standard way -> fails sometimes
//icon = Icon.ExtractAssociatedIcon(filePath); //icon = Icon.ExtractAssociatedIcon(filePath);
// API Code Pack -> fails sometimes // API Code Pack -> fails sometimes
//ShellFile shellFile = ShellFile.FromFilePath(filePath); //ShellFile shellFile = ShellFile.FromFilePath(filePath);
//Bitmap shellThumb = shellFile.Thumbnail.ExtraLargeBitmap; //Bitmap shellThumb = shellFile.Thumbnail.ExtraLargeBitmap;
} }
catch (Exception ex) catch (Exception ex)
{ {
log.Info($"TargetFilePath:'{TargetFilePath}'"); log.Info($"TargetFilePath:'{TargetFilePath}'");
log.Error($"{ex.ToString()}"); log.Error($"{ex.ToString()}");
} }
} }
} }
return isLnkDirectory; return isLnkDirectory;
} }
private bool SetLnk(Logger log, ref bool isLnkDirectory, private bool SetLnk(Logger log, ref bool isLnkDirectory,
ref string resolvedLnkPath) ref string resolvedLnkPath)
{ {
bool handled = false; bool handled = false;
resolvedLnkPath = LnkHelper.ResolveShortcut(TargetFilePath); resolvedLnkPath = LnkHelper.ResolveShortcut(TargetFilePath);
if (LnkHelper.IsDirectory(resolvedLnkPath)) if (LnkHelper.IsDirectory(resolvedLnkPath))
{ {
Icon = IconReader.GetFolderIcon(TargetFilePath, Icon = IconReader.GetFolderIcon(TargetFilePath,
IconReader.FolderType.Open, true); IconReader.FolderType.Open, true);
handled = true; handled = true;
isLnkDirectory = true; isLnkDirectory = true;
} }
else if (string.IsNullOrEmpty(resolvedLnkPath)) else if (string.IsNullOrEmpty(resolvedLnkPath))
{ {
ResolvedFileNotFound = true; ResolvedFileNotFound = true;
log.Info($"Resolve '{TargetFilePath}' not possible => no icon"); log.Info($"Resolve '{TargetFilePath}' not possible => no icon");
} }
else else
{ {
IWshShell shell = new WshShell(); IWshShell shell = new WshShell();
var lnk = shell.CreateShortcut(TargetFilePath) var lnk = shell.CreateShortcut(TargetFilePath)
as IWshShortcut; as IWshShortcut;
Arguments = lnk.Arguments; Arguments = lnk.Arguments;
WorkingDirectory = lnk.WorkingDirectory; WorkingDirectory = lnk.WorkingDirectory;
string iconLocation = lnk.IconLocation; string iconLocation = lnk.IconLocation;
if (iconLocation.Length > 2) if (iconLocation.Length > 2)
{ {
iconLocation = iconLocation.Substring(0, iconLocation = iconLocation.Substring(0,
iconLocation.Length - 2); iconLocation.Length - 2);
if (System.IO.File.Exists(iconLocation)) if (System.IO.File.Exists(iconLocation))
{ {
try try
{ {
Icon = Icon.ExtractAssociatedIcon(iconLocation); Icon = Icon.ExtractAssociatedIcon(iconLocation);
handled = true; handled = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
log.Info($"iconLocation:'{iconLocation}'"); log.Info($"iconLocation:'{iconLocation}'");
log.Error($"{ex.ToString()}"); log.Error($"{ex.ToString()}");
} }
} }
} }
TargetFilePath = resolvedLnkPath; TargetFilePath = resolvedLnkPath;
} }
SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig)); SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig));
return handled; return handled;
} }
private bool SetUrl(Logger log) private bool SetUrl(Logger log)
{ {
bool handled = false; bool handled = false;
string iconFile = string.Empty; string iconFile = string.Empty;
try try
{ {
FileIni file = new FileIni(TargetFilePath); FileIni file = new FileIni(TargetFilePath);
iconFile = file.Value("IconFile", string.Empty); iconFile = file.Value("IconFile", string.Empty);
if (string.IsNullOrEmpty(iconFile)) if (string.IsNullOrEmpty(iconFile))
{ {
string browserPath = FileUrl.GetDefaultBrowserPath(); string browserPath = FileUrl.GetDefaultBrowserPath();
if (string.IsNullOrEmpty(browserPath)) if (string.IsNullOrEmpty(browserPath))
{ {
log.Info($"No default browser found!"); log.Info($"No default browser found!");
} }
else else
{ {
Icon = IconReader.GetFileIcon(browserPath, false); Icon = IconReader.GetFileIcon(browserPath, false);
handled = true; handled = true;
} }
} }
else if (System.IO.File.Exists(iconFile)) else if (System.IO.File.Exists(iconFile))
{ {
Icon = Icon.ExtractAssociatedIcon(iconFile); Icon = Icon.ExtractAssociatedIcon(iconFile);
handled = true; handled = true;
} }
else else
{ {
log.Info($"Resolve '{TargetFilePath}' not possible => no icon"); log.Info($"Resolve '{TargetFilePath}' not possible => no icon");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
log.Info($"TargetFilePath:'{TargetFilePath}', " + log.Info($"TargetFilePath:'{TargetFilePath}', " +
$"iconFile:'{iconFile}'"); $"iconFile:'{iconFile}'");
log.Error($"{ex.ToString()}"); log.Error($"{ex.ToString()}");
} }
SetText($"{FileInfo.Name.Substring(0, FileInfo.Name.Length - 4)}"); SetText($"{FileInfo.Name.Substring(0, FileInfo.Name.Length - 4)}");
return handled; return handled;
} }
[DllImport("shell32.dll")] [DllImport("shell32.dll")]
static extern int FindExecutable(string lpFile, string lpDirectory, [Out] StringBuilder lpResult); static extern int FindExecutable(string lpFile, string lpDirectory, [Out] StringBuilder lpResult);
private bool SetSln(Logger log) private bool SetSln(Logger log)
{ {
bool handled = false; bool handled = false;
var executable = new StringBuilder(1024); var executable = new StringBuilder(1024);
try try
{ {
FindExecutable(TargetFilePath, string.Empty, executable); FindExecutable(TargetFilePath, string.Empty, executable);
// icon = IconReader.GetFileIcon(executable, false); // icon = IconReader.GetFileIcon(executable, false);
// e.g. VS 2019 icon, need another icom in imagelist // e.g. VS 2019 icon, need another icom in imagelist
List<Icon> extractedIcons = IconHelper.ExtractAllIcons( List<Icon> extractedIcons = IconHelper.ExtractAllIcons(
executable.ToString()); executable.ToString());
Icon = extractedIcons.Last(); Icon = extractedIcons.Last();
handled = true; handled = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
log.Info($"TargetFilePath:'{TargetFilePath}', " + log.Info($"TargetFilePath:'{TargetFilePath}', " +
$"executable:'{executable.ToString()}'"); $"executable:'{executable.ToString()}'");
log.Error($"{ex.ToString()}"); log.Error($"{ex.ToString()}");
} }
return handled; return handled;
} }
public void SetText(string text) public void SetText(string text)
{ {
//text = $" {text}"; //text = $" {text}";
if (text.Length > MenuDefines.LengthMax) if (text.Length > MenuDefines.LengthMax)
{ {
text = $"{text.Substring(0, MenuDefines.LengthMax)}..."; text = $"{text.Substring(0, MenuDefines.LengthMax)}...";
} }
Text = text; Text = text;
} }
#warning sort this class and check for duplicated #warning sort this class and check for duplicated
public event Action<object, EventArgs> OpenMenu; public event Action<object, EventArgs> OpenMenu;
public bool IsLoading = false; public bool IsLoading = false;
public bool RestartLoading = false; public bool RestartLoading = false;
public BackgroundWorker Reading = new BackgroundWorker(); public BackgroundWorker Reading = new BackgroundWorker();
Icon icon = null; Icon icon = null;
//FontFamily fontFamily = new FontFamily("Segoe UI"); //FontFamily fontFamily = new FontFamily("Segoe UI");
//Font font = new Font(new FontFamily("Segoe UI"), 12F, //Font font = new Font(new FontFamily("Segoe UI"), 12F,
// FontStyle.Regular, GraphicsUnit.Pixel); // FontStyle.Regular, GraphicsUnit.Pixel);
WaitMenuOpen waitMenuOpen = new WaitMenuOpen(); WaitMenuOpen waitMenuOpen = new WaitMenuOpen();
bool resolvedFileNotFound = false; bool resolvedFileNotFound = false;
bool disposed = false; bool disposed = false;
Logger log = new Logger(nameof(RowData)); Logger log = new Logger(nameof(RowData));
internal string TargetFilePathOrig; internal string TargetFilePathOrig;
internal bool HiddenEntry;
public RowData()
{ public RowData()
Reading.WorkerSupportsCancellation = true; {
Reading.WorkerSupportsCancellation = true;
Initialize();
void Initialize() Initialize();
{ void Initialize()
//Margin = new Padding(0, 0, 0, 0); {
//FlatAppearance.BorderSize = 0; //Margin = new Padding(0, 0, 0, 0);
//UseVisualStyleBackColor = true; //FlatAppearance.BorderSize = 0;
//FlatStyle = FlatStyle.Flat; //UseVisualStyleBackColor = true;
//BackColor = MenuDefines.File; //FlatStyle = FlatStyle.Flat;
//FlatAppearance.BorderColor = MenuDefines.File; //BackColor = MenuDefines.File;
//Anchor = (AnchorStyles.Left | AnchorStyles.Right); //FlatAppearance.BorderColor = MenuDefines.File;
//AutoSize = true; //Anchor = (AnchorStyles.Left | AnchorStyles.Right);
//AutoSizeMode = AutoSizeMode.GrowAndShrink; //AutoSize = true;
//Font = new Font(fontFamily, 7, FontStyle.Regular, GraphicsUnit.Pixel); //AutoSizeMode = AutoSizeMode.GrowAndShrink;
//ForeColor = Color.Black; //Font = new Font(fontFamily, 7, FontStyle.Regular, GraphicsUnit.Pixel);
waitMenuOpen.DoOpen += WaitMenuOpen_DoOpen; //ForeColor = Color.Black;
waitMenuOpen.DoOpen += WaitMenuOpen_DoOpen;
//MouseLeave += MenuButton_MouseLeave;
//void MenuButton_MouseLeave(object sender, EventArgs e) //MouseLeave += MenuButton_MouseLeave;
//{ //void MenuButton_MouseLeave(object sender, EventArgs e)
// if (Tag == null && //{
// !isContextMenuOpen && // if (Tag == null &&
// !ContainsMenu) // !isContextMenuOpen &&
// { // !ContainsMenu)
// BackColor = MenuDefines.File; // {
// } // BackColor = MenuDefines.File;
//} // }
//}
//MouseEnter += Menubutton_MouseEnter;
//void Menubutton_MouseEnter(object sender, EventArgs e) //MouseEnter += Menubutton_MouseEnter;
//{ //void Menubutton_MouseEnter(object sender, EventArgs e)
// if (Tag == null && //{
// !ContainsMenu) // if (Tag == null &&
// { // !ContainsMenu)
// BackColor = MenuDefines.FileHover; // {
// } // BackColor = MenuDefines.FileHover;
//} // }
//}
//BackColorChanged += MenuButton_BackColorChanged;
//void MenuButton_BackColorChanged(object sender, EventArgs e) //BackColorChanged += MenuButton_BackColorChanged;
//{ //void MenuButton_BackColorChanged(object sender, EventArgs e)
// FlatAppearance.BorderColor = BackColor; //{
//} // FlatAppearance.BorderColor = BackColor;
//}
}
} }
}
//DoubleClick += MenuButton_DoubleClick;
public void DoubleClick() //DoubleClick += MenuButton_DoubleClick;
{ public void DoubleClick()
if (ContainsMenu) {
{ if (ContainsMenu)
try {
{ try
Process.Start("explorer.exe", TargetFilePath); {
} Process.Start("explorer.exe", TargetFilePath);
catch (Exception ex) }
{ catch (Exception ex)
log.Info($"TargetFilePath:'{TargetFilePath}', " + {
$"=>DirectoryNotFound?"); log.Info($"TargetFilePath:'{TargetFilePath}', " +
log.Error($"{ex.ToString()}"); $"=>DirectoryNotFound?");
ex = new DirectoryNotFoundException(); log.Error($"{ex.ToString()}");
MessageBox.Show(ex.Message); ex = new DirectoryNotFoundException();
} MessageBox.Show(ex.Message);
} }
} }
}
//MouseDown += MenuButton_MouseDown;
public void MouseDown(DataGridView dgv, MouseEventArgs e) //MouseDown += MenuButton_MouseDown;
{ public void MouseDown(DataGridView dgv, MouseEventArgs e)
if (ContainsMenu) {
{ if (ContainsMenu)
TriggerMenuOpener(); // Touchscreen {
} TriggerMenuOpener(); // Touchscreen
}
if (IsLoading)
{ if (IsLoading)
waitMenuOpen.Click(); {
} waitMenuOpen.Click();
}
if (e == null ||
e.Button == MouseButtons.Left && if (e == null ||
!ContainsMenu) e.Button == MouseButtons.Left &&
{ !ContainsMenu)
try {
{ try
//https://stackoverflow.com/questions/31627801/ {
Process p = new Process(); //https://stackoverflow.com/questions/31627801/
p.StartInfo = new ProcessStartInfo(TargetFilePath); Process p = new Process();
p.StartInfo.Arguments = Arguments; p.StartInfo = new ProcessStartInfo(TargetFilePath);
p.StartInfo.WorkingDirectory = WorkingDirectory; p.StartInfo.Arguments = Arguments;
p.StartInfo.CreateNoWindow = true; p.StartInfo.WorkingDirectory = WorkingDirectory;
p.Start(); p.StartInfo.CreateNoWindow = true;
} p.Start();
catch (Exception ex) }
{ catch (Exception ex)
log.Info($"TargetFilePath:'{ TargetFilePath}', " + {
$"=>FileNotFound?"); log.Info($"TargetFilePath:'{ TargetFilePath}', " +
log.Error($"{ex.ToString()}"); $"=>FileNotFound?");
if (resolvedFileNotFound) log.Error($"{ex.ToString()}");
{ if (resolvedFileNotFound)
ex = new FileNotFoundException(); {
} ex = new FileNotFoundException();
MessageBox.Show(ex.Message); }
} MessageBox.Show(ex.Message);
} }
}
if (e != null &&
e.Button == MouseButtons.Right && if (e != null &&
FileInfo != null && e.Button == MouseButtons.Right &&
dgv.Rows.Count > RowIndex) FileInfo != null &&
{ dgv.Rows.Count > RowIndex)
IsContextMenuOpen = true; {
IsContextMenuOpen = true;
#warning is there any other possiblity to raise selection changed event? dataGridView.ClearSelection(); seems to overwrite selected
IsSelected = true; #warning is there any other possiblity to raise selection changed event? dataGridView.ClearSelection(); seems to overwrite selected
dgv.Rows[RowIndex].Selected = true; IsSelected = true;
dgv.Rows[RowIndex].Selected = true;
try
{ try
ShellContextMenu ctxMnu = new ShellContextMenu(); {
Point location = dgv.FindForm().Location; ShellContextMenu ctxMnu = new ShellContextMenu();
Point point = new Point( Point location = dgv.FindForm().Location;
e.X + location.X + dgv.Location.X, Point point = new Point(
e.Y + location.Y + dgv.Location.Y); e.X + location.X + dgv.Location.X,
if (ContainsMenu) e.Y + location.Y + dgv.Location.Y);
{ if (ContainsMenu)
DirectoryInfo[] dir = new DirectoryInfo[1]; {
dir[0] = new DirectoryInfo(TargetFilePathOrig); DirectoryInfo[] dir = new DirectoryInfo[1];
ctxMnu.ShowContextMenu(dir, point); dir[0] = new DirectoryInfo(TargetFilePathOrig);
} ctxMnu.ShowContextMenu(dir, point);
else }
{ else
FileInfo[] arrFI = new FileInfo[1]; {
arrFI[0] = new FileInfo(TargetFilePathOrig); FileInfo[] arrFI = new FileInfo[1];
ctxMnu.ShowContextMenu(arrFI, point); arrFI[0] = new FileInfo(TargetFilePathOrig);
} ctxMnu.ShowContextMenu(arrFI, point);
} }
catch (Exception ex) }
{ catch (Exception ex)
MessageBox.Show(ex.ToString() + TargetFilePath); {
} MessageBox.Show(ex.ToString() + TargetFilePath);
}
if (!dgv.IsDisposed)
{ if (!dgv.IsDisposed)
IsSelected = false; {
dgv.Rows[RowIndex].Selected = false; IsSelected = false;
} dgv.Rows[RowIndex].Selected = false;
}
IsContextMenuOpen = false;
} IsContextMenuOpen = false;
} }
}
public void MenuLoaded()
{ public void MenuLoaded()
waitMenuOpen.MenuLoaded(); {
} waitMenuOpen.MenuLoaded();
}
public void StartMenuOpener()
{ public void StartMenuOpener()
if (ContainsMenu) {
{ if (ContainsMenu)
IsLoading = true; {
waitMenuOpen.Start(); IsLoading = true;
} waitMenuOpen.Start();
} }
}
private void TriggerMenuOpener()
{ private void TriggerMenuOpener()
if (ContainsMenu && IsLoading) {
{ if (ContainsMenu && IsLoading)
waitMenuOpen.Start(); {
} waitMenuOpen.Start();
} }
}
public void StopLoadMenuAndStartWaitToOpenIt()
{ public void StopLoadMenuAndStartWaitToOpenIt()
if (ContainsMenu) {
{ if (ContainsMenu)
waitMenuOpen.Stop(); {
//IsLoading = false; waitMenuOpen.Stop();
} //IsLoading = false;
} }
}
private void WaitMenuOpen_DoOpen()
{ private void WaitMenuOpen_DoOpen()
IsLoading = false; {
OpenMenu?.Invoke(this, null); IsLoading = false;
} OpenMenu?.Invoke(this, null);
}
public void SetData(RowData data, DataGridView dgv)
{ public void SetData(RowData data, DataGridView dgv)
data.RowIndex = dgv.Rows.Add(); {
DataGridViewRow row = dgv.Rows[data.RowIndex]; data.RowIndex = dgv.Rows.Add();
DataGridViewRow row = dgv.Rows[data.RowIndex];
if (Icon == null)
{ if (Icon == null)
Icon = Properties.Resources.SystemTrayMenu; {
} Icon = Properties.Resources.SystemTrayMenu;
DataGridViewImageCell cellIcon = }
(DataGridViewImageCell)row.Cells[0]; DataGridViewImageCell cellIcon =
cellIcon.Value = data.Icon; (DataGridViewImageCell)row.Cells[0];
DataGridViewTextBoxCell cellName = if (HiddenEntry)
(DataGridViewTextBoxCell)row.Cells[1]; {
cellName.Value = data.Text; cellIcon.Value = AddIconOverlay(data.Icon, Properties.Resources.WhiteTransparency);
}
row.Tag = data; else
} {
cellIcon.Value = data.Icon;
public void Dispose() }
{
if (!disposed) DataGridViewTextBoxCell cellName =
{ (DataGridViewTextBoxCell)row.Cells[1];
icon?.Dispose(); cellName.Value = data.Text;
waitMenuOpen.Dispose();
} row.Tag = data;
disposed = true; }
}
} public Icon AddIconOverlay(Icon originalIcon, Icon overlay)
} {
var target = new Bitmap(originalIcon.Width, originalIcon.Height, PixelFormat.Format32bppArgb);
var graphics = Graphics.FromImage(target);
graphics.DrawIcon(originalIcon, 0, 0);
graphics.DrawIcon(overlay, 0, 0);
target.MakeTransparent(target.GetPixel(1,1));
return Icon.FromHandle(target.GetHicon());
}
public void Dispose()
{
if (!disposed)
{
icon?.Dispose();
waitMenuOpen.Dispose();
}
disposed = true;
}
}
}

View file

@ -1,4 +1,5 @@
using System; using Clearcove.Logging;
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
@ -160,10 +161,19 @@ namespace SystemTrayMenu
static void ShowInactiveTopmost(Form frm) static void ShowInactiveTopmost(Form frm)
{ {
ShowWindow(frm.Handle, SW_SHOWNOACTIVATE); try
SetWindowPos(frm.Handle.ToInt32(), HWND_TOPMOST, {
frm.Left, frm.Top, frm.Width, frm.Height, ShowWindow(frm.Handle, SW_SHOWNOACTIVATE);
SWP_NOACTIVATE); SetWindowPos(frm.Handle.ToInt32(), HWND_TOPMOST,
frm.Left, frm.Top, frm.Width, frm.Height,
SWP_NOACTIVATE);
}
catch (Exception exception)
{
Logger log = new Logger(nameof(FadeForm));
log.Error($"{exception.ToString()}");
//MessageBox.Show(exception.ToString());
}
} }
} }
} }

View file

@ -194,8 +194,8 @@ namespace SystemTrayMenu
bool isDirectory = false; bool isDirectory = false;
if (Directory.Exists(filePath)) if (Directory.Exists(filePath))
{ {
FileAttributes attr = File.GetAttributes(filePath); FileAttributes attributes = File.GetAttributes(filePath);
if ((attr & FileAttributes.Directory) == FileAttributes.Directory) if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
{ {
isDirectory = true; isDirectory = true;
} }

View file

@ -289,5 +289,15 @@ namespace SystemTrayMenu.Properties {
return ((System.Drawing.Icon)(obj)); return ((System.Drawing.Icon)(obj));
} }
} }
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
/// </summary>
public static System.Drawing.Icon WhiteTransparency {
get {
object obj = ResourceManager.GetObject("WhiteTransparency", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
} }
} }

View file

@ -187,4 +187,7 @@
<data name="NotSelected" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="NotSelected" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\NotSelected.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\NotSelected.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="WhiteTransparency" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\White50Percentage.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -180,6 +180,7 @@
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Resources\White50Percentage.ico" />
<None Include="Resources\STM.ico" /> <None Include="Resources\STM.ico" />
<None Include="Resources\STM_black.ico" /> <None Include="Resources\STM_black.ico" />
<None Include="Resources\Selected.png" /> <None Include="Resources\Selected.png" />

View file

@ -451,23 +451,19 @@ namespace SystemTrayMenu
break; break;
} }
if (HideHiddenEntries || HideSystemEntries) // filter entries.. FileAttributes attributes = File.GetAttributes(directory);
bool hiddenEntry = attributes.HasFlag(FileAttributes.Hidden);
bool systemEntry = attributes.HasFlag(
FileAttributes.Hidden | FileAttributes.System);
if ((HideHiddenEntries && hiddenEntry) ||
(HideSystemEntries && systemEntry))
{ {
FileAttributes attributes = File.GetAttributes(directory); continue;
if (HideHiddenEntries) // filter hidden files..
{
if (attributes.HasFlag(FileAttributes.Hidden))
continue;
}
if (HideSystemEntries) // filter system files..
{
if (attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)) // both must be set to be hidden!
continue;
}
} }
RowData menuButtonData = ReadMenuButtonData(directory, false); RowData menuButtonData = ReadMenuButtonData(directory, false);
menuButtonData.ContainsMenu = true; menuButtonData.ContainsMenu = true;
menuButtonData.HiddenEntry = hiddenEntry;
string resolvedLnkPath = string.Empty; string resolvedLnkPath = string.Empty;
menuButtonData.ReadIcon(true, ref resolvedLnkPath); menuButtonData.ReadIcon(true, ref resolvedLnkPath);
menuData.RowDatas.Add(menuButtonData); menuData.RowDatas.Add(menuButtonData);
@ -500,21 +496,18 @@ namespace SystemTrayMenu
foreach (string file in files) foreach (string file in files)
{ {
if (worker != null && worker.CancellationPending) if (worker != null && worker.CancellationPending)
break;
if (HideHiddenEntries || HideSystemEntries) // filter entries..
{ {
FileAttributes attributes = File.GetAttributes(file); break;
if (HideHiddenEntries) // filter hidden files.. }
{
if (attributes.HasFlag(FileAttributes.Hidden)) FileAttributes attributes = File.GetAttributes(file);
continue; bool hiddenEntry = attributes.HasFlag(FileAttributes.Hidden);
} bool systemEntry = attributes.HasFlag(
if (HideSystemEntries) // filter system files.. FileAttributes.Hidden | FileAttributes.System);
{ if ((HideHiddenEntries && hiddenEntry) ||
if (attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)) // both must be set to be hidden! (HideSystemEntries && systemEntry))
continue; {
} continue;
} }
RowData menuButtonData = ReadMenuButtonData(file, false); RowData menuButtonData = ReadMenuButtonData(file, false);
@ -524,6 +517,7 @@ namespace SystemTrayMenu
// file is pointing to a directory, so prepare submenu // file is pointing to a directory, so prepare submenu
menuButtonData = ReadMenuButtonData(resolvedLnkPath, true, menuButtonData); menuButtonData = ReadMenuButtonData(resolvedLnkPath, true, menuButtonData);
menuButtonData.ContainsMenu = true; menuButtonData.ContainsMenu = true;
menuButtonData.HiddenEntry = hiddenEntry;
} }
menuData.RowDatas.Add(menuButtonData); menuData.RowDatas.Add(menuButtonData);