Microsoft KB Archive/34614: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "<" to "<")
m (Text replacement - "&" to "&")
 
Line 47: Line 47:
       PAINTSTRUCT ps;
       PAINTSTRUCT ps;


       hDC = BeginPaint(hWnd, &amp;ps);
       hDC = BeginPaint(hWnd, &ps);


       for (nIndex = 0; nIndex < 50; nIndex++)
       for (nIndex = 0; nIndex < 50; nIndex++)
Line 53: Line 53:
                 rand() / 110, lpfnLineProc, (LPSTR)hDC);
                 rand() / 110, lpfnLineProc, (LPSTR)hDC);


       EndPaint(hWnd, &amp;ps);
       EndPaint(hWnd, &ps);
       break;
       break;
       }
       }

Latest revision as of 14:13, 21 July 2020

INFO: Creating Lines with a Nonstandard Pattern

Q34614



The information in this article applies to:


  • Microsoft Windows Software Development Kit (SDK) 3.1
  • Microsoft Win32 Application Programming Interface (API), used with:
    • Microsoft Windows NT Server versions 3.5, 3.51, 4.0
    • Microsoft Windows NT Workstation versions 3.5, 3.51, 4.0





SUMMARY

The Microsoft Windows graphical environment provides six predefined pens for drawing dotted, dashed, and solid lines. However, an application cannot draw fine gray lines, such as those on a Microsoft Excel spreadsheet, with these pens. This article describes how to create such lines.



MORE INFORMATION

An application can use the LineDDA function to produce any type of patterned line. Based on the endpoints of a line, LineDDA calculates each point on the line and calls an application-defined callback function for each point. The callback function is free to use the calculated points in any manner desired. An application can draw a gray line similar to those used in Excel by calling the the SetPixel function in the callback function to draw every other point.

For example, the following code calculates all points on the line from coordinates (30, 40) to (100, 100). Then it calls the function pointed to by the lpfnLineProc variable with the points and the handle to a device context (hDC) as parameters:

   LineDDA(30, 40, 100, 100, lpfnLineProc, (LPSTR)hDC); 

For more information on this function, see pages 4-272 and 4-273 of the "Microsoft Windows Software Development Kit Reference, Volume 1" for Windows 3.0 or pages 568 and 569 of the "Microsoft Windows Software Development Kit: Programmer's Reference, Volume 2: Functions" for Windows 3.1. Charles Petzold's book "Programming Windows 3" (Microsoft Press, 1990) demonstrates using the LineDDA function in a programming example on pages 593 through 598.

The following code fragment draws 50 random Excel-style lines. Note that the LineProc function must be listed as an EXPORT in the module definition (DEF) file:

   case WM_PAINT:
      {
      HDC hDC;
      int nIndex;
      PAINTSTRUCT ps;

      hDC = BeginPaint(hWnd, &ps);

      for (nIndex = 0; nIndex < 50; nIndex++)
         LineDDA(rand() / 110, rand() / 110, rand() / 110,
                 rand() / 110, lpfnLineProc, (LPSTR)hDC);

      EndPaint(hWnd, &ps);
      break;
      }

   void FAR PASCAL LineProc(x, y, lpData)

   short x, y;
   LPSTR lpData;
   {
   static short nTemp = 0;

   if (nTemp == 1)
      SetPixel((HDC)lpData, x, y, 0L);

   nTemp = (nTemp + 1) % 2;
} 

Additional query words: 3.00 3.10 3.50 4.00 win16sdk

Keywords : kbOSWinNT350 kbOSWinNT351 kbOSWinNT400 kbOSWin95 kbSDKWin16
Issue type : kbinfo
Technology : kbAudDeveloper kbSDKSearch kbWin32sSearch kbWin32API kbWinSDKSearch


Last Reviewed: May 11, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.