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

  1. /*
  2.  *   This program demonstrates the use of the Chord() function.
  3.  *   Chord() draws a chord. Chord() is called in response to a WM_PAINT
  4.  *   message in HelloWndProc();
  5.  */
  6.  
  7. #include "windows.h"
  8.  
  9. long    FAR PASCAL HelloWndProc(HWND, unsigned, WORD, LONG);
  10.  
  11. /* Procedure called when the application is loaded for the first time */
  12. BOOL HelloInit(hInstance)
  13. HANDLE hInstance;
  14.   {
  15.   PWNDCLASS   pHelloClass;
  16.  
  17.   pHelloClass = (PWNDCLASS)LocalAlloc(LPTR, sizeof(WNDCLASS));
  18.  
  19.   pHelloClass->hCursor        = LoadCursor(NULL, IDC_ARROW);
  20.   pHelloClass->hIcon             = LoadIcon(hInstance, NULL);
  21.   pHelloClass->lpszMenuName   = (LPSTR)NULL;
  22.   pHelloClass->lpszClassName     = (LPSTR)"Chord";
  23.   pHelloClass->hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  24.   pHelloClass->hInstance      = hInstance;
  25.   pHelloClass->style          = CS_HREDRAW | CS_VREDRAW;
  26.   pHelloClass->lpfnWndProc    = HelloWndProc;
  27.  
  28.   if (!RegisterClass((LPWNDCLASS)pHelloClass))
  29.         /* Initialization failed.
  30.          * Windows will automatically deallocate all allocated memory.
  31.          */
  32.     return FALSE;
  33.  
  34.   LocalFree((HANDLE)pHelloClass);
  35.   return TRUE;        /* Initialization succeeded */
  36.   }
  37.  
  38.  
  39. int     PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  40. HANDLE   hInstance, hPrevInstance;
  41. LPSTR    lpszCmdLine;
  42. int      cmdShow;
  43.   {
  44.   MSG   msg;
  45.   HWND  hWnd;
  46.  
  47.   HelloInit(hInstance);
  48.   hWnd = CreateWindow((LPSTR)"Chord",
  49.                       (LPSTR)"Chord()",
  50.                       WS_OVERLAPPEDWINDOW,
  51.                       CW_USEDEFAULT,
  52.                       CW_USEDEFAULT,
  53.                       CW_USEDEFAULT,
  54.                       CW_USEDEFAULT,
  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.   ShowWindow(hWnd, cmdShow);
  61.   UpdateWindow(hWnd);
  62.  
  63.   while (GetMessage((LPMSG) & msg, NULL, 0, 0))
  64.     {
  65.     TranslateMessage((LPMSG) & msg);
  66.     DispatchMessage((LPMSG) & msg);
  67.     }
  68.  
  69.   return (int)msg.wParam;
  70.   }
  71.  
  72.  
  73. /* Procedures which make up the window class. */
  74. long    FAR PASCAL HelloWndProc(hWnd, message, wParam, lParam)
  75. HWND       hWnd;
  76. unsigned   message;
  77. WORD       wParam;
  78. LONG       lParam;
  79.   {
  80.   PAINTSTRUCT ps;
  81.   BOOL bDrawn;       /* was the chord drawn? */
  82.  
  83.   switch (message)
  84.     {
  85.     case WM_DESTROY:
  86.       PostQuitMessage(0);
  87.       break;
  88.  
  89.     case WM_PAINT:
  90.       BeginPaint(hWnd, (LPPAINTSTRUCT) & ps);
  91.       bDrawn = Chord(ps.hdc, 5, 5, 100, 100, 0, 22, 150, 22);
  92.                   /***** draw the chord *****/
  93.       if (!bDrawn)
  94.         MessageBox(NULL,
  95.                    (LPSTR)"Chord failed!",
  96.                    (LPSTR)"Chord info:",
  97.                    MB_OK);          /* Tell User it didn't work */
  98.       EndPaint(hWnd, (LPPAINTSTRUCT) & ps);
  99.       break;
  100.  
  101.     default:
  102.       return DefWindowProc(hWnd, message, wParam, lParam);
  103.       break;
  104.     }
  105.   return(0L);
  106.   }
  107.