Win32: How to determine if DirectDraw is enabled?
When using CachedBitmaps
in GDIPlus, there is graphical corruption if Windows video "Hardware Acceleration" is lowered too much - such that DirectDraw is disabled:
There are six levels of hardware acceleration:
- Disable all accelerations
- Disable all but basic accelerations. (Default on server machines)
- Disable all DirectDraw and Direct3D accelerations, as well as all cursor and advanced accelerations
- Disable all cursor and advanced drawing accelerations
- Disable cursor and bitmap accelerations
- All accelerations are enabled (Default on desktop machines)
If DirectDraw is disabled, then using DrawCachedBitmap
in GD开发者_如何学CI+ will result in graphical corruption. It's easy enough for me to use the slower DrawImage()
API if DirectDraw is not enabled - but i have to be able to detect that DirectDraw is disabled.
How can i programatically check if DirectDraw is enabled?
The question is: How does dxdiag do this:
See also
KB191660 - DirectDraw or Direct3D option is unavailable (archive)
If you download the latest DirectX SDK (I'm sure older sdk's have similar examples) there is an example of querying DXDIAG info.
The example is located at (SDK Root)\Samples\C++\Misc\DxDiagReport
In dxdiaginfo.cpp methods of note
CDxDiagInfo::CDxDiagInfo
CDxDiagInfo::Init
CDxDiagInfo::QueryDxDiagViaDll
CDxDiagInfo::GetDisplayInfo
If you run the program it ouputs a giant list of values. I think the value you're interested in is pDisplayInfo->m_szDDStatusEnglish
You could check the registry for the acceleration slider value.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Video\{'some hex string'}\0000\Acceleration.Level
You're probably going to have to loop through all the folders in Video
as there are generally more than one entry.
Acceleration.Level Values
- 5 Disable all accelerations
- 4 Disable all but basic accelerations. (Default on server machines)
- 3 Disable all DirectDraw and Direct3D accelerations, as well as all cursor and advanced accelerations
- 2 Disable all cursor and advanced drawing accelerations
- 1 Disable cursor and bitmap accelerations
- 0 All accelerations are enabled (Default on desktop machines)
Update:
Here's an older thread about programatically changing/checking the acceleration level. http://www.autoitscript.com/forum/topic/61185-hardware-acceleration/
You could query a IDirectDraw interface and see what it does. I assume it will fail if hardware acceleration is turned off, but you might want to test GetCaps() or TestCooperativeLevel().
LPDIRECTDRAW lpdd7 = NULL; // DirectDraw 7.0
// first initialize COM, this will load the COM libraries
// if they aren't already loaded
if (FAILED(CoInitialize(NULL)))
{
// error
} // end if
// Create the DirectDraw object by using the
// CoCreateInstance() function
if (FAILED(CoCreateInstance(&CLSID_DirectDraw,
NULL, CLSCTX_ALL,
&IID_IDirectDraw7,
&lpdd7)))
{
// error
}
// now before using the DirectDraw object, it must
// be initialized using the initialize method
if (FAILED(IDirectDraw7_Initialize(lpdd7, NULL)))
{
// error
}
lpdd7->Release();
lpdd7 = NULL; // set to NULL for safety
// now that we're done with COM, uninitialize it
CoUninitialize();
Unfortunately the DirectDraw docs are no longer included in the SDKs. You might need an older version to get the samples and header files.
精彩评论