I am creating a Direct3D 9 application (not using any third-party libraries) that allows the user to switch between windowed and fullscreen and back again. When the application starts in windowed mode, it sets ClientWidth and ClientHeight to 640 and 480 respectively. This works fine.

When switching to fullscreen mode, it sets the screen resolution to 640x480, sets the form's BorderStyle to bsNone and sets the ClientWidth and ClientHeight to 640x480. Again, this works fine.

When switching back to windowed mode, it restores the screen resolution, restores the previous BorderStyle value and sets the ClientWidth and ClientHeight to 640 and 480. Not so fine this time. The ClientHeight gets set to 458 and the bottom 22 pixels of my 3D display are chopped off.

BorderStyle := bsSizeable;
ClientWidth := 640;
ClientHeight := 480;
Caption := Format('%dx%d', [ClientWidth, ClientHeight]);

This will set the form's Caption to '640x458'. Any ideas why?