int SaveDC(hdc) | |||||
HDC hdc; | /* handle of device context | */ |
The SaveDC function saves the current state of the given device context by copying state information (such as clipping region, selected objects, and mapping mode) to a context stack. The saved device context can later be restored by using the RestoreDC function.
hdc
Identifies the device context to be saved.
The return value is an integer identifying the saved device context if the function is successful. This integer can be used to restore the device context by calling the RestoreDC function. The return value is zero if an error occurs.
The SaveDC function can be used any number of times to save any number of device-context states.
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);