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

  1. /*
  2.  
  3. Function(s) demonstrated in this program: GetStretchBltMode
  4. Description:   This function retrieves the current stretching mode.  The
  5.    stretching mode defines how information is to be added or removed from
  6.    bitmaps that are stretched or compressed by using the StretchBlt function.
  7.  
  8. Additional Comments:  Possible modes are BLACKONWHITE, WHITEONBLACK, 
  9.    and COLORONCOLOR with values 1, 2, and 3 respectively.
  10. */
  11.  
  12.  
  13. #include <windows.h>
  14. #include "GetBitSM.h"
  15. #include <string.h>
  16. #include <stdio.h>
  17.  
  18.        char        szAppName[] = "GetBitSM";
  19.        HANDLE        hInstMain;
  20.        HWND        hWndMain;
  21.        char        szOutputBuffer1[70];
  22.        char        szOutputBuffer2[500];
  23.        HBITMAP        hBitmapHelp;
  24.  
  25. struct { char *szMessage; }
  26.        Messages [] = { "Help Message",
  27.        "     Sample program to illustrate the use of GetStretchBltMode.\n\
  28.        Choose the option to see the current stretch mode." };
  29.  
  30.  
  31. void ProcessMessage (HWND, int); 
  32.  
  33. void ProcessMessage (hWnd, MessageNumber) 
  34.      HWND     hWnd;
  35.      int      MessageNumber;
  36.      {
  37.      sprintf (szOutputBuffer1, "%s", Messages [MessageNumber]);
  38.      sprintf (szOutputBuffer2, "%s", Messages [MessageNumber + 1]);
  39.      MessageBox (hWnd, szOutputBuffer2, szOutputBuffer1, MB_OK);
  40.      }
  41.  
  42. /****************************************************************************/
  43.  
  44. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  45.     HANDLE    hInstance, hPrevInstance;
  46.     LPSTR    lpszCmdLine;
  47.     int     nCmdShow;
  48.     {
  49.     HWND    hWnd;
  50.     MSG     msg;
  51.     WNDCLASS    wndclass;
  52.     HBITMAP    hBitmapCirc, hBitmapDiam, hBitmapSqua, hBitmapXs, hBitmapTria,
  53.         hBitmapPlus;
  54.     HMENU    hMenu;
  55.     short    xScreen, yScreen;
  56.  
  57.     if (!hPrevInstance)
  58.     {
  59.     wndclass.style        = CS_HREDRAW | CS_VREDRAW | CS_SAVEBITS;
  60.     wndclass.lpfnWndProc    = WndProc;
  61.     wndclass.cbClsExtra     = 0;
  62.     wndclass.cbWndExtra     = 0;
  63.     wndclass.hInstance      = hInstance;
  64.     wndclass.hIcon        = NULL;
  65.     wndclass.hCursor    = LoadCursor (NULL, IDC_ARROW) ;
  66.     wndclass.hbrBackground    = GetStockObject (WHITE_BRUSH);
  67.     wndclass.lpszMenuName    = szAppName;
  68.     wndclass.lpszClassName    = szAppName;
  69.  
  70.     if (!RegisterClass (&wndclass) )
  71.         return FALSE;
  72.     }
  73.  
  74.     xScreen = GetSystemMetrics (SM_CXSCREEN);
  75.     yScreen = GetSystemMetrics (SM_CYSCREEN);
  76.  
  77.     hWnd = CreateWindow (szAppName, "Help Window",
  78.        WS_OVERLAPPEDWINDOW, xScreen/7, yScreen/58,
  79.        xScreen*3/4, yScreen*49/50, NULL, NULL, hInstance, NULL);
  80.  
  81.     hInstMain = hInstance;
  82.     hWndMain  = hWnd;
  83.  
  84.     ShowWindow (hWnd, nCmdShow);
  85.     UpdateWindow (hWnd);
  86.  
  87.     while (GetMessage (&msg, NULL, 0, 0))
  88.         {
  89.         TranslateMessage (&msg);
  90.         DispatchMessage (&msg);
  91.         }
  92.  
  93.     DeleteObject (hBitmapHelp);
  94.     return msg.wParam;
  95.     }
  96. /****************************************************************************/
  97.  
  98. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  99.    HWND      hWnd;
  100.    unsigned  iMessage;
  101.    WORD      wParam;
  102.    LONG      lParam;
  103.    {
  104.    int           Index;
  105.    HANDLE        hDC;
  106.    HDC           hMemoryDC;
  107.    BITMAP        Bitmap;
  108.    short     foo;
  109.  
  110.    switch (iMessage)
  111.        {
  112.        case WM_SIZE:
  113.         hDC = GetDC(hWnd);
  114.             hMemoryDC = CreateCompatibleDC(hDC);
  115.             hBitmapHelp = LoadBitmap (hInstMain, "BitmapHelp");
  116.             GetObject(hBitmapHelp, 16, (LPSTR) &Bitmap);
  117.             SelectObject(hMemoryDC, hBitmapHelp);
  118.             foo = GetStretchBltMode (hDC);
  119.  
  120.             SetStretchBltMode(hDC, BLACKONWHITE);
  121.             StretchBlt(hDC, 0, 0, LOWORD (lParam), HIWORD (lParam),
  122.                 hMemoryDC, 0, 0, Bitmap.bmWidth, Bitmap.bmHeight, SRCCOPY);
  123.  
  124.             SetStretchBltMode(hDC, foo);
  125.         DeleteObject (hBitmapHelp);
  126.         DeleteDC(hMemoryDC);
  127.         ReleaseDC(hWnd, hDC);
  128.         break;
  129.  
  130.        case WM_COMMAND:
  131.             switch (wParam) {
  132.               case IDM_GETMODE:
  133.                    hDC = GetDC(hWnd);
  134.                    hMemoryDC = CreateCompatibleDC(hDC);
  135.                    hBitmapHelp = LoadBitmap (hInstMain, "BitmapHelp");
  136.                    GetObject(hBitmapHelp, 16, (LPSTR) &Bitmap);
  137.                    SelectObject(hMemoryDC, hBitmapHelp);
  138.                    foo = GetStretchBltMode (hDC);
  139.  
  140.                    sprintf (szOutputBuffer1, "Stretch Mode = %x, BLACKONWHITE",
  141.                             foo);
  142.                    MessageBox (hWnd, szOutputBuffer1, "GetStretchBltMode", 
  143.                                MB_OK);
  144.  
  145.                    SetStretchBltMode(hDC, BLACKONWHITE);
  146.                    StretchBlt(hDC, 0, 0, LOWORD (lParam), HIWORD (lParam),
  147.                    hMemoryDC, 0, 0, Bitmap.bmWidth, Bitmap.bmHeight, SRCCOPY);
  148.                    SetStretchBltMode(hDC, foo);
  149.                    DeleteObject (hBitmapHelp);
  150.                    DeleteDC(hMemoryDC);
  151.                    ReleaseDC(hWnd, hDC);
  152.                    break;
  153.  
  154.               case IDM_HELP:
  155.                    ProcessMessage (hWnd, 0);
  156.                    break;
  157.              }
  158.             break;
  159.  
  160.        case WM_DESTROY:
  161.             PostQuitMessage (0);
  162.             break;
  163.  
  164.        default:
  165.             return DefWindowProc( hWnd, iMessage, wParam, lParam );
  166.        }
  167.     return 0L;
  168. }
  169.  
  170. /****************************************************************************/
  171.  
  172. 
  173.