|Microsoft DirectX 9.0|
The IDirect3DDevice9 interface provides IDirect3DDevice9::BeginStateBlock to record device states in a state block as your application calls for them. This method causes the system to start recording device state changes in a state block, rather than applying them to the device. A list of the states that can be recorded is in IDirect3DDevice9::BeginStateBlock.
When you're done recording the state block, notify the system to stop recording by calling the IDirect3DDevice9::EndStateBlock method. This method places the handle of the state block in the variable whose address you pass in the pToken parameter. Your application uses this handle to apply the state block to the device as needed, to capture new state data into the block, and to delete the state block when it is no longer required.
It is important to check the error code from the IDirect3DDevice9::EndStateBlock method. If the method fails, it is likely because the display mode has changed. Design your application to recover from this type of failure by recreating its surfaces and recording the state block again.