简体   繁体   中英

Unable to get the physical monitor handle on Windows 7 for color calibration

I'm on Windows 7 and I'm trying to change the color balance from code. Specifically, I'm trying to change these sliders that show on the color calibration wizard. I'm assuming that the correct functions are SetMonitorRedGreenOrBlueGain and SetMonitorRedGreenOrBlueDrive .

Here is my minimal working example:

#pragma comment(lib, "dxva2.lib")
#include <windows.h>
#include <lowlevelmonitorconfigurationapi.h>
#include <physicalmonitorenumerationapi.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>

using namespace std;

int main()
{   
    HWND hWnd = GetDesktopWindow();
    HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY);
    cout << "Monitor: " << hMonitor << endl;

    DWORD cPhysicalMonitors;
    BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &cPhysicalMonitors);
    cout << "GetNumber: " << bSuccess << ", number of physical monitors: " << cPhysicalMonitors << endl;

    LPPHYSICAL_MONITOR pPhysicalMonitors = (LPPHYSICAL_MONITOR)malloc(cPhysicalMonitors * sizeof(PHYSICAL_MONITOR));
    bSuccess = GetPhysicalMonitorsFromHMONITOR(hMonitor, cPhysicalMonitors, pPhysicalMonitors);
    cout << "GetPhysicalMonitor: " << bSuccess << endl
        << "Handle: " << pPhysicalMonitors[0].hPhysicalMonitor << endl
        << "Description: ";
    wcout << (WCHAR*)(pPhysicalMonitors[0].szPhysicalMonitorDescription);
    
    DestroyPhysicalMonitors(cPhysicalMonitors, pPhysicalMonitors);
    free(pPhysicalMonitors);    
    
}

The output is:

Monitor: 00010001
GetNumber: 1, number of physical monitors: 1
GetPhysicalMonitor: 1
Handle: 00000000
Description: Generic PnP Monitor

All the functions for brightness and color gains require HANDLE hPhysicalMonitor which is always null for my display (laptop screen). But, I know it must be possible to change the color balance since the color calibration window can do that.

What am I doing wrong?

EDIT 1:

As mentioned in the comments, it seems that the hPhysicalMonitor is correct. My issue is that calling functions like GetMonitorBrightness returns FALSE with an error code of ERROR_GRAPHICS_I2C_ERROR_TRANSMITTING_DATA (An error occurred while transmitting data to the device on the I2C bus.)

EDIT 2:

My monitor does support setting brightness and has 11 levels. Windows itself and some programs are able to adjust the brightness (the back-light of the monitor directly). So the issue must be software related.

My issue is that calling functions like GetMonitorBrightness returns FALSE with an error code of ERROR_GRAPHICS_I2C_ERROR_TRANSMITTING_DATA (An error occurred while transmitting data to the device on the I2C bus.)

GetMonitorBrightness works for me. I tested it on ie desktop. Some similar cases point out that GetMonitorBrightness does not work on some laptops.

I think your laptop does not support DDC/CI.

GetMonitorCapabilities : The function fails if the monitor does not support DDC/CI.

You may first check if your laptop supports DDC/Cl.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM