Solved

Slow Plot

Posted on 1998-11-17
6
209 Views
Last Modified: 2010-05-18
I've created a control which basically just draws a trace according to data supplied to it.  It does this using the line(x1,y1)-(x2,y2) function.
Basic problem - it's slow.  I may have up to 32 of these updating continuously in my project, and with the possibility of 1000 data points - this can mean drawing tens of thousands of lines in each iteration - which I want to happen once every two seconds or so.

So, what can anybody suggest?  Is there a better way of drawing these lines which goes faster?  I was hoping I may be able to get each instance of my control to work in parallel using multithreading, but I can't figure it out.

Cheers-
Rob
0
Comment
Question by:robholden
6 Comments
 
LVL 2

Expert Comment

by:kswinney
ID: 1445220
You can use the API calls "MoveTo" and "LineTo" which will draw significantly faster than VB's line method... but you might also try "Polygon" which will draw several line segments at once.

HTH.
0
 

Author Comment

by:robholden
ID: 1445221
I found LineTo and MoveToEx in the WIN32API.  However I can't seem to get them to work.  The API seems to have loads of graphics type calls, its quite overwhelming.  Could you post a bit of sample code to give me a starting point please?

Cheers
0
 

Author Comment

by:robholden
ID: 1445222
Ok, anybody else got any ideas?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:muffinthedog
ID: 1445223
Seems you might be able to use a memory DC and just BitBlt or StretchBlt it to where ever. Have some old code somewhere (not for a plot though) if you would like... May B write a leetle Dee el el function, pass an array and a hwnd, and have it update the window?
0
 
LVL 1

Accepted Solution

by:
javierma earned 100 total points
ID: 1445224
        I'd try using the API function Polyline. It's easy to do:
1) Declare the function in a module (just paste this)
Type POINTAPI
     x As Long
     y As Long
End Type
Declare Function Polyline& Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long)

2) Create a POINTAPI vector to store your points: (10 for example)
Dim ptVector(1 to 10) as POINTAPI

3) Call the function telling it how many points from that vector are you going to paint.
If you're going to paint in a form then hdc = MyForm.hdc; if on a PictureBox hdc = MyPicture.hdc; or if on a printer hdc = Printer.hdc
Dim Foo as Long
foo = Polyline(hdc , ptVector(1) , 10 )

You're all set. If foo = 0 it means that the function failed, otherwise it worked.

                  Javier Martinez

0
 

Author Comment

by:robholden
ID: 1445225
I like this solution - it is seriously fast.

Cheers-
Rob
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 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

12 Experts available now in Live!

Get 1:1 Help Now