?
Solved

API lineto

Posted on 2000-02-20
10
Medium Priority
?
499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 120 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month9 days, 6 hours left to enroll

764 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