Last active
July 18, 2016 08:17
-
-
Save ROki1988/af1a02e8f511d4b920f3e908c0f08b09 to your computer and use it in GitHub Desktop.
rust_sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate winapi; | |
extern crate user32; | |
fn main() { | |
println!("{}", get_foreground_window_title()) | |
} | |
fn get_foreground_window_title() -> String { | |
use std::ffi::OsString; | |
use std::os::windows::ffi::OsStringExt; | |
unsafe { | |
let whdl = user32::GetForegroundWindow(); | |
let length = user32::GetWindowTextLengthW(whdl); | |
let mut title = vec![ 0u16; (length+1) as usize ]; | |
user32::GetWindowTextW(whdl, title.as_mut_ptr(), length + 1); | |
OsString::from_wide(&title).to_string_lossy().into_owned() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RustとWindowsのワイド文字列(LPCWSTR / LPWSTR) | d.sunnyone.org
klutzy/rust-windows