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

  1. /*
  2.  *
  3.  *  SetStretchBltMode
  4.  *  setblt
  5.  *
  6.  *  SetStretchBltMode sets the stretching mode for the StretchBlt function.
  7.  *  The stretching mode defines which scan lines and/or columns
  8.  *  StretchBlt eliminates when contracting a bitmap.
  9.  *
  10.  *  This program demonstrates the use of the function SetStretchBltMode.
  11.  *  The stretch mode is set in one statement.  The SetStretchBltMode function
  12.  *  is passed two parameters: a handle to a display context,(ie. hDC) and a
  13.  *  new stretching mode (ie. WHITEONBLACK, BLACKONWHITE, or COLORONCOLOR).
  14.  *  SetStretchBltMode returns the previous stretching mode.
  15.  *
  16.  */
  17.  
  18. #include "windows.h"
  19.  
  20. /* Procedure called when the application is loaded for the first time */
  21. BOOL WinInit( hInstance )
  22. HANDLE hInstance;
  23. {
  24.     PWNDCLASS   pClass;
  25.  
  26.     pClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  27.  
  28.     /* registering the parent window class */
  29.     pClass->hCursor        = LoadCursor( NULL, IDC_ARROW );
  30.     pClass->lpszMenuName   = (LPSTR)NULL;
  31.     pClass->lpszClassName  = (LPSTR)"Window";
  32.     pClass->hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  33.     pClass->hInstance      = hInstance;
  34.     pClass->style          = CS_HREDRAW | CS_VREDRAW;
  35.     pClass->lpfnWndProc    = DefWindowProc;
  36.  
  37.     if (!RegisterClass( (LPWNDCLASS)pClass ) )
  38.         /* Initialization failed.
  39.          * Windows will automatically deallocate all allocated memory.
  40.          */
  41.         return FALSE;
  42.  
  43.     LocalFree( (HANDLE) pClass );
  44.     return TRUE;        /* Initialization succeeded */
  45. }
  46.  
  47.  
  48. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  49. HANDLE hInstance, hPrevInstance;
  50. LPSTR lpszCmdLine;
  51. int cmdShow;
  52. {
  53.     HWND  hWnd;             /* Handle to the parent window    */
  54.     short nOldStretchMode;  /* Return value for the SetStretchBltMode Routine */
  55.     HDC   hDC;              /* display context of client area */
  56.  
  57.     WinInit (hInstance);
  58.  
  59.     hWnd = CreateWindow((LPSTR)"Window",
  60.                         (LPSTR)"SetStretchBltMode",
  61.                         WS_TILEDWINDOW,
  62.                         20,20,400,200,
  63.                         (HWND)NULL,        /* no parent */
  64.                         (HMENU)NULL,       /* use class menu */
  65.                         (HANDLE)hInstance, /* handle to window instance */
  66.                         (LPSTR)NULL        /* no params to pass on */
  67.                        );
  68.  
  69.     /* Make window visible according to the way the app is activated */
  70.     ShowWindow( hWnd, cmdShow );
  71.     UpdateWindow(
  72.     hWnd );
  73.     /**************************************************************************/
  74.     hDC = GetDC (hWnd);            /* Get a handle to the Display Context */
  75.  
  76.     /* Set the stretching mode for the StretchBlt function and return the
  77.      * previous stretching mode in a (short) variable. */
  78.     nOldStretchMode = SetStretchBltMode ( hDC, WHITEONBLACK);
  79.  
  80.     ReleaseDC (hWnd, hDC);          /* Release handle to Display Context */
  81.     /*************************************************************************/
  82.     
  83.     /* return codes for SetStretchBltMode routine */
  84.     if (nOldStretchMode == WHITEONBLACK)
  85.       {  MessageBox (hWnd, (LPSTR)"The stretching mode is set. The previous mode was WHITONBLACK",
  86.              (LPSTR)"Done", MB_OK);
  87.       }
  88.     else if (nOldStretchMode == BLACKONWHITE)
  89.        {  MessageBox (hWnd, (LPSTR)"The stretching mode is changed. The previous mode was BLACKONWHITE",
  90.               (LPSTR)"Done", MB_OK);
  91.        }
  92.     else if (nOldStretchMode == COLORONCOLOR)
  93.       {   MessageBox (hWnd, (LPSTR)"The stretching mode is changed. The previous mode was COLORONCOLOR",
  94.               (LPSTR)"Done", MB_OK);
  95.       }
  96.     return 0;
  97. }
  98.