Solved

API lineto

Posted on 2000-02-20
10
486 Views
Last Modified: 2008-02-01
Hi,

I draw many lines by the Line method and found that is too slow.
Do you think the API lineto function will be faster?
0
Comment
Question by:victorlong
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2540150
The poor performance isn't caused by the Line method. It is due Windows itself.

Try setting the AutoRedraw property of your form to False.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2540161
Perhaps this can help make it faster, it made it really faster for me. You can add this to your form and set the Redraw property to False before you draw the lines and True when you are done..

Private m_Redraw As Boolean
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Property Let Redraw(RedrawState As Boolean)

  If (m_Redraw <> RedrawState) Then
    m_Redraw = RedrawState
    Call SendMessage(Me.hwnd, &HB, -m_Redraw, 0&)
    If m_Redraw Then Me.Refresh
  End If

End Property
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2540200
API LineTo will be faster than the Line method.  LineTo uses the current position to draw from, so in many cases you do not have to call MoveTo first.  In the Line method, the start and end positions are always given.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 7

Expert Comment

by:Vbmaster
ID: 2540222
Actually, you do not need to state the start positions with the VB Line either, you can for example use something like this ...

  Line (10, 10)-(200, 200), vbBlack
  Line -(400, 300), vbBlack

.... and it will continue from the current position on the second line.
0
 

Author Comment

by:victorlong
ID: 2540251
To Vbmaster:

I have just tested your code by adding an event

Private Sub Command1_Click()

 Me.Redraw = False
 Me.Line (0, 0)-(200, 200)
 Me.Redraw = True 'it made the line dissapeared!
 
End Sub

But, the line dissapeared.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2540563
Do not use Redraw, use AutoRedraw!
0
 

Author Comment

by:victorlong
ID: 2540720
To emoreau:

Redraw is a property created for the form. Please see Vbmaster's comment.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2540775
AutoRedraw is an already existing form's property that can help performance when using graphics method.
0
 
LVL 1

Accepted Solution

by:
powlin earned 40 total points
ID: 2541043
Line is more slow than any line drawing
i have done an appz that draw a rotating wireframe cube

in this case the LineTo is about 40-50% faster than Line you can also use PolyLineTo that draw line from an array point if your line segments is connected.

Setting autoredraw to false also speed up display but it looking flickering so Autoredraw is slower but appear more smooth.

0
 

Author Comment

by:victorlong
ID: 2544099
Experts,

Thank you for all your help.

I have just tested the speed in three cases:

API MovetoEx+Lineto: 14.75 seconds
VB Line: 15.16 seconds
VB Line+AutoRedraw/F/T: 16.37 seconds

So, only small difference :-(

In the loop of drawing lines, there are some calculation.....

I remember, long time ago, I used a statement which let no gpraph action in the loop until another statement all the graph actions were executed. I can not remember the name of the statements and in VB or Delphi :-( Perhaps that can help me?
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now