Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EasyWindowsApplication.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<Project Path="ProjectTemplates/EasyWinApp/EasyWinApp.csproj" />
<Project Path="ProjectTemplates/ProjectTemplates.csproj" />
<Project Path="ProjectTemplates/SimpleEasyWinApp/SimpleEasyWinApp.csproj" />
<Project Path="Sample/Sample.csproj" Id="0cbd3060-e5d2-464f-9d8a-b7a8795bce6c" />
<Project Path="Sample/Sample.csproj" Id="aef3e598-3bba-4bbd-97e2-e15f53e62275" />
</Solution>
5 changes: 4 additions & 1 deletion src/EasyWindowsApplication/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
38 changes: 32 additions & 6 deletions src/EasyWindowsApplication/Core/Windowing/Procedures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,49 @@ 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,
float width,
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);
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions src/EasyWindowsApplication/Core/Windowing/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
1 change: 1 addition & 0 deletions src/ProjectTemplates/EasyWinApp/EasyWinApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PublishAot>true</PublishAot>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<ApplicationIcon>EasyWinApp.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions src/ProjectTemplates/EasyWinApp/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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="EasyWinApp" />
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PublishAot>true</PublishAot>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<ApplicationIcon>SimpleEasyWinApp.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions src/ProjectTemplates/SimpleEasyWinApp/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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="SimpleEasyWinApp" />
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
</assembly>
62 changes: 30 additions & 32 deletions src/Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -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<IButton>(btn => btn
.Name("BtnIncrement")
.Text("Click me")
);
ch.View<ILabel>(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<IButton>(btn => btn
// .Name("BtnIncrement")
// .Text("Click me")
// )
// )
// )
// )
// )
// .Behavior(bh => bh
// .BtnIncrement.OnClick(() =>
// {
// counter++;
// bh.BtnIncrement.Text = $"Click: {counter}";
// })
// )
// .Initialize();
24 changes: 13 additions & 11 deletions src/Sample/Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,32 @@
<PublishAot>true</PublishAot>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<ApplicationIcon>Sample.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EasyWindowsApplication\EasyWindowsApplication.csproj" />
<PackageReference Include="RandAMediaLabGroup.EasyWindowsApplication" Version="*-*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EasyWindowsApplication.Generators\EasyWindowsApplication.Generators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<!--<ItemGroup>
<PackageReference Include="RandAMediaLabGroup.EasyWindowsApplication.Generators" Version="*-*" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\Raw\appsettings.json" />
</ItemGroup>-->

<ItemGroup>
<ProjectReference Include="..\EasyWindowsApplication.Generators\EasyWindowsApplication.Generators.csproj" />
<ProjectReference Include="..\EasyWindowsApplication\EasyWindowsApplication.csproj" />
</ItemGroup>

<Target Name="GenerateAppIcon" BeforeTargets="BeforeBuild"
Inputs="Resources\AppIcon\appicon.svg"
Outputs="$(IntermediateOutputPath)$(ApplicationIcon)">
<Target Name="GenerateAppIcon" BeforeTargets="BeforeBuild" Inputs="Resources\AppIcon\appicon.svg" Outputs="$(IntermediateOutputPath)$(ApplicationIcon)">
<PropertyGroup>
<_IcoGenDir>$(IntermediateOutputPath)IcoGen\</_IcoGenDir>
<_IcoGenProj>$(_IcoGenDir)IcoGen.csproj</_IcoGenProj>
<_IcoGenCs>$(_IcoGenDir)Program.cs</_IcoGenCs>
<_EasyWAProj>$(MSBuildProjectDirectory)\..\EasyWindowsApplication\EasyWindowsApplication.csproj</_EasyWAProj>

<_SvgAbs>$(MSBuildProjectDirectory)\Resources\AppIcon\appicon.svg</_SvgAbs>
<_IcoAbs>$(MSBuildProjectDirectory)\$(IntermediateOutputPath)$(ApplicationIcon)</_IcoAbs>
</PropertyGroup>
Expand All @@ -40,7 +42,7 @@
<MakeDir Directories="$(_IcoGenDir)" />

<WriteLinesToFile File="$(_IcoGenCs)" Lines="using EasyWindowsApplication.Core%3B" Overwrite="true" />
<WriteLinesToFile File="$(_IcoGenCs)" Lines='IconGenerator.GenerateIco(@"$(_SvgAbs)", @"$(_IcoAbs)", new[] { 16, 32, 48, 256 })%3B' />
<WriteLinesToFile File="$(_IcoGenCs)" Lines="IconGenerator.GenerateIco(@&quot;$(_SvgAbs)&quot;, @&quot;$(_IcoAbs)&quot;, new[] { 16, 32, 48, 256 })%3B" />

<ItemGroup>
<_IcoProjLine Include="&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;" />
Expand All @@ -52,7 +54,7 @@
<_IcoProjLine Include=" &lt;/PropertyGroup&gt;" />
<_IcoProjLine Include=" &lt;ItemGroup&gt;" />
<_IcoProjLine Include=" &lt;PackageReference Include=&quot;Svg.Skia&quot; Version=&quot;%2A&quot; /&gt;" />
<_IcoProjLine Include=" &lt;ProjectReference Include=&quot;$(_EasyWAProj)&quot; /&gt;" />
<_IcoProjLine Include=" &lt;PackageReference Include=&quot;RandAMediaLabGroup.EasyWindowsApplication&quot; Version=&quot;%2A-%2A&quot; /&gt;" />
<_IcoProjLine Include=" &lt;/ItemGroup&gt;" />
<_IcoProjLine Include="&lt;/Project&gt;" />
</ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions src/Sample/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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="Sample" />
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
</assembly>
Loading