2016-11-23 2 views
0

나는 다음과 같은 코드를 사용하여 기본 모니터의 밝기를 얻기 위해 노력 :WINAPI C는 ++

POINT monitorPoint = { 0, 0 }; 
    HANDLE monitor = MonitorFromPoint(monitorPoint, MONITOR_DEFAULTTOPRIMARY); 

    DWORD minb, maxb, currb; 
    if (GetMonitorBrightness(monitor, &minb, &currb, &maxb) == FALSE) { 
     std::cout << GetLastError() << std::endl; 
    } 

을하지만 실패하고 Invalid Parameter을 의미 GetLastError() 반환 87.

편집 :는이 같은 EnumDisplayMonitors()GetPhysicalMonitorsFromHMONITOR()를 사용하여이 문제를 해결하기 위해 관리 :

이제
std::vector<HANDLE> pMonitors; 

BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { 

    DWORD npm; 
    GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &npm); 
    PHYSICAL_MONITOR *pPhysicalMonitorArray = new PHYSICAL_MONITOR[npm]; 

    GetPhysicalMonitorsFromHMONITOR(hMonitor, npm, pPhysicalMonitorArray); 

    for (unsigned int j = 0; j < npm; ++j) { 
     pMonitors.push_back(pPhysicalMonitorArray[j].hPhysicalMonitor); 
    } 

    delete pPhysicalMonitorArray; 

    return TRUE; 
} 

// and later inside main simply: 
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, NULL); 

// and when I need to change the brightness: 
for (unsigned int i = 0; i < pMonitors.size(); ++i) { 
    SetMonitorBrightness(pMonitors.at(i), newValue); 
} 

나는이 새로운 문제가 발생 :

나는이 모니터가 내가 가지고 있기 때문에 처리 수 EnumDisplayMonitors()에서

1) 2 모니터. 문제는 단지 내 기본 작품입니다. 이 기본 모니터에 대해서도 작동을 멈 춥니 다 몇 시간 동안 SetMonitorBrightness()을 사용한 후

0xC0262582: ERROR_GRAPHICS_I2C_ERROR_TRANSMITTING_DATA

2) 나는 다음과 같은 오류 얻을 : 내가 보조 모니터 그래서 뭔가하려고 할 때마다 나는이 오류가

0xC026258D

+0

당신은 monitor'이'NULL' 또는'INVALID_HANDLE_VALUE'없는 '것을 확인 했습니까? – selbie

+0

GetMonitorCapabilities를 호출하여 MC_CAPS_BRIGHTNESS 플래그를 사용할 수 있는지 확인 했습니까? – selbie

+0

'MonitorFromPoint()'는'HANDLE'이 아닌'HMONITOR'를 리턴합니다. STRICT를 사용하여 컴파일하는 경우 코드가 컴파일되지 않습니다. –

답변

2

HMONITOR을 함수에 전달 중입니다. 그러나 설명서에 물리적 모니터에 대한 핸들이 필요하며이를 얻으려면 GetPhysicalMonitorsFromHMONITOR()으로 전화하는 것이 좋습니다. 실제로 MonitorFromPoint()은 을 반환하므로 STRICT 코드를 컴파일하지 못했을 수 있습니다. 이러한 실수를 근절하는 데 도움이되는 연습입니다.

MonitorFromPoint()에 대한 호출에 대한 오류 검사를 포함해야합니다. 그리고 설명서에서는 GetMonitorCapabilities()MC_CAPS_BRIGHTNESS으로 전달하여 모니터가 밝기 요청을 지원하는지 확인해야한다고 제안합니다.

자세한 내용에 대한 GetMonitorBrightness()의 문서를 참조하십시오 :

+0

'GetMonitorCapabilities()'는'ERROR_GRAPHICS_INVALID_PHYSICAL_MONITOR_HANDLE' 오류를 반환합니다. 이는 내 문제가'HANDLE monitor = MonitorFromPoint (...)'행임을 의미합니다. 'GetPhysicalMonitorsFromHMONITOR'를 사용하여 모니터 핸들을 얻는 방법에 대한 예를 들어 주시겠습니까? – DimChtz

+1

[GetPhysicalMonitorsFromHMONITOR()'설명서] (https://msdn.microsoft.com/en-us/library/windows/desktop/dd692950.aspx)에서 예제를 보았습니까? 유일한 차이점은'MonitorFromPoint()'대신'MonitorFromWindow()'를 사용하지만, 당신의 예제에서는 그다지 중요하지 않다는 것입니다. –

+0

@ 레미 나는 마침내 그것을 만들었다. 이제 또 다른 문제가 생겼습니다. 내가 arduino (시리얼 통신)에서 일부 수치를 얻은 후 while 루프에서'SetMonitorBrightness()'를 사용합니다. 몇 분 동안 작동하지만'SetMonitorBrightness()'가 15999를 넘는 오류 코드'3223725453'로 실패하고 그 의미를 찾을 수 없습니다. – DimChtz