Usage of DwmSetWindowAttribute

I want to set DWMWA_TRANSITIONS_FORCEDISABLED, but not clear how to pass the arguments. Could anyone give an example how to use winapi_ui_automation::um::dwmapi::DwmSetWindowAttribute ?

pub unsafe extern "system" fn DwmSetWindowAttribute(
    hWnd: HWND, 
    dwAttribute: DWORD, 
    pvAttribute: LPCVOID, 
    cbAttribute: DWORD

Though I added dependency in Cargo.toml winapi-ui-automation = "0.3.10", and in extern crate winapi_ui_automation;, when built an error say "can't find crate winapi_ui_automation". I find the crate, how could I added to my project ?

You might want to use winapi::um::dwmapi::DwmSetWindowAttribute() from the winapi crate and activate the dwmapi feature.

Looking at Microsoft's API docs, I'm assuming you would set the DWMWA_TRANSITIONS_FORCEDISABLED something like this:

use winapi::{
    minwindef::{BOOL, TRUE},
    winerror::{HRESULT, S_OK},
  um::dwmapi::{DwmSetWindowAttribute, DWMWA_TRANSITIONS_FORCEDISABLED},

unsafe {
  let hwnd = get_handle_for_window();
  let value: BOOL = TRUE;
  let result: HRESULT = DwmSetWindowAttribute(
    &value as *const BOOL as *const _,
    std::mem::size_of::<BOOL>() as _,

  if result != S_OK {
    // handle the error

Thanks for your kindness.

Could you please give a short explainaton of this conversion? &value as *const BOOL as *const _,. I have bool value, and need a pointer LPCVOID. Why two step conversion , and a ' _ ' ?

You can cast from a &TypeOne to a *const TypeOne, and from a *const TypeOne to a *const TypeTwo, but you can't cast directly from &TypeOne to *const TypeTwo.

In general, _ means "compiler, please infer the type for me". It's possible here because the compiler knows what the types of the arguments to DwmSetWindowAttribute are (and because LPCVOID is a type alias for *const c_void).


&value           // &BOOL
  as *const BOOL // *const BOOL
  as *const _    // *const c_void, aka LPCVOID

Great! Thank you.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.