C++/WinAPI

SetDeviceGammaRamp is not working

Dongmin Jang 2021. 1. 26. 16:06

GDI(Graphics Device Interface)를 이용해 디스플레이의 밝기값을 조절하는 작업을 gdi32.dll의 SetDeviceGammaRamp 함수를 사용하였지만 단일 모니터에서는 동작하지만 다중 모니터에서는 동작하지않는 문제가 발생.

 

Window Update 1903 버전부터 해당 동작이 원할하지않다라는 추측을 하게되었고 해당 issues가 최근 제기되는 것을 확인하였다. 아래는 제기된 해당 이슈들.

- hub.displaycal.net/forums/topic/windows-10-1903-please-read/

- github.com/Tyrrrz/LightBulb/issues/100

- zandronum.com/tracker/print_bug_page.php?bug_id=3770

 

사용했던 코드는 다음(https://github.com/UAASoftware/GammaRamp) 코드와 유사하여 문제가 발생하였고

다중 디스플레이 환경에서 GetDC()를 하게되면 전체 디스플레이에 대한 Device Context를 가져오는 것으로 생각,

특정 디스플레이에 대한 Device Context만 가져올 수 있도록 해당 부분을 수정하였다.

 

HDC hScreenDC = NULL;
HDC hGammaDC = hDC;

if (hDC == NULL)
{
  hScreenDC = CreateDC(_T("\\\\.\\Display1"), NULL, NULL, NULL);
  hGammaDC = CreateCompatibleDC(hScreenDC);
}

 ...

if (hDC == NULL)
{
  DeleteDC(hGammaDC);
} 

 

 

 

추측하기로는 윈도우 업데이트하면서 WDDM API와 gdi32.dll 사이에 수정이 있지않았을까

Window Display Device Model(WDDM) Architecture(source: https://docs.microsoft.com/ko-kr/windows-hardware/drivers/display/windows-vista-and-later-display-driver-model-architecture)