i am trying make a web show ruler, but firefox can’t find real dpi(dot pre inch).
i make a demo get dpi from windows.
cargo.toml
[package]
name = "aaaaa"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-
lang.org/cargo/reference/manifest.html
[dependencies.windows]
version = "0.51.1"
features = [
"Devices_Display",
"Devices_Display_Core",
"Foundation_Collections"
]
main.rs
use windows::{
Devices::Display::Core::*
};
fn main() {
match DisplayManager::Create(DisplayManagerOptions::None){
Ok(display_manager) => {
match &display_manager.GetCurrentTargets(){
Ok(display_target) => {
for x in display_target {
match x.IsConnected(){
Ok(is_connected) => {
if is_connected==false{
continue
}
}
Err(err) => {
println!("{:?}", err)
}
}
match x.TryGetMonitor(){
Ok(display_monitor) => {
match display_monitor.RawDpiX(){
Ok(dpi_x) => {
println!("dpi_x:{0}", dpi_x)
}
Err(_) => {}
}
match display_monitor.RawDpiX(){
Ok(dpi_y) => {
println!("dpi_y:{0}", dpi_y)
}
Err(_) => {}
}
}
Err(err) => {
println!("{:?}", err)
}
}
}
}
Err(err) => {
println!("{:?}", err)
}
}
}
Err(err) => {
println!("{:?}", err)
}
}
}