/
Program.cs
59 lines (50 loc) · 2.59 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using System.Windows.Forms;
using Microsoft.Windows.ApplicationModel.Resources;
using Microsoft.Windows.ApplicationModel;
namespace winforms_unpackaged_app
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Initialize dynamic dependencies so we can consume the Windows App SDK APIs from this unpackaged app.
// Take a dependency on Windows App SDK v1.0.0-preview1.
int hr = MddBootstrap.Initialize(0x00010000, "preview1");
if (hr < 0)
{
MessageBox.Show("Fail to initialize Dynamic Dependencies with error 0x" + hr.ToString("X"), "Error!");
return;
}
var resourceManager = new ResourceManager("winforms_unpackaged_app.pri");
// Fall back to other resource loaders if the resource is not found in MRT, in this case .net.
// This enables carrying forward existing assets without the need to convert them.
resourceManager.ResourceNotFound += (sender, args) =>
{
var candidate = new ResourceCandidate(
ResourceCandidateKind.String,
LegacyResources.ResourceManager.GetString(args.Name, LegacyResources.Culture));
args.SetResolvedCandidate(candidate);
};
var resourceLoader = new ResourceLoader();
// Create a custom resource context. Set the language to German.
var overrideResourceContext = resourceManager.CreateResourceContext();
overrideResourceContext.QualifierValues["Language"] = "de-DE";
// The resource manager and the resource loader do disk I/O and should be centrally cached.
// Since both end up loading the same file, ideally an app should only use one.
// The resource manager is a superset of the resource loader in terms of functionality.
Application.Run(new AppForm(resourceManager, resourceLoader, overrideResourceContext));
// Uninitialize dynamic dependencies.
MddBootstrap.Shutdown();
}
}
}