home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / display / savedc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.1 KB  |  90 lines

  1. /*
  2.  *  SaveDC
  3.  *  savedc.c,
  4.  *
  5.  *  This program demonstrates the use of the function SaveDC.
  6.  *  It saves the current state of the display context by copying state 
  7.  *  information to a context stack. The saved display context can later
  8.  *  be restored by using the RestoreDC function.
  9.  *
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. /* Procedure called when the application is loaded for the first time */
  15. BOOL WinInit( hInstance )
  16. HANDLE hInstance;
  17. {
  18.     WNDCLASS   wcClass;
  19.  
  20.     /* registering the parent window class */
  21.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  22.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  23.     wcClass.lpszMenuName   = (LPSTR)NULL;
  24.     wcClass.lpszClassName  = (LPSTR)"Savedc";
  25.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  26.     wcClass.hInstance      = hInstance;
  27.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  28.     wcClass.lpfnWndProc    = DefWindowProc;
  29.     wcClass.cbClsExtra     = 0;
  30.     wcClass.cbWndExtra     = 0;
  31.  
  32.     RegisterClass( (LPWNDCLASS)&wcClass );
  33.     return TRUE;        /* Initialization succeeded */
  34. }
  35.  
  36. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  37. HANDLE hInstance, hPrevInstance;
  38. LPSTR lpszCmdLine;
  39. int cmdShow;
  40. {
  41.     HWND   hWnd;                /* Handle to the parent window    */
  42.     HDC    hDC;                 /* Display context of client area */
  43.     HBRUSH hNewBrush, hOldBrush;/* Handle to the brushes          */
  44.     short  nDCIdentity;         /* identifier to the saved DC     */
  45.  
  46.     WinInit (hInstance);
  47.  
  48.     hWnd = CreateWindow((LPSTR)"Savedc",
  49.                         (LPSTR)"Saving Display Context",
  50.                         WS_OVERLAPPEDWINDOW,
  51.                         50,                /* x         */
  52.                         50,                /* y         */
  53.                         600,               /* width     */
  54.                         250,               /* height    */
  55.                         (HWND)NULL,        /* no parent */
  56.                         (HMENU)NULL,       /* use class menu */
  57.                         (HANDLE)hInstance, /* handle to window instance */
  58.                         (LPSTR)NULL        /* no params to pass on */
  59.                        );
  60.  
  61.     /* Make window visible according to the way the app is activated */
  62.     ShowWindow( hWnd, cmdShow );
  63.     UpdateWindow( hWnd );
  64.  
  65.     /* Get the DC of the client area */
  66.     hDC = GetDC (hWnd);
  67.  
  68.     /* Create a new brush and change the DC */
  69.     hNewBrush = CreateSolidBrush (GetSysColor (COLOR_WINDOW));
  70.     hOldBrush = (HBRUSH) SelectObject (hDC, (HANDLE) hNewBrush);
  71.  
  72.     /* Save the DC and get an unique identity of the saved DC */
  73.     nDCIdentity = SaveDC (hDC);
  74.  
  75.     /* Release the DC */
  76.     ReleaseDC (hWnd, hDC);
  77.     
  78.     /* return code for SaveDC routine. It is 0 if the DC is not saved */
  79.     if (nDCIdentity)
  80.       {  MessageBox (hWnd, (LPSTR)"The DC is saved",
  81.                      (LPSTR)"Done", MB_OK);
  82.       }
  83.     else 
  84.       {  MessageBox (hWnd, (LPSTR)"The DC is not saved",
  85.                      (LPSTR)NULL, MB_OK);
  86.       }
  87.  
  88.     return 0;
  89. }
  90.