IDisplayInformationStaticsInterop::GetForWindow 메서드(windows.graphics.display.interop.h)
지정된 창에 대한 DisplayInformation 개체를 검색합니다. GetForWindow 는 항상 새 DisplayInformation을 할당하고 반환합니다.
구문
HRESULT GetForWindow(
HWND window,
REFIID riid,
void **displayInfo
);
매개 변수
window
형식: [in] HWND
창의 핸들입니다.
riid
형식: [in] REFIID
DisplayInformation 클래스의 GUID입니다.
displayInfo
형식: [iid_is][retval][out] void**
반환된 DisplayInformation 개체에 대한 포인터를 수신하는 메모리 블록에 대한 포인터입니다.
반환 값
형식: HRESULT
함수가 성공하면 S_OK를 반환합니다. 그렇지 않으면 HRESULT오류 코드를 반환합니다.
설명
DisplayInformation은 창 이동 및 DPI 변경 메시지를 처리할 수 있도록 HWND의 메시지 루프를 연결합니다. 이 작업이 원활하게 수행되도록 하기 위해 GetForWindow 에는 다음과 같은 요구 사항이 있습니다.
- 창의 인수는 현재 스레드가 소유한 최상위 창의 HWND여야 합니다.
- 이벤트를 수신하려면 현재 스레드에 Windows.System.DispatcherQueue 가 실행 중이어야 합니다.
- 현재 스레드는 MTA 또는 STA일 수 있습니다.
창의 인수가 관련된 한 생성된 DisplayInformation을 캐싱해야 합니다. 등록 해제 이벤트 처리기; DisplayInformation instance 삭제하기 위해 마지막 참조를 삭제합니다.
예제
와이드 컬러 영역 및 고가동 범위 콘텐츠를 렌더링하는 앱이 모니터의 변화하는 조건에 동적으로 조정하는 것이 중요합니다. 또는 모니터 간에 이동할 때 노트북에서 사용자는 화면의 밝기를 조정할 수 있으며 앱에 제공된 톤 매핑 매개 변수를 조정할 수 있습니다.
// It's safe, and recommended, to cache the DisplayInformation created from an HWND,
// since it safely provides the latest information and event handlers for when
// changes take place.
#include <Windows.Graphics.Display.Interop.h>
#include <winrt/Windows.Graphics.Display.h>
using namespace winrt::Windows::Graphics::Display;
...
void ReadHdrParametersFromDisplayInformation(HWND myWindow)
{
auto factory{ winrt::get_activation_factory<DisplayInformation,
IDisplayInformationStaticsInterop>() };
DisplayInformation displayInfo{ nullptr };
winrt::check_hresult(
factory->GetForWindow(
myWindow,
winrt::guid_of<DisplayInformation>(),
winrt::put_abi(displayInfo)
)
);
auto colorInfo{ displayInfo.GetAdvancedColorInfo() };
// Here you can read colorInfo properties such as:
// * CurrentAdvancedColorKind
// * RedPrimary, BluePrimary, GreenPrimary, WhitePoint
// * MinLuminanceInNits, MaxLuminanceInNits
// * MaxAverageFullFrameLuminanceInNits, SdrWhiteLevelInNits
// ... and adapt your rendering.
// You can also subscribe event handlers to listen for changes:
displayInfo.AdvancedColorInfoChanged(
[&](auto sender, auto args)
{
// Handle the event.
}
);
// Cache the DisplayInformation object for as long as your window
// is alive: it always provides fresh data for your window.
}
요구 사항
지원되는 최소 클라이언트 | Windows 11 빌드 22621 |
머리글 | windows.graphics.display.interop.h |
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기