Add file dialog sample (#3226)
This commit is contained in:
Родитель
88a80f2022
Коммит
316d54483d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -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(())
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче