/// Gets the title for the window, or in the case of a control field, gets
/// the text on the object
Gets the title for the window, or in the case of a control field, gets
the text on the object
Gets the title for the window or in the case of a control field gets the text on the object
pub fn window_text(&self) -> Result<String, Box<dyn Error>> {
        let text_len = unsafe { GetWindowTextLengthW(self.hwnd) };
        // Return an empty string if the window text length was reported as
        // zero
        if text_len == 0 {
            return Ok(String::new());
        }
        // Allocate a buffer to hold `text_len` wide characters
        let text_len: usize = text_len.try_into().unwrap();
        let alc_len = text_len.checked_add(1).unwrap();
        let mut wchar_buffer: Vec<u16> = Vec::with_capacity(alc_len);
        unsafe {
            // Get the window text
            let ret = GetWindowTextW(self.hwnd, wchar_buffer.as_mut_ptr(),
                alc_len.try_into().unwrap());
            // Set the length of the vector
            wchar_buffer.set_len(ret.try_into().unwrap());
        }
        // Convert the UTF-16 string into a Rust UTF-8 `String`
        String::from_utf16(wchar_buffer.as_slice()).map_err(|x| {
            x.into()
        })
    }
pub fn window_text ( & self ) -> Result < String , Box < dyn Error > > { let text_len = unsafe { GetWindowTextLengthW ( self . hwnd ) } ; // Return an empty string if the window text length was reported as // zero if text_len == 0 { return Ok ( String :: new ( ) ) ; } // Allocate a buffer to hold `text_len` wide characters let text_len : usize = text_len . try_into ( ) . unwrap ( ) ; let alc_len = text_len . checked_add ( 1 ) . unwrap ( ) ; let mut wchar_buffer : Vec < u16 > = Vec :: with_capacity ( alc_len ) ; unsafe { // Get the window text let ret = GetWindowTextW ( self . hwnd , wchar_buffer . as_mut_ptr ( ) , alc_len . try_into ( ) . unwrap ( ) ) ; // Set the length of the vector wchar_buffer . set_len ( ret . try_into ( ) . unwrap ( ) ) ; } // Convert the UTF-16 string into a Rust UTF-8 `String` String :: from_utf16 ( wchar_buffer . as_slice ( ) ) . map_err ( | x | { x . into ( ) } ) }
Gets the title for the window, or in the case of a control field, gets
the text on the object
Gets the title for the window or in the case of a control field gets the text on the object
&self