Solved

API lineto

Posted on 2000-02-20
10
498 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

726 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