***************************************************************** * Neveprise Inc. Delphi FAQ * ***************************************************************** * Section: DirectX Topic: Enum video modes * * Created: July 27th, 1999 Revised: July 27th, 1999 * * Updates: www.neveprise.de Info: support@neveprise.de * ***************************************************************** Q: How can I enumerate all available video modes? How to declare the callback? A: Finding an enumeration function in DirectX is not hard, but the problem is how to declare the required callback function and what the lpContext param can be used for. What we do is to write one single function that retrieves all needed information as TStrings. This function contains the call to EnumDisplayModes() and in the var part our callback. The advantage of using TStrings as result is, that we have readable (for the user) and internal DirectX values in one object without declaring complex custom types. Perhaps you know that a string in TStrings can have an additional pointer to TObject (using AddObject() etc.) we can combine both information. //a "pseudo-record" as TObject, it contains information that is needed //later when we want to set a mode TDisplayMode_SD = class (TObject) Width: cardinal; Height: cardinal; BitDepth: cardinal; end; //the function to call from your app, Modes will contain a list with all //modes, Driver can be nil (default device, *not* recommended) or a valid //GUID. How to get it, please look up "enumerating display/ graphic modes" //in this FAQ. function EnumDisplayModes_SD(Driver: PGUID; var Modes: TStringList): boolean; var DD: IDirectDraw; //temporary DirectDraw object, needed to query DD2 DD2: IDirectDraw2; //temporary DirectDraw2 object //callback function that fills the list function Enum_CallBack(const Desc: TDDSurfaceDesc; Context: Pointer): HResult; stdcall; var DisMod: TDisplayMode_SD; //"record" holding the data begin DisMod:=TDisplayMode_SD.Create; with DisMod do begin Width:= Desc.dwWidth; //fill with values Height:= Desc.dwHeight; BitDepth:= Desc.ddpfPixelFormat.dwRGBBitCount; // ..and assign to stringlist as TObject TStringList(Context).AddObject(IntToStr(Width)+' x '+ IntToStr(Height)+' Pixels x '+ IntToStr(BitDepth)+' bit color', DisMod); end; Result:=DDEnumRet_OK; //continue enumeration end; begin Result:=false; DXStat:='Create DirectDraw'; //create temp. DDraw1 if DXCHeck(DirectDrawCreate(nil,DD,nil))=false then Exit; DXStat:='Query DirectDraw2'; //create temp. DDraw2 by Querying if DXCheck(DD.QueryInterface(IID_IDirectDraw2, DD2))=false then Exit; DXStat:='EnumDisplayModes'; //start enumeration if DXCheck(DD2.EnumDisplayModes(0, nil, Modes, @Enum_CallBack))=false then Exit; ReleaseCOM(DD2); ReleaseCOM(DD); Result:=true; end; //now you have TStrings, use it this way: //this fills a combobox (cbVideoModes) with all device modes slModes:=TStringList.Create; if EnumDisplayModes_SD(slModes)=true then cbVideoModes.Items:=slModes; //if an item is selected, we can retrieve the modes this way to pass'em //to DirectDrawCreate etc. var ModeDD: TDisplayMode_SD; TObject(ModeDD):=slModes.Objects[cbVideoModes.ItemIndex]; Blazko