How to get HDC from Canvas

TeeChart for ActiveX, COM and ASP
Post Reply
amol
Advanced
Posts: 231
Joined: Tue Mar 29, 2005 5:00 am

How to get HDC from Canvas

Post by amol » Mon Jan 22, 2007 5:25 pm

Hello,

I am implementing isometric axis for my application with ActiveX in visual C++ and I found some sample code in .net 2.0 with the following code. So I tried to convert it into C++.
I don't know have to convert: Canvas.Handle which I assume returns a HDC varible to C++ code like myChart.GetCanvas().GetHandleDC() which returns a VARIANT. I would appreicate that you can help me out. It is better if you can convert the whole subroutine. I think that it will also help someone else. BTW, I really hope that the MakeIOMetric() function works in ActiveX. When the current function is used, it can not produce the desired result with the right aspect ratio (sometimes works sometimes not).


Thanks,

Hookem

//////////////////////////////////////////////////////
the following is the code I copied from your website

Procedure MakeIsoAxis(AChart:TCustomChart);
var tmpX,tmpY,XRange,YRange,Offset,XYScreen:Double;
begin
With AChart do
if (ChartHeight>0) and (ChartWidth>0) then
begin
With BottomAxis do XRange:=Maximum-Minimum;
With LeftAxis do YRange:=Maximum-Minimum;

XYScreen:=1.0*(GetDeviceCaps(Canvas.Handle,HORZSIZE)/Screen.Width)/
(GetDeviceCaps(Canvas.Handle,VERTSIZE)/Screen.Height);

tmpX:=(XRange/ChartWidth);
tmpY:=(YRange/ChartHeight)*XYScreen;

if tmpX>tmpY then
begin
if tmpY<>0 then
begin
Offset:=((YRange*tmpX/tmpY)-YRange)/2.0;
With LeftAxis do SetMinMax(Minimum-Offset,Maximum+Offset);
end;
end
else
if tmpX<>0 then
begin
Offset:=((XRange*tmpY/tmpX)-XRange)/2.0;
With BottomAxis do SetMinMax(Minimum-Offset,Maximum+Offset);
end;
end;
end;

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Jan 23, 2007 8:27 am

Hi bchatt,

It may be easier for you converting the routine at TeeChart Pro v7 ActiveX features demo which you'll find at TeeChart's program group. The example is a What's New?\Welcome!\New in Axis\Isometric Axis.

Here's a C++ example using GetHandleDC():

Code: Select all

void CTestDrawView::OnOnBeforeDrawChartChart()
{
 // TODO: Add your control notification handler code here
 GETCHART(pChart);
 CDC DC;
 long hDC=pChart->GetCanvas().GetHandleDC();
 DC.Attach(HDC(hDC));
 m_Dib.Draw(&DC,m_StartPt,CSize(100,100)); //m_Dib is the Bitmap I want
to paint on Chart;
 DC.Detach();
}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

naiditsch
Newbie
Newbie
Posts: 1
Joined: Wed Jan 30, 2008 12:00 am

Small error

Post by naiditsch » Tue Feb 05, 2008 3:26 pm

There is a small error in code, correct code is:

long hDC=pChart->GetCanvas().GetHandleDC().lVal;

Please notice the attached '.lVal'.

Best regards,
naiditsch

Post Reply