diff --git a/src/EasyWindowsApplication.slnx b/src/EasyWindowsApplication.slnx
index d759bce..109d2b9 100644
--- a/src/EasyWindowsApplication.slnx
+++ b/src/EasyWindowsApplication.slnx
@@ -4,5 +4,5 @@
-
+
diff --git a/src/EasyWindowsApplication/Core/Constants.cs b/src/EasyWindowsApplication/Core/Constants.cs
index a209bef..2eab93a 100644
--- a/src/EasyWindowsApplication/Core/Constants.cs
+++ b/src/EasyWindowsApplication/Core/Constants.cs
@@ -49,7 +49,9 @@ internal static class IMAGE
internal static class LR
{
- internal const uint DEFAULTCOLOR = 0x0040;
+ internal const uint DEFAULTCOLOR = 0x00000000;
+ internal const uint DEFAULTSIZE = 0x00000040;
+ internal const uint CREATEDIBSECTION = 0x00002000;
}
internal static class WM
@@ -69,6 +71,7 @@ internal static class WM
internal const uint QUIT = 0x0012;
internal const uint SETTEXT = 0x000C;
internal const uint GETTEXT = 0x000D;
+ internal const uint SETICON = 0x0080;
internal const uint GETTEXTLENGTH = 0x000E;
internal const uint COMMAND = 0x0111;
internal const uint SYSCOMMAND = 0x0112;
diff --git a/src/EasyWindowsApplication/Core/Windowing/Procedures.cs b/src/EasyWindowsApplication/Core/Windowing/Procedures.cs
index c63c7f0..63c4d1c 100644
--- a/src/EasyWindowsApplication/Core/Windowing/Procedures.cs
+++ b/src/EasyWindowsApplication/Core/Windowing/Procedures.cs
@@ -6,9 +6,31 @@ namespace EasyWindowsApplication.Core.Windowing;
internal static class Procedures
{
private const int SW_SHOWNORMAL = 1;
+ private const uint RT_GROUP_ICON = 14;
+ private const int RT_MAINICON = 32512;
+ private static int _iconResId = -1;
internal static void SetRouter(MasterRouter router) { }
+ private static int ResolveIconResourceId(nint hInstance)
+ {
+ if (_iconResId > 0)
+ return _iconResId;
+
+ int resolved = RT_MAINICON;
+ for (int id = 1; id <= RT_MAINICON; id++)
+ {
+ if (Win32.FindResourceW(hInstance, (nint)id, (nint)RT_GROUP_ICON) != 0)
+ {
+ resolved = id;
+ break;
+ }
+ }
+
+ _iconResId = resolved;
+ return resolved;
+ }
+
internal static unsafe nint CreateMainWindow(
MasterRouter router,
string title,
@@ -16,16 +38,17 @@ internal static unsafe nint CreateMainWindow(
float height)
{
nint hInstance = Win32.GetModuleHandleW(0);
+ int iconResId = ResolveIconResourceId(hInstance);
nint hIconLarge = Win32.LoadImageW(
- hInstance, (nint)1, IMAGE.ICON,
- Win32.GetSystemMetrics(11), Win32.GetSystemMetrics(12),
- LR.DEFAULTCOLOR);
+ hInstance, (nint)iconResId, IMAGE.ICON,
+ 0, 0,
+ LR.DEFAULTSIZE | LR.CREATEDIBSECTION);
nint hIconSmall = Win32.LoadImageW(
- hInstance, (nint)1, IMAGE.ICON,
- Win32.GetSystemMetrics(49), Win32.GetSystemMetrics(50),
- LR.DEFAULTCOLOR);
+ hInstance, (nint)iconResId, IMAGE.ICON,
+ 0, 0,
+ LR.DEFAULTSIZE | LR.CREATEDIBSECTION);
string className = $"EasyWinApp_{Guid.NewGuid():N}";
nint classNamePtr = Marshal.StringToHGlobalUni(className);
@@ -68,6 +91,9 @@ internal static unsafe nint CreateMainWindow(
if (hwnd == 0)
throw new InvalidOperationException($"CreateWindowExW failed: {Marshal.GetLastWin32Error()}");
+ Win32.SendMessageW(hwnd, WM.SETICON, 1, hIconLarge);
+ Win32.SendMessageW(hwnd, WM.SETICON, 0, hIconSmall);
+
HandleRegistry.RegisterRouter(hwnd, router);
router.RegisterMainHwnd(hwnd);
diff --git a/src/EasyWindowsApplication/Core/Windowing/Win32.cs b/src/EasyWindowsApplication/Core/Windowing/Win32.cs
index 07073d3..142dc89 100644
--- a/src/EasyWindowsApplication/Core/Windowing/Win32.cs
+++ b/src/EasyWindowsApplication/Core/Windowing/Win32.cs
@@ -30,6 +30,9 @@ internal static partial nint CreateWindowExW(
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool DestroyWindow(nint hWnd);
+ [LibraryImport("kernel32.dll", SetLastError = true)]
+ internal static partial nint FindResourceW(nint hModule, nint lpName, nint lpType);
+
[LibraryImport("user32.dll", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
internal static partial nint LoadImageW(nint hInst, nint name, uint type, int cx, int cy, uint fuLoad);
@@ -44,6 +47,9 @@ internal static partial nint CreateWindowExW(
[LibraryImport("user32.dll")]
internal static partial int GetSystemMetrics(int nIndex);
+ [LibraryImport("user32.dll")]
+ internal static partial nint SendMessageW(nint hWnd, uint Msg, nint wParam, nint lParam);
+
[LibraryImport("kernel32.dll", StringMarshalling = StringMarshalling.Utf16)]
internal static partial nint GetModuleHandleW(nint lpModuleName);
}
diff --git a/src/ProjectTemplates/EasyWinApp/EasyWinApp.csproj b/src/ProjectTemplates/EasyWinApp/EasyWinApp.csproj
index ce0c77d..c5aff25 100644
--- a/src/ProjectTemplates/EasyWinApp/EasyWinApp.csproj
+++ b/src/ProjectTemplates/EasyWinApp/EasyWinApp.csproj
@@ -8,6 +8,7 @@
true
True
EasyWinApp.ico
+ app.manifest
diff --git a/src/ProjectTemplates/EasyWinApp/app.manifest b/src/ProjectTemplates/EasyWinApp/app.manifest
new file mode 100644
index 0000000..83a5b37
--- /dev/null
+++ b/src/ProjectTemplates/EasyWinApp/app.manifest
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+ PerMonitorV2, PerMonitor
+ true
+
+
+
diff --git a/src/ProjectTemplates/SimpleEasyWinApp/SimpleEasyWinApp.csproj b/src/ProjectTemplates/SimpleEasyWinApp/SimpleEasyWinApp.csproj
index b2a4462..7ca7824 100644
--- a/src/ProjectTemplates/SimpleEasyWinApp/SimpleEasyWinApp.csproj
+++ b/src/ProjectTemplates/SimpleEasyWinApp/SimpleEasyWinApp.csproj
@@ -8,6 +8,7 @@
true
True
SimpleEasyWinApp.ico
+ app.manifest
diff --git a/src/ProjectTemplates/SimpleEasyWinApp/app.manifest b/src/ProjectTemplates/SimpleEasyWinApp/app.manifest
new file mode 100644
index 0000000..876d6fe
--- /dev/null
+++ b/src/ProjectTemplates/SimpleEasyWinApp/app.manifest
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+ PerMonitorV2, PerMonitor
+ true
+
+
+
diff --git a/src/Sample/Program.cs b/src/Sample/Program.cs
index 4b59efd..98a74e8 100644
--- a/src/Sample/Program.cs
+++ b/src/Sample/Program.cs
@@ -1,36 +1,34 @@
using EasyWindowsApplication;
-using EasyWindowsApplication.Win32ControlsModule.Frontend;
using EasyWindowsApplication.Share;
+using EasyWindowsApplication.Win32ControlsModule.Frontend;
+
+WindowsApplication.Layout(ly => ly.Window()).Initialize();
-int counter = 0;
+//int counter = 0;
-WindowsApplication
- .Resources(rd => rd.Setting(st => st.UseWinApi()))
- .Layout(ly => ly
- .Window(iw => iw
- .Name("MainWindow")
- .Title("Easy Win App")
- .Dimensions(420, 280)
- .Position(WindowPositionOnScreen.Center)
- .Content(c => c
- .Children(ch =>
- {
- ch.View(btn => btn
- .Name("BtnIncrement")
- .Text("Click me")
- );
- ch.View(lb => lb.Name("LbShowIncrement").Text("0 Increment"));
- })
- )
- )
- .AlternativeWindow(aw => aw.Name("MsgWindow"))
- )
- .Behavior(bh =>
- {
- bh.BtnIncrement.OnClick(() =>
- {
- counter++;
- bh.LbShowIncrement.Text = $"{counter} Increment";
- });
- })
- .Initialize();
+//WindowsApplication
+// .Resources(rd => rd.Setting(st => st.UseWinApi()))
+// .Layout(ly => ly
+// .Window(iw => iw
+// .Name("MainWindow")
+// .Title("Easy Win App")
+// .Dimensions(420, 280)
+// .Position(WindowPositionOnScreen.Center)
+// .Content(c => c
+// .Children(ch => ch
+// .View(btn => btn
+// .Name("BtnIncrement")
+// .Text("Click me")
+// )
+// )
+// )
+// )
+// )
+// .Behavior(bh => bh
+// .BtnIncrement.OnClick(() =>
+// {
+// counter++;
+// bh.BtnIncrement.Text = $"Click: {counter}";
+// })
+// )
+// .Initialize();
diff --git a/src/Sample/Sample.csproj b/src/Sample/Sample.csproj
index e7e9bc4..45390cc 100644
--- a/src/Sample/Sample.csproj
+++ b/src/Sample/Sample.csproj
@@ -8,30 +8,32 @@
true
True
Sample.ico
+ app.manifest
-
+
-
-
+
+
+
+
+
-
+
<_IcoGenDir>$(IntermediateOutputPath)IcoGen\
<_IcoGenProj>$(_IcoGenDir)IcoGen.csproj
<_IcoGenCs>$(_IcoGenDir)Program.cs
- <_EasyWAProj>$(MSBuildProjectDirectory)\..\EasyWindowsApplication\EasyWindowsApplication.csproj
+
<_SvgAbs>$(MSBuildProjectDirectory)\Resources\AppIcon\appicon.svg
<_IcoAbs>$(MSBuildProjectDirectory)\$(IntermediateOutputPath)$(ApplicationIcon)
@@ -40,7 +42,7 @@
-
+
<_IcoProjLine Include="<Project Sdk="Microsoft.NET.Sdk">" />
@@ -52,7 +54,7 @@
<_IcoProjLine Include=" </PropertyGroup>" />
<_IcoProjLine Include=" <ItemGroup>" />
<_IcoProjLine Include=" <PackageReference Include="Svg.Skia" Version="%2A" />" />
- <_IcoProjLine Include=" <ProjectReference Include="$(_EasyWAProj)" />" />
+ <_IcoProjLine Include=" <PackageReference Include="RandAMediaLabGroup.EasyWindowsApplication" Version="%2A-%2A" />" />
<_IcoProjLine Include=" </ItemGroup>" />
<_IcoProjLine Include="</Project>" />
diff --git a/src/Sample/app.manifest b/src/Sample/app.manifest
new file mode 100644
index 0000000..c12fa83
--- /dev/null
+++ b/src/Sample/app.manifest
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+ PerMonitorV2, PerMonitor
+ true
+
+
+