From 76a5b55fe41abab866c14e26b69a902d5f1fa8f6 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 18 Jan 2024 10:05:52 -0600 Subject: [PATCH 1/3] task dialog samples --- .../windows-sys/task_dialog/Cargo.toml | 12 +++++ .../samples/windows-sys/task_dialog/build.rs | 13 ++++++ .../windows-sys/task_dialog/manifest.xml | 19 ++++++++ .../windows-sys/task_dialog/src/main.rs | 44 +++++++++++++++++++ crates/samples/windows/task_dialog/Cargo.toml | 12 +++++ crates/samples/windows/task_dialog/build.rs | 13 ++++++ .../samples/windows/task_dialog/manifest.xml | 19 ++++++++ .../samples/windows/task_dialog/src/main.rs | 43 ++++++++++++++++++ 8 files changed, 175 insertions(+) create mode 100644 crates/samples/windows-sys/task_dialog/Cargo.toml create mode 100644 crates/samples/windows-sys/task_dialog/build.rs create mode 100644 crates/samples/windows-sys/task_dialog/manifest.xml create mode 100644 crates/samples/windows-sys/task_dialog/src/main.rs create mode 100644 crates/samples/windows/task_dialog/Cargo.toml create mode 100644 crates/samples/windows/task_dialog/build.rs create mode 100644 crates/samples/windows/task_dialog/manifest.xml create mode 100644 crates/samples/windows/task_dialog/src/main.rs diff --git a/crates/samples/windows-sys/task_dialog/Cargo.toml b/crates/samples/windows-sys/task_dialog/Cargo.toml new file mode 100644 index 0000000000..c6001abb56 --- /dev/null +++ b/crates/samples/windows-sys/task_dialog/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "sample_task_dialog_sys" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.windows-sys] +path = "../../../libs/sys" +features = [ + "Win32_UI_Controls", + "Win32_UI_WindowsAndMessaging", +] diff --git a/crates/samples/windows-sys/task_dialog/build.rs b/crates/samples/windows-sys/task_dialog/build.rs new file mode 100644 index 0000000000..2a3e49c9a8 --- /dev/null +++ b/crates/samples/windows-sys/task_dialog/build.rs @@ -0,0 +1,13 @@ +fn main() { + println!("cargo:rerun-if-changed=manifest.xml"); + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rustc-link-arg-bins=/MANIFEST:EMBED"); + + println!( + "cargo:rustc-link-arg-bins=/MANIFESTINPUT:{}", + std::path::Path::new("manifest.xml") + .canonicalize() + .unwrap() + .display() + ); +} diff --git a/crates/samples/windows-sys/task_dialog/manifest.xml b/crates/samples/windows-sys/task_dialog/manifest.xml new file mode 100644 index 0000000000..a35c4d237f --- /dev/null +++ b/crates/samples/windows-sys/task_dialog/manifest.xml @@ -0,0 +1,19 @@ + + + + true + PerMonitorV2 + + + + + + + + diff --git a/crates/samples/windows-sys/task_dialog/src/main.rs b/crates/samples/windows-sys/task_dialog/src/main.rs new file mode 100644 index 0000000000..37583d4025 --- /dev/null +++ b/crates/samples/windows-sys/task_dialog/src/main.rs @@ -0,0 +1,44 @@ +use windows_sys::{core::*, Win32::Foundation::*, Win32::UI::Controls::*}; + +fn main() { + unsafe { + let mut config = TASKDIALOGCONFIG { + cbSize: std::mem::size_of::() as _, + ..std::mem::zeroed() + }; + + let buttons = [TASKDIALOG_BUTTON { + nButtonID: 123, + pszButtonText: w!("Let's do it"), + }]; + + config.pszWindowTitle = w!("Window title"); + config.pszMainInstruction = w!("Main instruction"); + config.pszContent = w!("Content"); + config.pButtons = buttons.as_ptr(); + config.cButtons = buttons.len() as _; + config.pfCallback = Some(callback); + config.dwFlags = TDF_USE_COMMAND_LINKS | TDF_ALLOW_DIALOG_CANCELLATION; + + let mut selection = 0; + + TaskDialogIndirect( + &config, + &mut selection, + std::ptr::null_mut(), + std::ptr::null_mut(), + ); + + if selection == buttons[0].nButtonID { + println!("custom button"); + }; + } +} + +extern "system" fn callback(_: HWND, notification: u32, _: WPARAM, _: LPARAM, _: isize) -> HRESULT { + if notification == TDN_BUTTON_CLICKED as _ { + println!("button clicked"); + } + + 0 +} diff --git a/crates/samples/windows/task_dialog/Cargo.toml b/crates/samples/windows/task_dialog/Cargo.toml new file mode 100644 index 0000000000..028232b4e4 --- /dev/null +++ b/crates/samples/windows/task_dialog/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "sample_task_dialog" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.windows] +path = "../../../libs/windows" +features = [ + "Win32_UI_Controls", + "Win32_UI_WindowsAndMessaging", +] diff --git a/crates/samples/windows/task_dialog/build.rs b/crates/samples/windows/task_dialog/build.rs new file mode 100644 index 0000000000..2a3e49c9a8 --- /dev/null +++ b/crates/samples/windows/task_dialog/build.rs @@ -0,0 +1,13 @@ +fn main() { + println!("cargo:rerun-if-changed=manifest.xml"); + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rustc-link-arg-bins=/MANIFEST:EMBED"); + + println!( + "cargo:rustc-link-arg-bins=/MANIFESTINPUT:{}", + std::path::Path::new("manifest.xml") + .canonicalize() + .unwrap() + .display() + ); +} diff --git a/crates/samples/windows/task_dialog/manifest.xml b/crates/samples/windows/task_dialog/manifest.xml new file mode 100644 index 0000000000..a35c4d237f --- /dev/null +++ b/crates/samples/windows/task_dialog/manifest.xml @@ -0,0 +1,19 @@ + + + + true + PerMonitorV2 + + + + + + + + diff --git a/crates/samples/windows/task_dialog/src/main.rs b/crates/samples/windows/task_dialog/src/main.rs new file mode 100644 index 0000000000..df0c8733c5 --- /dev/null +++ b/crates/samples/windows/task_dialog/src/main.rs @@ -0,0 +1,43 @@ +use windows::{core::*, Win32::Foundation::*, Win32::UI::Controls::*}; + +fn main() -> Result<()> { + unsafe { + let mut config = TASKDIALOGCONFIG { + cbSize: std::mem::size_of::() as _, + ..Default::default() + }; + + let buttons = [TASKDIALOG_BUTTON { + nButtonID: 123, + pszButtonText: w!("Let's do it"), + }]; + + config.pszWindowTitle = w!("Window title"); + config.pszMainInstruction = w!("Main instruction"); + config.pszContent = w!("Content"); + config.pButtons = buttons.as_ptr(); + config.cButtons = buttons.len() as _; + config.pfCallback = Some(callback); + + config.dwFlags = + TASKDIALOG_FLAGS(TDF_USE_COMMAND_LINKS.0 | TDF_ALLOW_DIALOG_CANCELLATION.0); + + let mut selection = 0; + + TaskDialogIndirect(&config, Some(&mut selection), None, None)?; + + if selection == buttons[0].nButtonID { + println!("custom button"); + }; + + Ok(()) + } +} + +extern "system" fn callback(_: HWND, notification: u32, _: WPARAM, _: LPARAM, _: isize) -> HRESULT { + if notification == TDN_BUTTON_CLICKED.0 as _ { + println!("button clicked"); + } + + HRESULT(0) +} From 7f26f4d827375fd76c0eb2f31226b66a8a689130 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 18 Jan 2024 10:13:01 -0600 Subject: [PATCH 2/3] yml --- .github/workflows/clippy.yml | 2 ++ .github/workflows/test.yml | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 7104bf229d..9f69a9da0c 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -63,6 +63,8 @@ jobs: cargo clippy -p sample_shell && cargo clippy -p sample_simple && cargo clippy -p sample_spellchecker && + cargo clippy -p sample_task_dialog && + cargo clippy -p sample_task_dialog_sys && cargo clippy -p sample_thread_pool_work && cargo clippy -p sample_thread_pool_work_sys && cargo clippy -p sample_uiautomation && diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 30fa52b2df..9f1d9777ad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -70,6 +70,8 @@ jobs: cargo test -p sample_shell && cargo test -p sample_simple && cargo test -p sample_spellchecker && + cargo test -p sample_task_dialog && + cargo test -p sample_task_dialog_sys && cargo test -p sample_thread_pool_work && cargo test -p sample_thread_pool_work_sys && cargo test -p sample_uiautomation && @@ -100,8 +102,8 @@ jobs: cargo test -p test_does_not_return && cargo test -p test_enums && cargo test -p test_error && - cargo test -p test_event && cargo clean && + cargo test -p test_event && cargo test -p test_extensions && cargo test -p test_handles && cargo test -p test_helpers && From 7b0f50951b0d2cd89338f3ae0c7a6714946f455e Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 18 Jan 2024 10:24:49 -0600 Subject: [PATCH 3/3] Manifests only work with MSVC --- .../samples/windows-sys/task_dialog/build.rs | 21 +++++++++++-------- crates/samples/windows/task_dialog/build.rs | 21 +++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/crates/samples/windows-sys/task_dialog/build.rs b/crates/samples/windows-sys/task_dialog/build.rs index 2a3e49c9a8..00f1a307ad 100644 --- a/crates/samples/windows-sys/task_dialog/build.rs +++ b/crates/samples/windows-sys/task_dialog/build.rs @@ -1,13 +1,16 @@ fn main() { - println!("cargo:rerun-if-changed=manifest.xml"); println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rustc-link-arg-bins=/MANIFEST:EMBED"); - println!( - "cargo:rustc-link-arg-bins=/MANIFESTINPUT:{}", - std::path::Path::new("manifest.xml") - .canonicalize() - .unwrap() - .display() - ); + if std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "msvc" { + println!("cargo:rerun-if-changed=manifest.xml"); + println!("cargo:rustc-link-arg-bins=/MANIFEST:EMBED"); + + println!( + "cargo:rustc-link-arg-bins=/MANIFESTINPUT:{}", + std::path::Path::new("manifest.xml") + .canonicalize() + .unwrap() + .display() + ); + } } diff --git a/crates/samples/windows/task_dialog/build.rs b/crates/samples/windows/task_dialog/build.rs index 2a3e49c9a8..00f1a307ad 100644 --- a/crates/samples/windows/task_dialog/build.rs +++ b/crates/samples/windows/task_dialog/build.rs @@ -1,13 +1,16 @@ fn main() { - println!("cargo:rerun-if-changed=manifest.xml"); println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rustc-link-arg-bins=/MANIFEST:EMBED"); - println!( - "cargo:rustc-link-arg-bins=/MANIFESTINPUT:{}", - std::path::Path::new("manifest.xml") - .canonicalize() - .unwrap() - .display() - ); + if std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "msvc" { + println!("cargo:rerun-if-changed=manifest.xml"); + println!("cargo:rustc-link-arg-bins=/MANIFEST:EMBED"); + + println!( + "cargo:rustc-link-arg-bins=/MANIFESTINPUT:{}", + std::path::Path::new("manifest.xml") + .canonicalize() + .unwrap() + .display() + ); + } }