Skip to content

Commit

Permalink
添加一个 WinForm 窗口
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Oct 11, 2023
1 parent e3b1e43 commit 07fd610
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 35 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build-and-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ on:
paths:
- 'CoreAppUWP/**'
workflow_dispatch:

env:
DOTNET_VERSION: '6.0.x' # The .NET SDK version to use
DOTNET_VERSION: '8.0.x' # The .NET SDK version to use

jobs:
build-and-test:
Expand All @@ -26,12 +26,13 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
# Install the .NET Core workload
- name: Install .NET Core

# Install the .NET Core App workload
- name: Install .NET Core App
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{env.DOTNET_VERSION}}
dotnet-quality: 'preview'

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
Expand Down
30 changes: 24 additions & 6 deletions CoreAppUWP/App.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
using Windows.UI;
Expand Down Expand Up @@ -59,12 +60,29 @@ private void OnApplicationViewActivated(CoreApplicationView sender, IActivatedEv

Tiles.UpdateTile();

StringBuilder builder = new StringBuilder()
.AppendLine(RuntimeInformation.FrameworkDescription)
.AppendLine(RuntimeInformation.OSDescription)
.Append($"ProcessArchitecture: {RuntimeInformation.ProcessArchitecture}");
MessageDialog dialog = new(builder.ToString(), "Hello World!");
_ = dialog.ShowAsync();
Application.EnableVisualStyles();

Form form = new() { Text = "Form" };

Button button = new()
{
Text = "Show Dialog",
Parent = form,
Height = 48,
Width = 200
};
button.Click += (sender, args) =>
{
StringBuilder builder = new StringBuilder()
.AppendLine(RuntimeInformation.FrameworkDescription)
.AppendLine(RuntimeInformation.OSDescription)
.Append($"ProcessArchitecture: {RuntimeInformation.ProcessArchitecture}");
MessageDialog dialog = new(builder.ToString(), "Hello World!");
_ = dialog.ShowAsync();
};

form.Show();
form.Activate();
}

private static void ExtendViewIntoTitleBar(bool extendViewIntoTitleBar)
Expand Down
24 changes: 14 additions & 10 deletions CoreAppUWP/CoreAppUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<TargetFramework>net6.0-windows10.0.22621.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<UseWinUI>True</UseWinUI>
<UseWindowsForms>True</UseWindowsForms>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -31,24 +32,24 @@
</PropertyGroup>

<ItemGroup>
<Compile Remove="AppPackages\**" />
<EmbeddedResource Remove="AppPackages\**" />
<None Remove="AppPackages\**" />
<Page Remove="AppPackages\**" />
<Compile Remove="Forms\**" />
<EmbeddedResource Remove="Forms\**" />
<None Remove="Forms\**" />
<Page Remove="Forms\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.2" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230313.1" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.3" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231008000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<ItemGroup>
<PRIResource Remove="AppPackages\**" />
</ItemGroup>

<ItemGroup>
<Content Include="favicon.ico" />
</ItemGroup>
Expand All @@ -70,4 +71,7 @@
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
<ItemGroup>
<PRIResource Remove="Forms\**" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions CoreAppUWP/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ICoreWindowInterop

GetParent
SetParent
5 changes: 2 additions & 3 deletions CoreAppUWP/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap uap5 rescap">
IgnorableNamespaces="uap uap5 mp">

<Identity
Name="wherewhere.CoreAppUWP"
Expand All @@ -17,7 +16,7 @@

<Properties>
<DisplayName>CoreAppUWP</DisplayName>
<PublisherDisplayName>qq251</PublisherDisplayName>
<PublisherDisplayName>wherewhere</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>

Expand Down
4 changes: 2 additions & 2 deletions CoreAppUWP/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ private static async void StartCoreApplication()
PackageManager manager = new();
string basePath = AppDomain.CurrentDomain.BaseDirectory;
XmlDocument manifest = await XmlDocument.LoadFromFileAsync(await StorageFile.GetFileFromPathAsync(Path.Combine(basePath, "AppxManifest.xml")));
IXmlNode identity = manifest.GetElementsByTagName("Identity").FirstOrDefault();
IXmlNode identity = manifest.GetElementsByTagName("Identity")[0];
string name = identity.Attributes.FirstOrDefault((x) => x.NodeName == "Name")?.InnerText;
IXmlNode application = manifest.GetElementsByTagName("Application").FirstOrDefault();
IXmlNode application = manifest.GetElementsByTagName("Application")[0];
string id = application.Attributes.FirstOrDefault((x) => x.NodeName == "Id")?.InnerText;
IEnumerable<Package> packages = manager.FindPackagesForUser("").Where((x) => x.Id.FamilyName.StartsWith(name));
if (packages.Any())
Expand Down
2 changes: 1 addition & 1 deletion CoreAppUWP/Properties/PublishProfiles/win10-arm64.pubxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<!-- See https://github.com/microsoft/CsWinRT/issues/373 -->
<PublishTrimmed>$(SelfContained)</PublishTrimmed>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion CoreAppUWP/Properties/PublishProfiles/win10-x64.pubxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<!-- See https://github.com/microsoft/CsWinRT/issues/373 -->
<PublishTrimmed>$(SelfContained)</PublishTrimmed>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion CoreAppUWP/Properties/PublishProfiles/win10-x86.pubxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<!-- See https://github.com/microsoft/CsWinRT/issues/373 -->
<PublishTrimmed>$(SelfContained)</PublishTrimmed>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
</Project>
8 changes: 2 additions & 6 deletions CoreAppUWP/Tiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ namespace CoreAppUWP
{
public static class Tiles
{
public static void UpdateTile()
{
UpdateTitle(CreateTile());
}
public static void UpdateTile() => CreateTile().UpdateTitle();

private static void UpdateTitle(TileContent tileContent)
private static void UpdateTitle(this TileContent tileContent)
{
TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
tileUpdater.Clear();
Expand Down Expand Up @@ -138,6 +135,5 @@ private static TileContent CreateTile()
}
};
}

}
}

0 comments on commit 07fd610

Please sign in to comment.