DOCUMENT:Q34614 11-MAY-2001 [win16sdk] TITLE :INFO: Creating Lines with a Nonstandard Pattern PRODUCT :Microsoft Windows Software Development Kit PROD/VER:WINDOWS:3.1,95; winnt:3.5,3.51,4.0 OPER/SYS: KEYWORDS:kbOSWinNT350 kbOSWinNT351 kbOSWinNT400 kbOSWin95 kbSDKWin16 ====================================================================== ------------------------------------------------------------------------------- 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 Technology : kbAudDeveloper kbSDKSearch kbWin32sSearch kbWin32API kbWinSDKSearch Version : WINDOWS:3.1,95; winnt:3.5,3.51,4.0 Issue type : kbinfo ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2001.