Skip to content

Commit

Permalink
sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Aug 27, 2024
1 parent 88a80f2 commit 0fe87c9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ jobs:
run: cargo clippy -p sample_enum_windows
- name: Clippy sample_enum_windows_sys
run: cargo clippy -p sample_enum_windows_sys
- name: Clippy sample_file_dialogs
run: cargo clippy -p sample_file_dialogs
- name: Clippy sample_kernel_event
run: cargo clippy -p sample_kernel_event
- name: Clippy sample_memory_buffer
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ jobs:
run: cargo test -p sample_enum_windows --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_enum_windows_sys
run: cargo test -p sample_enum_windows_sys --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_file_dialogs
run: cargo test -p sample_file_dialogs --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_kernel_event
run: cargo test -p sample_kernel_event --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_memory_buffer
Expand Down Expand Up @@ -151,10 +153,10 @@ jobs:
run: cargo test -p test_alternate_success_code --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_arch
run: cargo test -p test_arch --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_arch_feature
run: cargo test -p test_arch_feature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_arch_feature
run: cargo test -p test_arch_feature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_array
run: cargo test -p test_array --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_bcrypt
Expand Down Expand Up @@ -253,10 +255,10 @@ jobs:
run: cargo test -p test_result --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_return_handle
run: cargo test -p test_return_handle --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_return_struct
run: cargo test -p test_return_struct --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_return_struct
run: cargo test -p test_return_struct --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_riddle
run: cargo test -p test_riddle --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_standalone
Expand Down
12 changes: 12 additions & 0 deletions crates/samples/windows/file_dialogs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "sample_file_dialogs"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies.windows]
path = "../../../libs/windows"
features = [
"Win32_UI_Shell_Common",
"Win32_System_Com",
]
31 changes: 31 additions & 0 deletions crates/samples/windows/file_dialogs/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use windows::{core::*, Win32::System::Com::*, Win32::UI::Shell::Common::*, Win32::UI::Shell::*};

fn main() -> Result<()> {
unsafe {
CoIncrementMTAUsage()?;

let dialog: IFileSaveDialog = CoCreateInstance(&FileSaveDialog, None, CLSCTX_ALL)?;

dialog.SetFileTypes(&[
COMDLG_FILTERSPEC {
pszName: w!("Text files"),
pszSpec: w!("*.txt"),
},
COMDLG_FILTERSPEC {
pszName: w!("All files"),
pszSpec: w!("*.*"),
},
])?;

if dialog.Show(None).is_ok() {
let result = dialog.GetResult()?;
let path = result.GetDisplayName(SIGDN_FILESYSPATH)?;
println!("user picked: {}", path.display());
CoTaskMemFree(Some(path.0 as _));
} else {
println!("user canceled");
}

Ok(())
}
}

0 comments on commit 0fe87c9

Please sign in to comment.