API in Excel

  • Thread starter Thread starter Mike510
  • Start date Start date
M

Mike510

Can anybody give an example or link of using GDI in Excel?
Is it possible to plot a function on a form surface for example without
Excel charts, just using LineTo, SetPixel etc.?

Thank you in advance.

Mike
 
I have found a solution using VB6 examples and news archive:
Dim hDC As Long
Dim DummyPt As PointAPI
hDC = GetDC(0)
Call SetPixelV(hDC, 100, 100, vbRed)
Call MoveToEx(hDC, 5, 15, DummyPt)
Call LineTo(hDC, 25, 15)
ReleaseDC 0, hDC
But instead a form it is plotting on Excel window itself (or on VBA editor).

Can anybody help? What parameter should I pass to GetDC() instead of 0?

Thank you in advance.

Mike.
 
Hi Mike510,
I have found a solution using VB6 examples and news archive:
Dim hDC As Long
Dim DummyPt As PointAPI
hDC = GetDC(0)
Call SetPixelV(hDC, 100, 100, vbRed)
Call MoveToEx(hDC, 5, 15, DummyPt)
Call LineTo(hDC, 25, 15)
ReleaseDC 0, hDC
But instead a form it is plotting on Excel window itself (or on VBA editor).

Can anybody help? What parameter should I pass to GetDC() instead of 0?

The parameter to GetDC (and ReleaseDC) should be the window handle of the
form, found using the FindWindow(vbNullString,Me.Caption) API call.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk
 
Thank you very much for your help, Mr. Bullen.
Before I have read your post, I tried GetActiveWindow(). It worked too.
Should I delete hDC after releasing it or it is not necessary?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top