Как спроектировать режим отображения с окна на полноэкранный режим без окон во время выполнения?

0

На данный момент мне нужно изменить режим отображения на полноэкранные без полей окна перед выполнением программы, чтобы получить желаемый результат. Я хочу изменить режим отображения из оконного окна в полноэкранное без полей, просто нажав Alt + Enter, когда программа запущена. Как я могу изменить код, чтобы он смог изменить режим отображения во время выполнения?

SystemClass.cpp

void SystemClass::InitializeWindows()
{
    WNDCLASSEX wc;
    DEVMODE dmScreenSettings;

    int screenWidth, screenHeight;
    int posX, posY;


    // Get an external pointer to this object
    ApplicationHandle = this;

    // Get the instance of this application
    m_hinstance = GetModuleHandle( NULL );

    // Give the application a name
    m_applicationName = "Zero DirectX Framework";

    // Setup the windows class with default settings
    wc.style            = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc.lpfnWndProc      = WndProc;
    wc.cbClsExtra       = 0;
    wc.cbWndExtra       = 0;
    wc.hInstance        = m_hinstance;
    wc.hIcon            = LoadIcon( NULL, IDI_WINLOGO );
    wc.hIconSm          = wc.hIcon;
    wc.hCursor          = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground    = (HBRUSH)GetStockObject( BLACK_BRUSH );
    wc.lpszMenuName     = NULL;
    wc.lpszClassName    = m_applicationName;
    wc.cbSize           = sizeof( WNDCLASSEX );

    // Register the window class
    RegisterClassEx( &wc );

    // Determine the resolution of the clients desktop screen
    screenWidth  = GetSystemMetrics( SM_CXSCREEN );
    screenHeight = GetSystemMetrics( SM_CYSCREEN );

    // Setup the screen settings depending on whether it is running in full screen or in windowed mode
    if ( FULL_SCREEN )
    {
        // If full screen set the screen to maximum size of the users desktop and 32bit
        memset( &dmScreenSettings, 0, sizeof(dmScreenSettings) );
        dmScreenSettings.dmSize         = sizeof(dmScreenSettings);
        dmScreenSettings.dmPelsWidth    = (unsigned long)screenWidth;
        dmScreenSettings.dmPelsHeight   = (unsigned long)screenHeight;
        dmScreenSettings.dmBitsPerPel   = 32;
        dmScreenSettings.dmFields       = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

        // Change the display settings to full screen
        ChangeDisplaySettings( &dmScreenSettings, CDS_FULLSCREEN );

        // Set the position of the window to the top left corner
        posX = posY = 0;

        // Create the window with the screen settings and get the handle to it
        m_hwnd = CreateWindowEx( WS_EX_APPWINDOW, m_applicationName, m_applicationName, 
        WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
        posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);

        SetMenu( m_hwnd, NULL );
    }
    else
    {
        // If windowed then set it to 800x600 resolution
        screenWidth  = 1280;
        screenHeight = 768;

        // Place the window in the middle of the screen
        posX = ( GetSystemMetrics( SM_CXSCREEN ) - screenWidth ) / 2;
        posY = ( GetSystemMetrics( SM_CYSCREEN ) - screenHeight) / 2;

        m_hwnd = CreateWindowEx( 0, m_applicationName, m_applicationName, WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, 
        posX, posY, screenWidth, screenHeight, 
        NULL, NULL, m_hinstance, NULL );
    }

    // Bring the window up on the screen and set it as main focus
    ShowWindow( m_hwnd, SW_SHOW );
    SetForegroundWindow( m_hwnd );
    SetFocus( m_hwnd );

    // Hide the mouse cursor
    ShowCursor(true);
} 
Теги:
winapi
directx
fullscreen
directx-9

1 ответ

0

Вы должны перезагрузить устройство при переходе с окна на полный экран и наоборот.
Некоторые примечания:

  • Вы должны освободить всю память из пула по умолчанию (то есть неуправляемого видеопамяти) до сброса и повторного использования после этого.
  • Я поддерживаю два разных текущих параметра для оконного и полного экрана, поскольку возможности могут отличаться.
  • Обратите внимание, что Reset и CreateDevice изменяют текущие параметры, которые вы использовали, например, задав размер заднего буфера в оконном режиме. Вы можете сделать копию своих исходных параметров для использования в последующих вызовах Reset.
  • Сброс в оконный режим не сохраняет исходный размер и положение окна; вы должны хранить их отдельно.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню