앱 활성화 방법(DirectX 및 C++)
이 토픽에서는 UWP(유니버설 Windows 플랫폼) DirectX 앱에 대한 활성화 환경 정의 방법을 보여 줍니다.
앱 활성화 이벤트 처리기 등록
먼저 앱이 시작되고 운영 체제에서 초기화될 때 발생하는 CoreApplicationView::Activated 이벤트를 처리하도록 등록합니다.
이 코드를 뷰 공급자의 IFrameworkView::Initialize 메서드 구현에 추가합니다(예제에서는 MyViewProvider라는 이름).
void App::Initialize(CoreApplicationView^ applicationView)
{
// Register event handlers for the app lifecycle. This example includes Activated, so that we
// can make the CoreWindow active and start rendering on the window.
applicationView->Activated +=
ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &App::OnActivated);
//...
}
앱에 대한 CoreWindow 인스턴스 활성화
앱이 시작되면 앱의 CoreWindow에 대한 참조를 가져와야 합니다. CoreWindow에는 앱이 창 이벤트를 처리하는 데 사용하는 창 이벤트 메시지 디스패처가 포함되어 있습니다. CoreWindow::GetForCurrentThread를 호출하여 앱 활성화 이벤트에 대한 콜백에서 이 참조를 가져옵니다. 이 참조를 얻은 후에는 CoreWindow::Activate를 호출하여 기본 앱 창을 활성화합니다.
void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
{
// Run() won't start until the CoreWindow is activated.
CoreWindow::GetForCurrentThread()->Activate();
}
기본 앱 창에 대한 이벤트 메시지 처리 시작
이벤트 메시지로 발생하는 콜백은 앱의 CoreWindow에 대해 CoreDispatcher에서 처리됩니다. 앱의 기본 루프(보기 공급자의 IFrameworkView::Run 메서드에서 구현됨)에서 CoreDispatcher::ProcessEvents를 호출하지 않으면 이 콜백이 호출되지 않습니다.
// This method is called after the window becomes active.
void App::Run()
{
while (!m_windowClosed)
{
if (m_windowVisible)
{
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
m_main->Update();
if (m_main->Render())
{
m_deviceResources->Present();
}
}
else
{
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
}
}
}
관련 항목