Skip to content

Commit

Permalink
Improve core/xaml app sample ergonomics (#1463)
Browse files Browse the repository at this point in the history
  • Loading branch information
riverar committed Jan 26, 2022
1 parent 130e3bf commit d6b88f4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 8 deletions.
4 changes: 4 additions & 0 deletions crates/samples/core_app/Cargo.toml
Expand Up @@ -6,8 +6,12 @@ edition = "2018"
[dependencies.windows]
path = "../../libs/windows"
features = [
"alloc",
"implement",
"ApplicationModel_Core",
"UI_Core",
"Win32_Foundation",
"Win32_Storage_Packaging_Appx",
"Win32_System_Com",
"Win32_UI_WindowsAndMessaging"
]
2 changes: 1 addition & 1 deletion crates/samples/core_app/appx/AppxManifest.xml
Expand Up @@ -19,7 +19,7 @@
<Resource Language="en-us" />
</Resources>
<Applications>
<Application Id="App" Executable="sample.exe" EntryPoint="CoreApp.App">
<Application Id="App" Executable="core_app.exe" EntryPoint="CoreApp.App">
<uap:VisualElements DisplayName="Rust CoreApp" Description="Description"
Square150x150Logo="Square150x150Logo.png" Square44x44Logo="Square44x44Logo.png" BackgroundColor="transparent">
<uap:SplashScreen Image="SplashScreen.png" />
Expand Down
7 changes: 4 additions & 3 deletions crates/samples/core_app/register.cmd
@@ -1,5 +1,6 @@
cargo build
copy appx\* target\debug
cd target\debug
copy appx\* ..\..\..\target\debug
cd ..\..\..\target\debug
powershell -command "Get-AppxPackage *0f8c5510-182f-4208-a48e-4215050a0453* | Remove-AppxPackage"
powershell -command "Add-AppxPackage -Register AppxManifest.xml"
cd ..\..\
cd ..\..\crates\samples\core_app
16 changes: 15 additions & 1 deletion crates/samples/core_app/src/main.rs
@@ -1,6 +1,15 @@
#![windows_subsystem = "windows"]

use windows::{core::*, ApplicationModel::Core::*, Win32::System::Com::*, UI::Core::*};
use windows::{
core::*,
ApplicationModel::{Core::*, Package},
Win32::{
Foundation::HWND,
System::Com::*,
UI::WindowsAndMessaging::{MessageBoxW, MB_ICONSTOP, MB_OK},
},
UI::Core::*,
};

#[implement(IFrameworkViewSource)]
struct CoreApp();
Expand Down Expand Up @@ -48,6 +57,11 @@ impl IFrameworkView_Impl for CoreAppView {
fn main() -> Result<()> {
unsafe {
CoInitializeEx(std::ptr::null_mut(), COINIT_MULTITHREADED)?;

if let Err(result) = Package::Current() {
MessageBoxW(HWND::default(), "This sample must be registered (via register.cmd) and launched from Start.", "Error", MB_ICONSTOP | MB_OK);
return Err(result);
}
}

let app: IFrameworkViewSource = CoreApp().into();
Expand Down
6 changes: 5 additions & 1 deletion crates/samples/xaml_app/Cargo.toml
Expand Up @@ -6,9 +6,13 @@ edition = "2018"
[dependencies.windows]
path = "../../libs/windows"
features = [
"alloc",
"implement",
"ApplicationModel_Activation",
"Win32_System_Com",
"UI_Xaml_Controls",
"UI_Xaml",
"Win32_Foundation",
"Win32_Storage_Packaging_Appx",
"Win32_System_Com",
"Win32_UI_WindowsAndMessaging",
]
2 changes: 1 addition & 1 deletion crates/samples/xaml_app/register.cmd
@@ -1,6 +1,6 @@
cargo build
copy appx\* ..\..\..\target\debug
cd ..\..\..\target\debug
powershell -command "Get-AppxPackage *942b16b2* | Remove-AppxPackage"
powershell -command "Get-AppxPackage *942b16b2-c2af-4092-ba34-e4f0c2df308b* | Remove-AppxPackage"
powershell -command "Add-AppxPackage -Register AppxManifest.xml"
cd ..\..\crates\samples\xaml_app
18 changes: 17 additions & 1 deletion crates/samples/xaml_app/src/main.rs
@@ -1,7 +1,17 @@
#![windows_subsystem = "windows"]
#![allow(non_snake_case)]

use windows::{core::*, ApplicationModel::Activation::*, Win32::System::Com::*, UI::Xaml::Controls::*, UI::Xaml::*};
use windows::{
core::*,
ApplicationModel::{Activation::LaunchActivatedEventArgs, Package},
Win32::System::Com::*,
Win32::{
Foundation::HWND,
UI::WindowsAndMessaging::{MessageBoxW, MB_ICONSTOP, MB_OK},
},
UI::Xaml::Controls::*,
UI::Xaml::*,
};

#[implement(IApplicationOverrides)]
struct MyApp();
Expand All @@ -17,7 +27,13 @@ impl IApplicationOverrides_Impl for MyApp {
fn main() -> Result<()> {
unsafe {
CoInitializeEx(std::ptr::null_mut(), COINIT_MULTITHREADED)?;

if let Err(result) = Package::Current() {
MessageBoxW(HWND::default(), "This sample must be registered (via register.cmd) and launched from Start.", "Error", MB_ICONSTOP | MB_OK);
return Err(result);
}
}

Application::Start(ApplicationInitializationCallback::new(|_| {
Application::compose(MyApp())?;
Ok(())
Expand Down

0 comments on commit d6b88f4

Please sign in to comment.