Skip to content

Commit 236235e

Browse files
Started working on Win32 Host
1 parent 0c94d16 commit 236235e

File tree

133 files changed

+319
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+319
-15
lines changed

VBAudioRouter.Host/Program.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using Microsoft.Toolkit.Forms.UI.XamlHost;
2+
using System;
3+
using System.Drawing;
4+
using System.Windows.Forms;
5+
using Windows.UI.Xaml;
6+
using Application = System.Windows.Forms.Application;
7+
8+
namespace VBAudioRouter.Host
9+
{
10+
static class Program
11+
{
12+
[STAThread]
13+
static void Main()
14+
{
15+
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
16+
Application.EnableVisualStyles();
17+
Application.SetCompatibleTextRenderingDefault(false);
18+
19+
XamlWindow<WelcomePage> window = new();
20+
window.Show();
21+
using (new App())
22+
{
23+
window.InitializeXamlContent();
24+
Application.Run(window);
25+
}
26+
}
27+
}
28+
29+
class XamlWindow<T> : Form where T : UIElement
30+
{
31+
public WindowsXamlHost XamlHost { get; private set; }
32+
public void InitializeXamlContent()
33+
{
34+
this.SuspendLayout();
35+
36+
XamlHost = new();
37+
XamlHost.Dock = DockStyle.Fill;
38+
XamlHost.Child = Activator.CreateInstance<T>();
39+
this.Controls.Add(XamlHost);
40+
41+
this.ResumeLayout(false);
42+
this.PerformLayout();
43+
44+
SplashScreenVisible = false;
45+
this.Refresh();
46+
}
47+
48+
#region SplashScreen
49+
public bool SplashScreenVisible { get; private set; } = true;
50+
public void ShowSplashScreen()
51+
{
52+
SplashScreenVisible = true;
53+
this.Refresh();
54+
}
55+
56+
protected override void OnPaint(PaintEventArgs e)
57+
{
58+
if (SplashScreenVisible)
59+
using (Graphics g = e.Graphics)
60+
{
61+
g.Clear(Color.Red);
62+
}
63+
else
64+
base.OnPaint(e);
65+
}
66+
#endregion
67+
}
68+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
<AssetTargetFallback>uap10.0.19041</AssetTargetFallback>
8+
<LangVersion>9</LangVersion>
9+
<Platforms>AnyCPU;x64</Platforms>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.Toolkit.Forms.UI.XamlHost" Version="6.1.2" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\VBAudioRouter.UWP\VBAudioRouter.UWP.vbproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<Package
4+
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
5+
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
6+
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
7+
IgnorableNamespaces="uap rescap">
8+
9+
<Identity
10+
Name="373dc081-e2cd-4c79-84f4-b99c81d121ac"
11+
Publisher="CN=lukas"
12+
Version="1.0.0.0" />
13+
14+
<Properties>
15+
<DisplayName>VBAudioRouter.Package</DisplayName>
16+
<PublisherDisplayName>lukas</PublisherDisplayName>
17+
<Logo>Images\StoreLogo.png</Logo>
18+
</Properties>
19+
20+
<Dependencies>
21+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
22+
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
23+
</Dependencies>
24+
25+
<Resources>
26+
<Resource Language="x-generate"/>
27+
</Resources>
28+
29+
<Applications>
30+
<Application Id="App"
31+
Executable="$targetnametoken$.exe"
32+
EntryPoint="$targetentrypoint$">
33+
<uap:VisualElements
34+
DisplayName="VBAudioRouter.Package"
35+
Description="VBAudioRouter.Package"
36+
BackgroundColor="transparent"
37+
Square150x150Logo="Images\Square150x150Logo.png"
38+
Square44x44Logo="Images\Square44x44Logo.png">
39+
<uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" />
40+
<uap:SplashScreen Image="Images\SplashScreen.png" />
41+
</uap:VisualElements>
42+
</Application>
43+
</Applications>
44+
45+
<Capabilities>
46+
<Capability Name="internetClient" />
47+
<rescap:Capability Name="runFullTrust" />
48+
</Capabilities>
49+
</Package>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
4+
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0'">
5+
<VisualStudioVersion>15.0</VisualStudioVersion>
6+
</PropertyGroup>
7+
8+
<ItemGroup Label="ProjectConfigurations">
9+
<ProjectConfiguration Include="Debug|x86">
10+
<Configuration>Debug</Configuration>
11+
<Platform>x86</Platform>
12+
</ProjectConfiguration>
13+
<ProjectConfiguration Include="Release|x86">
14+
<Configuration>Release</Configuration>
15+
<Platform>x86</Platform>
16+
</ProjectConfiguration>
17+
<ProjectConfiguration Include="Debug|x64">
18+
<Configuration>Debug</Configuration>
19+
<Platform>x64</Platform>
20+
</ProjectConfiguration>
21+
<ProjectConfiguration Include="Release|x64">
22+
<Configuration>Release</Configuration>
23+
<Platform>x64</Platform>
24+
</ProjectConfiguration>
25+
<ProjectConfiguration Include="Debug|ARM">
26+
<Configuration>Debug</Configuration>
27+
<Platform>ARM</Platform>
28+
</ProjectConfiguration>
29+
<ProjectConfiguration Include="Release|ARM">
30+
<Configuration>Release</Configuration>
31+
<Platform>ARM</Platform>
32+
</ProjectConfiguration>
33+
<ProjectConfiguration Include="Debug|ARM64">
34+
<Configuration>Debug</Configuration>
35+
<Platform>ARM64</Platform>
36+
</ProjectConfiguration>
37+
<ProjectConfiguration Include="Release|ARM64">
38+
<Configuration>Release</Configuration>
39+
<Platform>ARM64</Platform>
40+
</ProjectConfiguration>
41+
<ProjectConfiguration Include="Debug|AnyCPU">
42+
<Configuration>Debug</Configuration>
43+
<Platform>AnyCPU</Platform>
44+
</ProjectConfiguration>
45+
<ProjectConfiguration Include="Release|AnyCPU">
46+
<Configuration>Release</Configuration>
47+
<Platform>AnyCPU</Platform>
48+
</ProjectConfiguration>
49+
</ItemGroup>
50+
51+
<PropertyGroup>
52+
<WapProjPath Condition="'$(WapProjPath)'==''">$(MSBuildExtensionsPath)\Microsoft\DesktopBridge\</WapProjPath>
53+
</PropertyGroup>
54+
55+
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
56+
57+
<PropertyGroup>
58+
<ProjectGuid>b5c5d13e-675b-4c34-bfbb-1125484cc5fd</ProjectGuid>
59+
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
60+
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
61+
<DefaultLanguage>en-US</DefaultLanguage>
62+
63+
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
64+
</PropertyGroup>
65+
66+
<ItemGroup>
67+
<AppxManifest Include="Package.appxmanifest">
68+
<SubType>Designer</SubType>
69+
</AppxManifest>
70+
71+
</ItemGroup>
72+
73+
<ItemGroup>
74+
<Content Include="Images\SplashScreen.scale-200.png" />
75+
<Content Include="Images\LockScreenLogo.scale-200.png" />
76+
<Content Include="Images\Square150x150Logo.scale-200.png" />
77+
<Content Include="Images\Square44x44Logo.scale-200.png" />
78+
<Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
79+
<Content Include="Images\StoreLogo.png" />
80+
<Content Include="Images\Wide310x150Logo.scale-200.png" />
81+
</ItemGroup>
82+
83+
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
84+
85+
<ItemGroup>
86+
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.19041.8" PrivateAssets="all" />
87+
</ItemGroup>
88+
89+
</Project>

VBAudioRouter/App.xaml renamed to VBAudioRouter.UWP/App.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<Application
1+
<xamlhost:XamlApplication
2+
xmlns:xamlhost="using:Microsoft.Toolkit.Win32.UI.XamlHost"
23
x:Class="VBAudioRouter.App"
34
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
45
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -31,4 +32,4 @@
3132
</controls:XamlControlsResources.MergedDictionaries>
3233
</controls:XamlControlsResources>
3334
</Application.Resources>
34-
</Application>
35+
</xamlhost:XamlApplication>

VBAudioRouter/App.xaml.vb renamed to VBAudioRouter.UWP/App.xaml.vb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
Imports VBAudioRouter.Dialogs
1+
Imports System.Runtime.InteropServices
2+
Imports Microsoft.Toolkit.Win32.UI.XamlHost
3+
Imports VBAudioRouter.Dialogs
24
Imports VBAudioRouter.Utils
35
Imports Windows.UI
46
Imports Windows.UI.Core.Preview
57

68
NotInheritable Class App
7-
Inherits Application
9+
Inherits XamlApplication
10+
11+
Public Sub New()
12+
Initialize()
13+
InitializeComponent()
14+
End Sub
815

916
Protected Overrides Async Sub OnLaunched(e As LaunchActivatedEventArgs)
1017
LaunchApp(e)
1.42 KB

VBAudioRouter/Controls/Nodes/FileInputNodeControl.xaml.vb renamed to VBAudioRouter.UWP/Controls/Nodes/FileInputNodeControl.xaml.vb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Imports VBAudioRouter.Utils
44
Imports Windows.Media.Audio
55
Imports Windows.Media.Core
66
Imports Windows.Storage.Pickers
7+
Imports WinUI.Interop
78

89
Namespace Controls.Nodes
910

@@ -50,6 +51,9 @@ Namespace Controls.Nodes
5051

5152
Private Async Sub Button_Click(sender As Object, e As RoutedEventArgs)
5253
Dim filePicker As New FileOpenPicker()
54+
If Not InteropHelper.IsUWP() Then
55+
DirectCast(filePicker, NativeWindow.IInitializeWithWindow).Initialize(Process.GetCurrentProcess().MainWindowHandle)
56+
End If
5357
#Region "Picker Init"
5458
filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary
5559
filePicker.FileTypeFilter.Add(".mp3")

VBAudioRouter/GraphViewPage.xaml.vb renamed to VBAudioRouter.UWP/GraphViewPage.xaml.vb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Public NotInheritable Class GraphViewPage
2222
isLoaded = True
2323

2424
Dim dialog As New Dialogs.OutputDeviceSelectDialog()
25+
dialog.XamlRoot = Me.XamlRoot
2526
Await dialog.ShowAsync()
2627

2728
Await InitAudioGraphAsync(CreateGraphSettings(dialog.SelectedRenderDevice))
@@ -56,6 +57,7 @@ Public NotInheritable Class GraphViewPage
5657
Public ReadOnly Property BackgroundAudioSession As ExtendedExecutionForegroundSession
5758

5859
Private Async Function EnableBackgroundAudioAsync() As Task
60+
If Not WinUI.Interop.InteropHelper.IsUWP() Then Exit Function
5961
_BackgroundAudioSession = New ExtendedExecutionForegroundSession()
6062
BackgroundAudioSession.Reason = ExtendedExecutionForegroundReason.BackgroundAudio
6163
BackgroundAudioSession.Description = "Play Background audio"
File renamed without changes.
File renamed without changes.

VBAudioRouter/SpeakerControlPage.xaml.vb renamed to VBAudioRouter.UWP/SpeakerControlPage.xaml.vb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@ Public NotInheritable Class SpeakerControlPage
2222
Dim timer As New Timers.Timer()
2323
timer.Interval = 30
2424
AddHandler timer.Elapsed, Sub()
25-
Dim unused = Dispatcher.RunIdleAsync(Sub()
26-
Dim meters As Single() = New Single(MeterInformation.GetMeteringChannelCount() - 1) {}
27-
Dim metersRef = GCHandle.Alloc(meters, GCHandleType.Pinned)
28-
MeterInformation.GetChannelsPeakValues(meters.Length, metersRef.AddrOfPinnedObject)
29-
metersRef.Free()
30-
LeftMeter.ScaleY = meters(0)
31-
RightMeter.ScaleY = meters(1)
32-
End Sub)
25+
Dim unused = Dispatcher?.RunIdleAsync(Sub()
26+
Dim meters As Single() = New Single(MeterInformation.GetMeteringChannelCount() - 1) {}
27+
Dim metersRef = GCHandle.Alloc(meters, GCHandleType.Pinned)
28+
MeterInformation.GetChannelsPeakValues(meters.Length, metersRef.AddrOfPinnedObject)
29+
metersRef.Free()
30+
LeftMeter.ScaleY = meters(0)
31+
RightMeter.ScaleY = meters(1)
32+
End Sub)
3333
End Sub
3434
timer.Enabled = True
3535

36-
Exit Sub
3736
_AudioSessionManager = DirectCast(Await AudioInterfaceActivator.ActivateAudioInterfaceAsync(Of IAudioSessionManager)(deviceId), IAudioSessionManager2)
3837
AudioSessionManager.RegisterSessionNotification(Me)
3938
Dim sessionEnumerator = AudioSessionManager.GetSessionEnumerator()
File renamed without changes.

VBAudioRouter/VBAudioRouter.vbproj renamed to VBAudioRouter.UWP/VBAudioRouter.UWP.vbproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@
431431
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
432432
<Version>7.1.2</Version>
433433
</PackageReference>
434+
<PackageReference Include="Microsoft.Toolkit.Win32.UI.XamlApplication">
435+
<Version>6.1.3</Version>
436+
</PackageReference>
434437
<PackageReference Include="Microsoft.UI.Xaml">
435438
<Version>2.8.0-prerelease.210927001</Version>
436439
</PackageReference>
@@ -447,7 +450,7 @@
447450
<Version>1.0.38</Version>
448451
</PackageReference>
449452
<PackageReference Include="WinUI.Interop">
450-
<Version>0.1.0</Version>
453+
<Version>0.1.2</Version>
451454
</PackageReference>
452455
</ItemGroup>
453456
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
File renamed without changes.

0 commit comments

Comments
 (0)