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

  1. /*
  2.  * Function demonstrated in this program: LineTo
  3.  *
  4.  * Description:
  5.  *   This program demonstrates the use of the LineTo () function.
  6.  *   LineTo () draws a line from the current position up to, but not including
  7.  *   the point specified by X, Y. It also updates the current position to X, Y.
  8.  *   In this program, LineTo () is called in response to a WM_PAINT message
  9.  *   in HelloWndProc ().
  10.  *
  11.  */
  12.  
  13. #include "windows.h"
  14.  
  15. long    FAR PASCAL HelloWndProc (HWND, unsigned, WORD, LONG);
  16.  
  17. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  18. HANDLE    hInstance, hPrevInstance;
  19. LPSTR     lpszCmdLine;
  20. int       cmdShow;
  21.   {
  22.   MSG       msg;
  23.   HWND      hWnd;
  24.   HMENU     hMenu;
  25.   WNDCLASS  HelloClass;
  26.  
  27.   if (!hPrevInstance)
  28.     {
  29.     HelloClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  30.     HelloClass.hIcon          = LoadIcon (hInstance, NULL);
  31.     HelloClass.lpszMenuName   = (LPSTR)NULL;
  32.     HelloClass.lpszClassName  = (LPSTR)"LineTo";
  33.     HelloClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  34.     HelloClass.hInstance      = hInstance;
  35.     HelloClass.style          = CS_HREDRAW | CS_VREDRAW;
  36.     HelloClass.lpfnWndProc    = HelloWndProc;
  37.  
  38.     if (!RegisterClass ( (LPWNDCLASS)&HelloClass))
  39.       return FALSE;
  40.     }
  41.  
  42.   hWnd = CreateWindow ( (LPSTR)"LineTo",
  43.                       (LPSTR)"LineTo ()",
  44.                       WS_OVERLAPPEDWINDOW,
  45.                       CW_USEDEFAULT, CW_USEDEFAULT,
  46.                       CW_USEDEFAULT, CW_USEDEFAULT,
  47.                       (HWND)NULL,           /* no parent */
  48.                       (HMENU)NULL,          /* use class menu */
  49.                       (HANDLE)hInstance,    /* handle to window instance */
  50.                       (LPSTR)NULL);         /* no params to pass on */
  51.  
  52.   ShowWindow (hWnd, cmdShow);
  53.   UpdateWindow (hWnd);
  54.  
  55.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  56.     {
  57.     TranslateMessage ( (LPMSG) & msg);
  58.     DispatchMessage ( (LPMSG) & msg);
  59.     }
  60.   return (int)msg.wParam;
  61.   }
  62.  
  63.  
  64. /* Procedures which make up the window class. */
  65. long    FAR PASCAL HelloWndProc (hWnd, message, wParam, lParam)
  66. HWND     hWnd;
  67. unsigned message;
  68. WORD     wParam;
  69. LONG     lParam;
  70.   {
  71.   PAINTSTRUCT ps;
  72.  
  73.   switch (message)
  74.     {
  75.     case WM_DESTROY:
  76.       PostQuitMessage (0);
  77.       break;
  78.  
  79.     case WM_PAINT:
  80.       BeginPaint (hWnd, (LPPAINTSTRUCT) & ps);
  81.  
  82.       MoveTo (ps.hdc, 100, 10);    /*  move current position to 100, 10 */
  83.       LineTo (ps.hdc, 100, 200);   /*  draw from 100, 10 to 10, 200      */
  84.       MoveTo (ps.hdc, 200, 10);    /*  move current position to 200, 10 */
  85.       LineTo (ps.hdc, 200, 200);   /*  draw from 200, 10 to 200, 200     */
  86.       LineTo (ps.hdc, 300, 10);    /* draw to 300, 10                      */
  87.  
  88.       EndPaint (hWnd, (LPPAINTSTRUCT) & ps);
  89.       break;
  90.  
  91.     default:
  92.       return DefWindowProc (hWnd, message, wParam, lParam);
  93.       break;
  94.     }
  95.   return (0L);
  96.   }
  97.