+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

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
@ -256,6 +257,7 @@ namespace SystemTrayMenu.Controls
bool disposed = false;
Logger log = new Logger(nameof(RowData));
internal string TargetFilePathOrig;
internal bool HiddenEntry;
public RowData()
{
@ -462,7 +464,15 @@ namespace SystemTrayMenu.Controls
}
DataGridViewImageCell cellIcon =
(DataGridViewImageCell)row.Cells[0];
if (HiddenEntry)
{
cellIcon.Value = AddIconOverlay(data.Icon, Properties.Resources.WhiteTransparency);
}
else
{
cellIcon.Value = data.Icon;
}
DataGridViewTextBoxCell cellName =
(DataGridViewTextBoxCell)row.Cells[1];
@ -471,6 +481,16 @@ namespace SystemTrayMenu.Controls
row.Tag = data;
}
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)

View file

@ -1,4 +1,5 @@
using System;
using Clearcove.Logging;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
@ -159,11 +160,20 @@ namespace SystemTrayMenu
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static void ShowInactiveTopmost(Form frm)
{
try
{
ShowWindow(frm.Handle, SW_SHOWNOACTIVATE);
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;
if (Directory.Exists(filePath))
{
FileAttributes attr = File.GetAttributes(filePath);
if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
FileAttributes attributes = File.GetAttributes(filePath);
if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
{
isDirectory = true;
}

View file

@ -289,5 +289,15 @@ namespace SystemTrayMenu.Properties {
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">
<value>..\Resources\NotSelected.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

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

View file

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