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

  1. /*
  2.  *  Function Name:   BeginPaint EndPaint
  3.  *  Program Name:    endpaint.c
  4.  *  Special Notes:
  5.  *
  6.  *  SDK Version:         2.03
  7.  *  Runtime Version:     2.03
  8.  *  Microsoft C Version: 5.0
  9.  *
  10.  *  Description:
  11.  *   This function tells Windows that the program has finished processing
  12.  *   the paint message and it is okay for Windows to go ahead and remove
  13.  *   the display context.
  14.  *
  15.  *   Windows Version 2.0 function demonstration application
  16.  *
  17.  */
  18.  
  19. #include "windows.h"
  20.  
  21. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  22.  
  23. /***********************************************************************/
  24.  
  25. void CALL_EndPaint(hDC)
  26. HDC hDC;
  27. {
  28.     TextOut(hDC, 10, 10, (LPSTR)"See code for details. /n", 22);
  29.  
  30.     return;
  31. }
  32.  
  33. /**************************************************************************/
  34.  
  35. /* Procedure called when the application is loaded for the first time */
  36. BOOL WinInit( hInstance )
  37. HANDLE hInstance;
  38. {
  39.     WNDCLASS   wcClass;
  40.  
  41.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  42.     wcClass.lpfnWndProc    = WndProc;
  43.     wcClass.cbClsExtra     =0;
  44.     wcClass.cbWndExtra     =0;
  45.     wcClass.hInstance      = hInstance;
  46.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  47.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  48.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  49.     wcClass.lpszMenuName   = (LPSTR)NULL;
  50.     wcClass.lpszClassName  = (LPSTR)"EndPaint";
  51.  
  52.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  53.         /* Initialization failed.
  54.          * Windows will automatically deallocate all allocated memory.
  55.          */
  56.         return FALSE;
  57.  
  58.     return TRUE;        /* Initialization succeeded */
  59. }
  60.  
  61.  
  62. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  63. HANDLE hInstance, hPrevInstance;
  64. LPSTR lpszCmdLine;
  65. int cmdShow;
  66. {
  67.     MSG   msg;
  68.     HWND  hWnd;
  69.  
  70.     if (!hPrevInstance)
  71.         {
  72.         /* Call initialization procedure if this is the first instance */
  73.         if (!WinInit( hInstance ))
  74.             return FALSE;
  75.         }
  76.  
  77.     hWnd = CreateWindow((LPSTR)"EndPaint",
  78.                         (LPSTR)"EndPaint()",
  79.                         WS_OVERLAPPEDWINDOW,
  80.                         CW_USEDEFAULT,
  81.                         CW_USEDEFAULT,
  82.                         CW_USEDEFAULT,
  83.                         CW_USEDEFAULT,
  84.                         (HWND)NULL,        /* no parent */
  85.                         (HMENU)NULL,       /* use class menu */
  86.                         (HANDLE)hInstance, /* handle to window instance */
  87.                         (LPSTR)NULL        /* no params to pass on */
  88.                         );
  89.  
  90.     /* Make window visible according to the way the app is activated */
  91.     ShowWindow( hWnd, cmdShow );
  92.     UpdateWindow( hWnd );
  93.  
  94.     /* Polling messages from event queue */
  95.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  96.         {
  97.         TranslateMessage((LPMSG)&msg);
  98.         DispatchMessage((LPMSG)&msg);
  99.         }
  100.  
  101.     return (int)msg.wParam;
  102. }
  103.  
  104. /* Procedures which make up the window class. */
  105. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  106. HWND hWnd;
  107. unsigned message;
  108. WORD wParam;
  109. LONG lParam;
  110. {
  111.     PAINTSTRUCT ps;
  112.  
  113.     switch (message)
  114.     {
  115.  
  116.     case WM_PAINT:
  117.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  118.         CALL_EndPaint(ps.hdc);
  119.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  120.         break;
  121.  
  122.     case WM_DESTROY:
  123.         PostQuitMessage( 0 );
  124.         break;
  125.  
  126.     default:
  127.         return DefWindowProc( hWnd, message, wParam, lParam );
  128.         break;
  129.     }
  130.     return(0L);
  131. }
  132.  
  133. 
  134.