Set Window Size to Maximized

A very simple question, but I’ve not been able to find an answer for it. How would I go about making the window size to be maximized, not full screen, but just maximized, when the application starts?
I’ve already come across this:

loadPrcFileData("", "fullscreen 0") # Set to 1 for fullscreen
loadPrcFileData("", "win-size 800 600")
loadPrcFileData("", "win-origin 10 10")
loadPrcFileData("", "win-fixed-size 0")

But I’ve not seen anything mentioning how to set the window to “maximized” mode when the application starts. Any help will be appreciated, thanks.

This is not yet supported in the public releases, but is a feature in the current development version and will be in 1.11 (with thanks to @wolf).

1 Like

Okay, in the meantime, immediately the main-menu of my application is invoked, I resize the window this way:

        xSize=base.pipe.getDisplayWidth()
        ySize=base.pipe.getDisplayHeight()
        props = WindowProperties()
        props.setSize(xSize,ySize)
        props.setFixedSize(1)
        base.win.requestProperties(props)

This does something similar to what I wanted, with the exception that the client-side decorations vanish. I’d have to adjust the height of the window to make them visible again. Of the height of the window, how much is taken by client-side decorations? Is there a way to get this value, so that:

        xSize=base.pipe.getDisplayWidth()
        properYSize=base.pipe.getDisplayHeight()-clientSideDecorationHeight
        props = WindowProperties()
        props.setSize(xSize,properYSize)
        props.setFixedSize(1)
        base.win.requestProperties(props)

Would basically yield the same effect as maximizing the window?

The dimensions of the Panda window are always of the “client area” of the window, ie. the region that is actually being rendered into.

There is no current way to get the size of the window decorations, except by directly interfacing with the Win32 API.

Alright, I suppose I will have to settle for this for now and use “sys.exit()” and “props.setMinimized(True)” to simulate exiting and minimizing the window from within the application, if there’s not much that can be done about the window decorations.

Thanks.

This can easily be hacked.

pip install pywin32

from direct.showbase.ShowBase import ShowBase
import win32gui, win32con

class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        self.accept("space", self.fullmode)

    def fullmode(self):
        hwnd = win32gui.FindWindow(None, 'Panda')
        win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)

game = Game()
game.run()

press space!

The only thing I don’t understand is how you can do this during initialization.

A more reliable way to get the hwnd from the Panda window is via base.win.window_handle.

I think you may need to wait until you get a window-event indicating that the window is open.

It doesn’t work.

TypeError: The object is not a PyHANDLE object

Regarding the event, I am not aware of it. As far as I know it can be tracked by task.

The reason I wanted a panda3d-solution as opposed to other solutions is because panda3d’s solution would end up supporting windows, ubuntu and macOs.

Is this hack cross-platform, or would it only work on windows? If it’s only compatible with windows, what can be done to make it cross-platform, if anything?

I don’t think it’s cross-platform, but there are similar solutions for other platforms. I’m not exactly sure, but the linux alternative is xlib.

Ok, thanks anyways, I’ll just stick to other solution for the time being.