Skip to content

Commit

Permalink
update: add Wice demo
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Jul 22, 2024
1 parent 13919db commit 9e53bb7
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 1 deletion.
62 changes: 62 additions & 0 deletions NotifyIcon.Demo.Wice/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Diagnostics;
using System.Reflection;
using NotifyIcon = NotifyIconEx.NotifyIcon;

namespace WiceApp1;

internal class App : Wice.Application
{
public App()
{
var notifyIcon = new NotifyIcon()
{
Text = "NotifyIcon",
Icon = Icon.ExtractAssociatedIcon(Process.GetCurrentProcess().MainModule?.FileName!)!,
};
notifyIcon.AddMenu("MenuItem1", new Bitmap(ResourceHelper.GetStream("NotifyIcon.Demo.Wice.Assets.Images.Lock.png")));
var toDisableItem = notifyIcon.AddMenu("MenuItem2", new Bitmap(ResourceHelper.GetStream("NotifyIcon.Demo.Wice.Assets.Images.Lock.png")));
notifyIcon.AddMenu("-");
notifyIcon.AddMenu("MenuItem3");
notifyIcon.AddMenu("MenuItem4", true);
notifyIcon.AddMenu("MenuItem5", OnClick);
notifyIcon.AddMenu("-");
notifyIcon.AddMenu("SubMenu", null!,
[
new ToolStripMenuItem("SubMenuItem1"),
new ToolStripMenuItem("SubMenuItem2"),
new ToolStripMenuItem("SubMenuItem3"),
new ToolStripMenuItem("SubSubMenu", null!,
[
new ToolStripMenuItem("SubSubMenuItem1"),
new ToolStripMenuItem("SubSubMenuItem2"),
new ToolStripMenuItem("SubSubMenuItem3")
])
]);
notifyIcon.AddMenu("-");
notifyIcon.AddMenu("Exit", (_, _) => Environment.Exit(0));
notifyIcon.BalloonTipShown += OnBalloonTipShown;

toDisableItem.Enabled = false;

void OnBalloonTipShown(object? sender, EventArgs e)
{
Debug.WriteLine("OnBalloonTipShown");
}

void OnClick(object? sender, EventArgs e)
{
notifyIcon.BalloonTipTitle = "Title";
notifyIcon.BalloonTipText = "This Balloon Tips";
notifyIcon.ShowBalloonTip(5);
}
}
}

file static class ResourceHelper
{
public static Stream GetStream(string name, Assembly assembly = null!)
{
Stream stream = (assembly ?? Assembly.GetExecutingAssembly()).GetManifestResourceStream(name)!;
return stream;
}
}
Binary file added NotifyIcon.Demo.Wice/Assets/Images/Lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions NotifyIcon.Demo.Wice/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using DirectN;
using Wice;
using Wice.Effects;

namespace WiceApp1;

public class MainWindow : Window, IDisposable
{
public MainWindow()
{
// we draw our own titlebar using Wice itself
WindowsFrameMode = WindowsFrameMode.None;

// resize to 66% of the screen
var monitor = GetMonitor().Bounds;
ResizeClient(monitor.Width * 2 / 3, monitor.Height * 2 / 3);

// the EnableBlurBehind call may be necessary when using the Windows' acrylic depending on Windows version
// otherwise the window will be (almost) black
Native.EnableBlurBehind();
RenderBrush = AcrylicBrush.CreateAcrylicBrush(
CompositionDevice,
_D3DCOLORVALUE.White,
0.2f,
useWindowsAcrylic: true
);
}

public void Dispose()
{
}
}
45 changes: 45 additions & 0 deletions NotifyIcon.Demo.Wice/NotifyIcon.Demo.Wice.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net472</TargetFramework>
<LangVersion>12.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
<Resource Include="Assets\Images\*.png" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Assets\Images\*.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="DirectN" Version="1.16.1" />
</ItemGroup>

<ItemGroup>
<Reference Include="Wice">
<SpecificVersion>False</SpecificVersion>
<HintPath>packages\Wice.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.Contracts">
<Version>10.0.26100.1</Version>
</PackageReference>
<PackageReference Include="System.Numerics.Vectors">
<Version>4.5.0</Version>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NotifyIcon\NotifyIcon.csproj" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions NotifyIcon.Demo.Wice/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace WiceApp1;

internal class Program
{
public static void Main()
{
using var dw = new App();
using var win = new MainWindow();
win.Center();
win.Show();
dw.Run();
}
}
59 changes: 59 additions & 0 deletions NotifyIcon.Demo.Wice/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="Wice.Samples.Gallery"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>

<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->

<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>


<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>


</assembly>
12 changes: 11 additions & 1 deletion NotifyIcon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotifyIcon.Demo.WinUI", "No
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotifyIcon.Demo.Avalonia", "NotifyIcon.Demo.Avalonia\NotifyIcon.Demo.Avalonia.csproj", "{D5C0A191-AF75-482C-AA26-CF13AE93248E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotifyIcon.Demo.Maui", "NotifyIcon.Demo.Maui\NotifyIcon.Demo.Maui.csproj", "{14AE6AB5-01D1-471A-B03D-DB574222DB77}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotifyIcon.Demo.Maui", "NotifyIcon.Demo.Maui\NotifyIcon.Demo.Maui.csproj", "{14AE6AB5-01D1-471A-B03D-DB574222DB77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotifyIcon.Demo.Wice", "NotifyIcon.Demo.Wice\NotifyIcon.Demo.Wice.csproj", "{8A65AC0D-B065-448A-A557-CE7D38301941}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -79,6 +81,14 @@ Global
{14AE6AB5-01D1-471A-B03D-DB574222DB77}.Release|x64.ActiveCfg = Release|Any CPU
{14AE6AB5-01D1-471A-B03D-DB574222DB77}.Release|x64.Build.0 = Release|Any CPU
{14AE6AB5-01D1-471A-B03D-DB574222DB77}.Release|x64.Deploy.0 = Release|Any CPU
{8A65AC0D-B065-448A-A557-CE7D38301941}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A65AC0D-B065-448A-A557-CE7D38301941}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A65AC0D-B065-448A-A557-CE7D38301941}.Debug|x64.ActiveCfg = Debug|Any CPU
{8A65AC0D-B065-448A-A557-CE7D38301941}.Debug|x64.Build.0 = Debug|Any CPU
{8A65AC0D-B065-448A-A557-CE7D38301941}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A65AC0D-B065-448A-A557-CE7D38301941}.Release|Any CPU.Build.0 = Release|Any CPU
{8A65AC0D-B065-448A-A557-CE7D38301941}.Release|x64.ActiveCfg = Release|Any CPU
{8A65AC0D-B065-448A-A557-CE7D38301941}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 9e53bb7

Please sign in to comment.