Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Using LineDDA api to control each point of line.

Total Hit ( 3246)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


This small code snippet will show you the use of LineDDA api which is very useful when you want to control each point of line. LineDDA use a callback method which gives x and y cordinates of the point to be drawn.

Step-By-Step Example

- Create a standard exe project
- Add one module to the project
- Add the following code in form1

Form1.frm

Click here to copy the following block
Private Sub Form_Paint()
  Dim LinePts() As typLinePoint
  Dim LoopPts As Long, NumPts As Long

  ' Grab the line points for this line
  LinePts() = GetLinePts(10, 10, 100, 100, NumPts)

  If (NumPts) Then  ' Draw them
    For LoopPts = 0 To NumPts - 1
      Form1.PSet ( _
          LinePts(LoopPts).X * Screen.TwipsPerPixelX, _
          LinePts(LoopPts).Y * Screen.TwipsPerPixelY), _
          CLng(LoopPts / NumPts * &HFF) * &H10101
    Next LoopPts
  End If
End Sub

Module1.frm

Click here to copy the following block
Option Explicit

Private Declare Function LineDDA Lib "gdi32" ( _
    ByVal n1 As Long, ByVal n2 As Long, ByVal n3 As Long, _
    ByVal n4 As Long, ByVal lpLineDDAProc As Long, _
    ByVal lParam As Long) As Long

Public Type typLinePoint
  X As Long
  Y As Long
End Type

Private LinePts() As typLinePoint
Private NumPts As Long

Public Function GetLinePts(ByVal inXa As Long, ByVal inYa As Long, _
  ByVal inXb As Long, ByVal inYb As Long, _
  ByRef outPointCount As Long) As typLinePoint()
  Erase LinePts()
  NumPts = 0

  ' Call the function that does the work
  Call LineDDA(inXa, inYa, inXb, inYb, AddressOf LineDDAProc, 0&)

  ' Return point list and number of returned points
  GetLinePts = LinePts()
  outPointCount = NumPts
End Function

Private Sub LineDDAProc(ByVal X As Long, _
  ByVal Y As Long, ByVal lpData As Long)
  ReDim Preserve LinePts(NumPts) As typLinePoint
  LinePts(NumPts).X = X  ' Callback for LineDDA()
  LinePts(NumPts).Y = Y  ' Add this point to the list
  NumPts = NumPts + 1
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.