I'm having a very strange problem switching from full-screen mode back to windowed mode. At the time the Direct3D9 device is reset, the window is 20 pixels shorter than it should be. Here is some debug output showing the problem (WSize is the window size, CSize is the window client size):
Code:
Debug Output: Starting in windowed mode
Debug Output: WSize:806x632  CSize:800x600
Debug Output: Going to fullscreen mode
Debug Output: WSize:800x600  CSize:800x600
Debug Output: Going to windowed mode
Debug Output: WSize:806x612  CSize:800x580
Here is the code that changes the window properties.
[pascal]procedure TfrmMain.DeviceReset(Sender: TObject);
begin
gSystem.Fonts.InvalidateDeviceObjects;

if gSystem.Device.Windowed then
begin
DKLog('Going to windowed mode');
{ Going to a windowed mode }
{ Restore the previous border style and position }
BorderStyle := FWindowedBorderStyle;
Left := FWindowedLeft;
Top := FWindowedTop;
end
else
begin
DKLog('Going to fullscreen mode');
{ Going from windowed to full-screen }
{ Save the border style and position of the window }
FWindowedBorderStyle := BorderStyle;
FWindowedLeft := Left;
FWindowedTop := Top;

{ Borderless window at 0,0 }
BorderStyle := bsNone;
Left := 0;
Top := 0;
end;
ClientWidth := gSystem.Device.Width;
ClientHeight := gSystem.Device.Height;

gSystem.Device.WindowHandle := Handle;
end;[/pascal]
I call that code, fill the D3DPRESENTPARAMETERS structure and call Reset on the Direct3D device. The debug output above is logged just before the call to Reset.

Why would the window be 20 pixels shorter than it was before?

Edit: Why don't the pascal tags understand the original Pascal style comments?