Question

I'm starting my DirectX 11.1 Metro (without XAML) application as following:

[Platform::MTAThread]
int main(Platform::Array<Platform::String^>^)
{
    // Some additional initializations
    //...

    auto frameworkViewSource = ref new MyFrameworkViewSource();
    Windows::ApplicationModel::Core::CoreApplication::Run(frameworkViewSource);
}

Run function is below:

virtual void Run()
    {
        while(!m_windowClosed)
        {
            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
            DoWork();
    }

}

Then I'm trying to call Quit function (in case user requested exit):

Quit()
{
    // Uninit variables
    //...
    Windows::ApplicationModel::Core::CoreApplication::Exit();
}

But

Windows::ApplicationModel::Core::CoreApplication::Exit();

has no effect. As a result I have crash in DoWork() function because variables were uninitialized but application wasn't exited and while loop is continuing.

Also, in case I call CoreWindow::GetForCurrentThread()->Close() from the Quit function, debugger never hits OnWindowClosed event handler:

m_window->Closed += ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &MyFrameworkView::OnWindowClosed);

void MyFrameworkView::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
{
    m_windowClosed = true;
}

The question is: how do I properly quit the game in case I'm planning to have "Quit" item in menu?

Was it helpful?

Solution

Short answer: you can't.

Long answer: The Windows Store app model doesn't permit apps to programmatically close, regardless of whether they use DirectX, XAML, or JavaScript. Instead, users must shut down using one of the standard gestures or actions (swipe down from top or ALT+F4). Apps can programmatically exit only by crashing. This page has more details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top