Solved

API lineto

Posted on 2000-02-20
10
482 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 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 7

Expert Comment

by:Vbmaster
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
Do not use Redraw, use AutoRedraw!
0
 

Author Comment

by:victorlong
Comment Utility
To emoreau:

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

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

771 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

11 Experts available now in Live!

Get 1:1 Help Now