BOOL RestoreDC(hdc, nSavedDC) | |||||
HDC hdc; | /* handle of device context | */ | |||
int nSavedDC; | /* integer identifying device context to restore | */ |
The RestoreDC function restores the given device context to a previous state. The device context is restored by popping state information off a stack created by earlier calls to the SaveDC function.
hdc
Identifies the device context.
nSavedDC
Specifies the device context to be restored. This parameter can be a value returned by a previous SaveDC function. If the parameter is –1, the most recently saved device context is restored.
The return value is nonzero if the function is successful. Otherwise, it is zero.
The stack can contain the state information for several instances of the device context. If the context specified by the nSavedDC parameter is not at the top of the stack, RestoreDC deletes all state information between the instance specified by nSavedDC and the top of the stack.
The following example uses the GetMapMode function to retrieve the mapping mode for the current device context, uses the SaveDC function to save the state of the device context, changes the mapping mode, restores the previous state of the device context by using the RestoreDC function, and retrieves the mapping mode again. The final mapping mode is the same as the mapping mode prior to the call to the SaveDC function.
HDC hdcLocal;
int MapMode;
char *aModes[] = {"ZERO", "MM_TEXT", "MM_LOMETRIC", "MM_HIMETRIC",
"MM_LOENGLISH", "MM_HIENGLISH", "MM_TWIPS",
"MM_ISOTROPIC", "MM_ANISOTROPIC" };
hdcLocal = GetDC(hwnd);
MapMode = GetMapMode(hdcLocal);
TextOut(hdc, 100, 100, (LPSTR) aModes[MapMode],
lstrlen(aModes[MapMode]));
SaveDC(hdcLocal);
SetMapMode(hdcLocal, MM_LOENGLISH);
MapMode = GetMapMode(hdcLocal);
TextOut(hdc, 100, 120, (LPSTR) aModes[MapMode],
lstrlen(aModes[MapMode]));
RestoreDC(hdcLocal, -1);
MapMode = GetMapMode(hdcLocal);
TextOut(hdc, 100, 140, (LPSTR) aModes[MapMode],
lstrlen(aModes[MapMode]));
ReleaseDC(hwnd, hdcLocal);