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

  1. /*
  2.  *   InflateRect
  3.  *
  4.  *   This program demonstrates the use of the InflateRect function. The
  5.  *   InflateRect function increase or decreases the values in the given
  6.  *   LPRECT structure according to the x and y parameters in the function
  7.  *   call. To demonstrate the increase in size of the rectangle described
  8.  *   by lpRect in this application, after InflateRect was called, the
  9.  *   rectangle was inverted using InvertRect.
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. long    FAR PASCAL HelloWndProc(HWND, unsigned, WORD, LONG);
  15.  
  16. /* Procedure called when the application is loaded for the first time */
  17. BOOL HelloInit( hInstance )
  18. HANDLE hInstance;
  19. {
  20.   PWNDCLASS   pHelloClass;
  21.  
  22.   pHelloClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  23.  
  24.   pHelloClass->hCursor        = LoadCursor( NULL, IDC_ARROW );
  25.   pHelloClass->hIcon          = LoadIcon( hInstance, NULL);
  26.   pHelloClass->lpszMenuName   = (LPSTR)NULL;
  27.   pHelloClass->lpszClassName  = (LPSTR)"Sample Application";
  28.   pHelloClass->hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  29.   pHelloClass->hInstance      = hInstance;
  30.   pHelloClass->style          = CS_HREDRAW | CS_VREDRAW;
  31.   pHelloClass->lpfnWndProc    = HelloWndProc;
  32.  
  33.   if (!RegisterClass( (LPWNDCLASS)pHelloClass ) )
  34. /* Initialization failed.
  35.          * Windows will automatically deallocate all allocated memory.
  36.          */
  37.     return FALSE;
  38.  
  39.   LocalFree( (HANDLE)pHelloClass );
  40.   return TRUE;        /* Initialization succeeded */
  41. }
  42.  
  43.  
  44. int    PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  45. HANDLE hInstance, hPrevInstance;
  46. LPSTR lpszCmdLine;
  47. int    cmdShow;
  48. {
  49.   MSG   msg;
  50.   HWND  hWnd;
  51.   HMENU hMenu;
  52.   HDC hDC;            /** handle to display context      **/
  53.   RECT lpRect;      /** rectangle coordinates structure    **/
  54.  
  55.   HelloInit( hInstance );
  56.   hWnd = CreateWindow((LPSTR)"Sample", (LPSTR)"Sample Application",
  57.       WS_OVERLAPPEDWINDOW,
  58.       CW_USEDEFAULT, 0,
  59.       CW_USEDEFAULT, 0,
  60.       NULL, NULL, hInstance, NULL);
  61.  
  62. /* Make window visible according to the way the app is activated */
  63.   ShowWindow( hWnd, cmdShow );
  64.   UpdateWindow( hWnd );
  65.  
  66. /** get handle to display context **/
  67.   hDC = GetDC(hWnd);
  68.  
  69. /** fill lpRect with coordinate info for rectangle **/
  70.   lpRect.left = 50;
  71.   lpRect.top  = 50;
  72.   lpRect.right = 150;
  73.   lpRect.bottom = 150;
  74.  
  75.   MessageBox(GetFocus(), (LPSTR)"a small rectangle",
  76.       (LPSTR)"I am about to InvertRect...", MB_OK);
  77.  
  78. /** invert pixels in lpRect **/
  79.   InvertRect (hDC, (LPRECT) & lpRect);
  80.  
  81.   MessageBox(GetFocus(), (LPSTR)"the rectangle",
  82.       (LPSTR)"I am about to InflateRect...", MB_OK);
  83.  
  84. /** inflate rect by 10 in x direction and 10 in y direction **/
  85.   InflateRect((LPRECT) & lpRect, 10, 10);
  86.  
  87.   MessageBox(GetFocus(), (LPSTR)"the inflated rectangle",
  88.       (LPSTR)"I am about to InvertRect...", MB_OK);
  89.  
  90. /** invert the inflated rect to show it is now bigger **/
  91.   InvertRect (hDC, (LPRECT) & lpRect);
  92.  
  93. /* Polling messages from event queue */
  94.   while (GetMessage((LPMSG) & msg, NULL, 0, 0))
  95.   {
  96.     TranslateMessage((LPMSG) & msg);
  97.     DispatchMessage((LPMSG) & msg);
  98.   }
  99.  
  100.   return msg.wParam;
  101. }
  102.  
  103.  
  104. /* Procedures which make up the window class. */
  105. long    FAR PASCAL HelloWndProc( hWnd, message, wParam, lParam )
  106. HWND hWnd;
  107. unsigned    message;
  108. WORD wParam;
  109. LONG lParam;
  110. {
  111.   switch (message)
  112.   {
  113.   case WM_DESTROY:
  114.     PostQuitMessage( 0 );
  115.     break;
  116.  
  117.   default:
  118.     return DefWindowProc( hWnd, message, wParam, lParam );
  119.     break;
  120.   }
  121.   return(0L);
  122. }
  123.  
  124.  
  125.