How to increase brightness with windows-rs?

I have been trying to create a small program to run on autostart to set my brightness, contrast and gamma as setting these in nvidia's control panel will reset to default upon restart.
I found windows-rs and figured it would be the best way to achieve what I wanted, but im unsure as how to get parts working.

I found the SetMonitorBrightness function within windows::Win32::Devices::Display and have my code as

use windows::{core::*, Win32::Devices::Display::*, Win32::Foundation::*};

fn main() {
    unsafe {
        let bright:i32 = SetMonitorBrightness(TODO,10);

but currently i'm having trouble figuring out how to satisfy the first argument.

The documents list needing this HANDLE from windows::Win32::Foundation as shown below.

pub unsafe fn SetMonitorBrightness<P0>(
    hmonitor: P0,
    dwnewbrightness: u32
) -> i32
    P0: IntoParam<HANDLE>,

but im unsure as to what constant to use to satisfy the HANDLE as Win32::Foundation has thousands of constants and I cant check every one to see if it has the Into trait if im understanding everything correctly.

Does anyone know what constant to use or am I missing something entierly?

You are not looking for a constant; a handle is typically acquired at runtime. In this case, by calling other functions of the Windows API.
Unfortunately, the documentation you need is not available on windows and windows-sys crates are generated from the Windows API metadata, and do not include any rustdoc. Instead, you need to go on

The documention for SetMonitorBrightness is found here.
You’ll find information on how you can retrieve a handle properly:

I suggest you dig the documentation from here. At some point you will enumerate the monitors, filter out what does not interest you (you may receive pseudo-monitors), and so on until you have everything you need to call SetMonitorBrightness, i.e., the handle for the monitor you are interested in.

You may also want to call GetMonitorBrightness in order to find what are the minimum and maximum brightness values.


Also note that handle values are temporary, so you'll want to save a monitor GUID if you have multiple.


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.