Alexander S.
Alexander S.

Reputation: 158

Use HWND to toggle application fullscreen

So I am trying to move another application to a second screen and then I want to set it full screen in C++.

I have the HWND handle from the application from a list of processes and then I can set the position from the window where I want with MoveWindow. This works perfectly.

Is there a similar way to set the application to full screen? I can only seem to find info about setting your own application to full screen. But in this case I want to be able to move any application I want and set it to full screen. (As far as this is possible, but for the purpose I need it it should be)

If I press Alt+Enter on the window after moving it, it does exactly what I want. So I hope I can do that from code?

EDIT: BTW I tried ShowWindow(windowToMove, SHOW_FULLSCREEN); But it seems to maximize it but it is not similar to ALT+ENTER.

Thanks for any help in advance!

Upvotes: 1

Views: 5121

Answers (1)

NORM_4EL
NORM_4EL

Reputation: 145

BOOL IsWindowMode = TRUE;
WINDOWPLACEMENT wpc;
LONG HWNDStyle = 0;
LONG HWNDStyleEx = 0;

void FullScreenSwitch( )
{
    if ( IsWindowMode )
    {
        IsWindowMode = FALSE;
        GetWindowPlacement( HWNDWindow, &wpc );
        if ( HWNDStyle == 0 )
            HWNDStyle = GetWindowLong( HWNDWindow, GWL_STYLE );
        if ( HWNDStyleEx == 0 )
            HWNDStyleEx = GetWindowLong( HWNDWindow, GWL_EXSTYLE );

        LONG NewHWNDStyle = HWNDStyle;
        NewHWNDStyle &= ~WS_BORDER;
        NewHWNDStyle &= ~WS_DLGFRAME;
        NewHWNDStyle &= ~WS_THICKFRAME;

        LONG NewHWNDStyleEx =HWNDStyleEx;
        NewHWNDStyleEx &= ~WS_EX_WINDOWEDGE;

        SetWindowLong( HWNDWindow, GWL_STYLE, NewHWNDStyle | WS_POPUP );
        SetWindowLong( HWNDWindow, GWL_EXSTYLE, NewHWNDStyleEx | WS_EX_TOPMOST );
        ShowWindow( HWNDWindow, SW_SHOWMAXIMIZED );
    }
    else
    {
        IsWindowMode = TRUE;
        SetWindowLong( HWNDWindow, GWL_STYLE, HWNDStyle );
        SetWindowLong( HWNDWindow, GWL_EXSTYLE, HWNDStyleEx );
        ShowWindow( HWNDWindow, SW_SHOWNORMAL );
        SetWindowPlacement( HWNDWindow, &wpc );
    }
}

This code switch windowed window to fullscreen and back. (WINAPI, and need start target process in window mode)

Upvotes: 3

Related Questions