Skip to content

Commit 968dfc1

Browse files
Improved tray icons for 125% and 150% scales
1 parent f6f98f7 commit 968dfc1

File tree

11 files changed

+58
-59
lines changed

11 files changed

+58
-59
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ bin/Debug
44
*.pdb
55

66
/.vs
7+
*.vshost.exe*
8+
.suo
9+
*.suo

App.config

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0"?>
22
<configuration>
3-
3+
44
<configSections>
5-
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
6-
<section name="CopyCopyDict.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
5+
<sectionGroup name="userSettings">
6+
<section name="CopyCopyDict.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
77
</sectionGroup>
88
</configSections>
9-
9+
1010
<startup>
1111
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
1212
<supportedRuntime version="v2.0.50727" />
@@ -28,5 +28,5 @@
2828
</setting>
2929
</CopyCopyDict.Properties.Settings>
3030
</userSettings>
31-
31+
3232
</configuration>

CopyCopyDict.csproj

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,8 @@
1313
<FileAlignment>512</FileAlignment>
1414
<TargetFrameworkProfile>
1515
</TargetFrameworkProfile>
16-
<PublishUrl>publish\</PublishUrl>
17-
<Install>true</Install>
18-
<InstallFrom>Disk</InstallFrom>
19-
<UpdateEnabled>false</UpdateEnabled>
20-
<UpdateMode>Foreground</UpdateMode>
21-
<UpdateInterval>7</UpdateInterval>
22-
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
23-
<UpdatePeriodically>false</UpdatePeriodically>
24-
<UpdateRequired>false</UpdateRequired>
25-
<MapFileExtensions>true</MapFileExtensions>
26-
<ApplicationRevision>0</ApplicationRevision>
27-
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
28-
<IsWebBootstrapper>false</IsWebBootstrapper>
29-
<UseApplicationTrust>false</UseApplicationTrust>
30-
<BootstrapperEnabled>true</BootstrapperEnabled>
31-
</PropertyGroup>
32-
<PropertyGroup>
16+
<LangVersion>5</LangVersion>
17+
<ErrorReport>prompt</ErrorReport>
3318
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
3419
</PropertyGroup>
3520
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
@@ -38,26 +23,17 @@
3823
<DefineConstants>DEBUG;TRACE</DefineConstants>
3924
<DebugType>full</DebugType>
4025
<PlatformTarget>AnyCPU</PlatformTarget>
41-
<LangVersion>7.3</LangVersion>
42-
<ErrorReport>prompt</ErrorReport>
43-
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
44-
<Prefer32Bit>true</Prefer32Bit>
4526
</PropertyGroup>
4627
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
4728
<OutputPath>bin\Release\</OutputPath>
4829
<DefineConstants>TRACE</DefineConstants>
4930
<Optimize>true</Optimize>
5031
<DebugType>pdbonly</DebugType>
5132
<PlatformTarget>AnyCPU</PlatformTarget>
52-
<LangVersion>7.3</LangVersion>
53-
<ErrorReport>prompt</ErrorReport>
54-
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
55-
<Prefer32Bit>true</Prefer32Bit>
5633
</PropertyGroup>
34+
<PropertyGroup />
5735
<ItemGroup>
5836
<Reference Include="System" />
59-
<Reference Include="System.Data" />
60-
<Reference Include="System.Deployment" />
6137
<Reference Include="System.Drawing" />
6238
<Reference Include="System.Windows.Forms" />
6339
<Reference Include="System.Xml" />
@@ -96,19 +72,5 @@
9672
<ItemGroup>
9773
<Content Include="Resources\Icon.ico" />
9874
</ItemGroup>
99-
<ItemGroup>
100-
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
101-
<Visible>False</Visible>
102-
<ProductName>.NET Framework 3.5 SP1</ProductName>
103-
<Install>true</Install>
104-
</BootstrapperPackage>
105-
</ItemGroup>
10675
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
107-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
108-
Other similar extension points exist, see Microsoft.Common.targets.
109-
<Target Name="BeforeBuild">
110-
</Target>
111-
<Target Name="AfterBuild">
112-
</Target>
113-
-->
11476
</Project>

HotKeyWindow.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ protected override void WndProc(ref Message m)
3636
{
3737
if (m.Msg == WM_HOTKEY &&
3838
_isRegistered &&
39-
m.WParam.ToInt32() == HotKeyId)
39+
m.WParam.ToInt32() == HotKeyId &&
40+
Pressed != null)
4041
{
41-
Pressed?.Invoke();
42+
Pressed();
4243
}
4344

4445
base.WndProc(ref m);

KeyInterceptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ private void ListenerWorker()
124124
while (!_isDisposed)
125125
{
126126
_listenerEvent.WaitOne();
127-
if (!_isDisposed)
127+
if (!_isDisposed && Pressed != null)
128128
{
129-
Pressed?.Invoke();
129+
Pressed();
130130
}
131131
}
132132
}

Program.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
// License: MIT
55
// </copyright>
66

7+
using System;
78
using System.Diagnostics;
9+
using System.Drawing;
10+
using System.Runtime.InteropServices;
811
using System.Threading;
912
using System.Windows.Forms;
1013

@@ -14,7 +17,8 @@ public class Program
1417
{
1518
public static void Main()
1619
{
17-
using (var mutex = new Mutex(true, "CopyCopyDictRunning", out var mutexCreated))
20+
bool mutexCreated;
21+
using (var mutex = new Mutex(true, "CopyCopyDictRunning", out mutexCreated))
1822
{
1923
if (!mutexCreated)
2024
{
@@ -32,9 +36,27 @@ public static void Main()
3236
menu.Items.Add(openItem);
3337
menu.Items.Add("-");
3438
menu.Items.Add("Exit", null, (e, a) => Application.Exit());
39+
40+
var icon = Resources.Resources.Icon;
41+
using (var g = Graphics.FromHwnd(IntPtr.Zero))
42+
{
43+
var desktop = g.GetHdc();
44+
var logicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);
45+
var physicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);
46+
var dpiY = GetDeviceCaps(desktop, (int)DeviceCap.LOGPIXELSY);
47+
var scale = Math.Max(
48+
(double)physicalScreenHeight / logicalScreenHeight,
49+
(double)dpiY / 96);
50+
var iconSize = (int)Math.Round(16 * scale);
51+
if (Array.IndexOf(new[] { 16, 20, 24 }, iconSize) >= 0)
52+
{
53+
icon = new Icon(icon, iconSize, iconSize);
54+
}
55+
}
56+
3557
var trayIcon = new NotifyIcon
3658
{
37-
Icon = Resources.Resources.Icon,
59+
Icon = icon,
3860
ContextMenuStrip = menu,
3961
Visible = true
4062
};
@@ -77,5 +99,14 @@ private static void BrowseClipboardText()
7799
catch { }
78100
Browse(text);
79101
}
102+
103+
[DllImport("gdi32.dll")]
104+
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
105+
public enum DeviceCap
106+
{
107+
VERTRES = 10,
108+
DESKTOPVERTRES = 117,
109+
LOGPIXELSY = 90
110+
}
80111
}
81112
}

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.1.0.0")]
35-
[assembly: AssemblyFileVersion("1.1.0.0")]
34+
[assembly: AssemblyVersion("1.1.1.0")]
35+
[assembly: AssemblyFileVersion("1.1.1.0")]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Background app that opens the definition or translation of a selected word with
33

44
![](./Resources/record.gif)
55

6+
The tool is less than 30 KB in size and works on all versions of Windows, from Windows XP to Windows 11.
7+
68
[Releases](../../releases) page
79

810
In the [CopyCopyDict.exe.config](../../blob/master/bin/Release/CopyCopyDict.exe.config) file, you can add one or more services by specifying languages and query format in the url pattern. For example:

Resources/Icon.ico

2.92 KB
Binary file not shown.

bin/Release/CopyCopyDict.exe

10 KB
Binary file not shown.

0 commit comments

Comments
 (0)