How to get HDC from Canvas
Posted: 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;
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;