PDA

View Full Version : Switching windowed->fullscreen->windowed



Sly
08-01-2005, 06:38 AM
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?

TheLion
08-01-2005, 09:29 AM
Only reason I might think of is that you change the look of the window (like taking out borders and adding a caption etc) after changing the clientwidth/clientheight, since the title bar could be around 22 pixels or so...

What you could try is to resize the window values using the width, height properties and then adjusting the width/height to get the correct client size using the windows API function AdjustWindowRectEx... like about so:

var WindowRect : TRect;

WindowRect.left := 0; // Set Left Value To 0
WindowRect.top := 0; // Set Top Value To 0
WindowRect.right := Width; // Set Right Value To Requested Width
WindowRect.bottom := Height; // Set Bottom Value To Requested Height

AdjustWindowRectEx(WindowRect, WS_OVERLAPPEDWINDOW, False, WS_EX_APPWINDOW OR WS_EX_WINDOWEDGE);

and then setting the forms width/height:

Form1.Width := ( WindowRect.right - WindowRect.left );
Form1.Height := ( WindowRect.bottom - WindowRect.top );

You do have to change the windowstates in the code above though, however if you are not sure which ones Delphi is using for your window, just use Spy++ it will tell you! ;)

I always write my own window code for games lately, just because it's easier keeping control of, since you setup everything by hand! :)

Clootie
09-01-2005, 01:55 PM
When developing mine code to integrate Delphi VCL and DirectX windowed / fullscreen application I've found it's just close to impossible to use default (not subclassed) forms. So, after that mine current solution is to create new window (plain Win32 API CreateWindow) for fullscreen mode and locate iv above Delphi VCL app. And revert to rendering to VCL form in windowed mode.

PS. IIRC most pain in the a...s was handling Alt-TAB, Ctrl-Alt-Del, etc. events and restore VCL state correcly in these situations. - so double test these!

Sly
09-01-2005, 10:20 PM
I've given up trying to find a solution to this problem at the moment. TheLion, your idea didn't work either.

I'll be switching from VCL to plain Win32 eventually. Using VCL while developing.

Clootie
10-01-2005, 11:06 AM
Sly, you can try to look at Templates and VCLfullscreenD3D at: some D3D samples (http://clootie.narod.ru/delphi/download_custom.html#D3Dex_Templates).
These samples are build based on: Summer 2003 DX9 SDK for Delphi (http://clootie.narod.ru/delphi/download_dx90.html)