Windowed Mode

Top  Previous  Next

The 2D command set supports a windowed mode DirectX screen by using the ATTACHSCREEN function.  Attaching a screen to a regular Emergence BASIC window allows running a 2D program on the desktop without taking up full control of the screen.

When opening the window to be used as the base of the screen you should always specify @NOAUTODRAW as one of the style flags in the OPENWINDOWstatement. This prevents the EBASIC window from trying to overwrite the attached screen
 

DEF win as WINDOW
width = 640:heigt = 480
OPENWINDOW win,0,0,width,height,@NOAUTODRAW|@SIZE,0,"Windowed 2D screen",&myhandler
IF(ATTACHSCREEN(win,width,height,TRUE) < 0)
    MESSAGEBOX win,"Couldn't create DirectX window","Error"
    CLOSEWINDOW win
    END
ENDIF

The optional bStretch parameter of the ATTACHSCREEN function specifies how the 2D system should handle copying the back buffer to the windowed screen. If TRUE it will stretch to fit the screen allowing the window to be resized and the screen will be automatically scaled to fit the client area of the window. If FALSE then the screen is copied as sized. If your not using the stretch to fit feature then use the EBASIC GETCLIENTSIZE command to determine the exact dimensions of the screen to use.

The attached screen will have the same bpp as the users Windows screen. The FLIP command has to do a bit copy from the back buffer to the window instead of a hardware flip. Because of this a windowed 2D program will be slower than an identical full screen version.

Closing the screen

You must close the screen with the CLOSESCREEN command before using CLOSEWINDOW. Failing to do so will result in strange behavior such as the program sticking in memory or an access violation.
 

WAITUNTIL run=0
CLOSESCREEN
CLOSEWINDOW win
END

Notes

Only one windowed screen at a time is allowed to be attached.

A complete windowed 2D example can be seen in the dx_windowed.eba sample