Solved

Slow Plot

Posted on 1998-11-17
6
195 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
Comment Utility
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
Comment Utility
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
Comment Utility
Ok, anybody else got any ideas?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Expert Comment

by:muffinthedog
Comment Utility
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
Comment Utility
        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
Comment Utility
I like this solution - it is seriously fast.

Cheers-
Rob
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

772 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

15 Experts available now in Live!

Get 1:1 Help Now