Page 1 of 1

How to get HDC from Canvas

Posted: Mon Jan 22, 2007 5:25 pm
by 9526439
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;

Posted: Tue Jan 23, 2007 8:27 am
by narcis
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();
}

Small error

Posted: Tue Feb 05, 2008 3:26 pm
by 15048122
There is a small error in code, correct code is:

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

Please notice the attached '.lVal'.

Best regards,
naiditsch