🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Change resolution and update window without flickering

Started by
3 comments, last by JohnnyCode 3 years, 5 months ago

Hi,

I have created a dll for hooking a game (becouse I don't have the source code) to solve a bug.

In short in this game the videos play in wrong resolutions.

To correct this bug I have inserted in the right place this code:

  bool SetDiplayResolution(int Width, int Height, int Refresh = 0)
    {
        LONG Outout;
    
        DEVMODE desiredMode;
        memset(&desiredMode, 0, sizeof(desiredMode));
        desiredMode.dmSize = sizeof(desiredMode);
    
        if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &desiredMode) != 0)
        {
            desiredMode.dmSize = sizeof(DEVMODE);
            desiredMode.dmPelsWidth = Width;
            desiredMode.dmPelsHeight = Height;
    
            if (Refresh > 0)
            {
                desiredMode.dmDisplayFrequency = Refresh;
                desiredMode.dmFields = DM_PELSHEIGHT | DM_PELSWIDTH | DM_DISPLAYFREQUENCY;
            }
            else
            {
                desiredMode.dmFields = DM_PELSHEIGHT | DM_PELSWIDTH;
            }
    
            Outout = ChangeDisplaySettings(&desiredMode, 0);
    
        }
    
        return Outout;
    }


void myfunction
{

    HWND hWnd = GetActiveWindow();

    SetDiplayResolution(1920, 1080);

    SetWindowPos(hWnd, 0, 0, 0, 1920, 1080, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
    UpdateWindow(hWnd);
}

This code work fine but unfortunatenly the transaction beetween the old and new resolution produce some very short, but visble annoyng effects:

  1. Temporary presence of the windows bar.
  2. The screen flash for one instant.

I have also tried to create a secondary “cover” window topmost without success.

I ask if there is a way to solve these problem using DirectDraw, OpenGL , or other way.

Thanks !

Advertisement

You have hooked update event function messsage. Why dont you just provide hwnd to creation of GPU device at point it happens. Present or swap will be in window provided, with v-sync enabled and further states of gpu.

Hi Jonny,

Thank you for your reponse ?

I forget to provide another information:

When I change the resolution from:

1280x960 to 1920x1080 (when the video start). I see these very short artifacts.

When I change the resolution from:

1920x1080 to 1280x960 (when the video finish). I don't see any artifacts.

I have tried to replace this line:

// SetWindowPos(hWnd, 0, 0, 0, 1920, 1080, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

with this:

SetWindowPos(hWnd, 0, 0, 0, 1920, 1080,0);

and the result is the some.

Can you please provide a sample code ? I don't have much experience about,

Thanks !

I'm not experienced with moding, but if you are able to recompile some part, study the entire part. You can alter defintion code quite securely, while not altering declarations.

This topic is closed to new replies.

Advertisement