Skip to content

Commit

Permalink
task dialog samples
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Jan 18, 2024
1 parent 587520b commit 76a5b55
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/samples/windows-sys/task_dialog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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",
]
13 changes: 13 additions & 0 deletions crates/samples/windows-sys/task_dialog/build.rs
Original file line number Diff line number Diff line change
@@ -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()
);
}
19 changes: 19 additions & 0 deletions crates/samples/windows-sys/task_dialog/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:application>
<asmv3:windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"/>
</dependentAssembly>
</dependency>
</assembly>
44 changes: 44 additions & 0 deletions crates/samples/windows-sys/task_dialog/src/main.rs
Original file line number Diff line number Diff line change
@@ -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::<TASKDIALOGCONFIG>() 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
}
12 changes: 12 additions & 0 deletions crates/samples/windows/task_dialog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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",
]
13 changes: 13 additions & 0 deletions crates/samples/windows/task_dialog/build.rs
Original file line number Diff line number Diff line change
@@ -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()
);
}
19 changes: 19 additions & 0 deletions crates/samples/windows/task_dialog/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:application>
<asmv3:windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"/>
</dependentAssembly>
</dependency>
</assembly>
43 changes: 43 additions & 0 deletions crates/samples/windows/task_dialog/src/main.rs
Original file line number Diff line number Diff line change
@@ -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::<TASKDIALOGCONFIG>() 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)
}

0 comments on commit 76a5b55

Please sign in to comment.