zoukankan      html  css  js  c++  java
  • rust win32api EnumWindows

    1 Cargo.toml

    [package]
    name = "hellowinapi"
    version = "0.1.0"
    edition = "2018"
    
    # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
    
    [dependencies]
    windows = "0.19"
    
    [build-dependencies]
    windows = "0.19"

    2  build.rs

    fn main() {
        windows::build! {
            Windows::Win32::
            {UI::WindowsAndMessaging::{
                EnumWindows, GetWindowTextW,            
            },
            {Storage::FileSystem::GetLogicalDriveStringsW,}
        }
        };
    }

    3 src/main.rs

    mod bindings {
        windows::include_bindings!();
    }
    
    use {bindings::Windows::Win32::{UI::WindowsAndMessaging::{EnumWindows,GetWindowTextW,},
        Foundation::{LPARAM,HWND,BOOL,PWSTR,}
    }};
    fn main() -> windows::Result<()> {
        unsafe { EnumWindows(Some(enum_window), LPARAM(0)).ok() }
    }
    
    extern "system" fn enum_window(window: HWND, _: LPARAM) -> BOOL {
        unsafe {
            let mut text: [u16; 512] = [0; 512];
            let len = GetWindowTextW(window, PWSTR(text.as_mut_ptr()), text.len() as i32);
            let text = String::from_utf16_lossy(&text[..len as usize]);
    
            if !text.is_empty() {
                println!("{}", text);
            }
    
            return true.into();
        }
    }

    参考:https://hub.fastgit.org/microsoft/windows-samples-rs

    https://hub.fastgit.org/microsoft/windows-rs

    https://microsoft.github.io/windows-docs-rs/doc/bindings/Windows/

  • 相关阅读:
    MinkowskiPooling池化(上)
    稀疏张量基础
    稀疏张量网络
    英伟达TRTTorch
    闵可夫斯基引擎Minkowski Engine
    reactive和reactor
    today search
    today news 2020-8-8
    如何去写一本精品小书?
    today news
  • 原文地址:https://www.cnblogs.com/pu369/p/15239469.html
Copyright © 2011-2022 走看看