prabhakar157
June 17th, 2006, 02:28 AM
Using the Mapping modes like MM_LOENGLISH etc change the client view coordinate system to inches... but
How to get the units in Meters? I mean.... provided ne amount of pixels units i want it to be displayed in Meters...
I made use of thid code which is actually a Delphi program
I modified it to MFC code..... (and this is an SDI Application)
class CDoublePoint : CObject
{
public:
CDoublePoint();
virtual ~CDoublePoint()
{
}
CDoublePoint(double X,double Y); //Parameter Constructor
double PixelHorizToMM(int PixelX);
double PixelVertToMM(int PixelY);
CDoublePoint(const CDoublePoint& D_PointSrc);
void PixelPointToMM(CPoint PixelPt);
public:
double D_x,D_y;
};
CDoublePoint::CDoublePoint()
{
}
CDoublePoint::CDoublePoint(const CDoublePoint& D_PointSrc) //Copy Constructor
{
this->D_x = D_PointSrc.D_x;
this->D_y = D_PointSrc.D_y;
}
CDoublePoint::CDoublePoint(double X,double Y) //Parameter Constructor
{
this->D_x = X;
this->D_y = Y;
}
double CDoublePoint::PixelHorizToMM(int PixelX)
{
HDC hdcDesk;
hdcDesk = GetDC(AfxGetMainWnd()->GetSafeHwnd());
//GetDC(0) was used in Delphi
this->D_x = PixelX * (GetDeviceCaps(hdcDesk, HORZSIZE) /
GetDeviceCaps(hdcDesk, HORZRES));
ReleaseDC(AfxGetMainWnd()->GetSafeHwnd(),hdcDesk);
// and ReleaseDC(0,hdcDesk) was used here
return this->D_x;
}
double CDoublePoint::PixelVertToMM(int PixelY)
{
HDC hdcDesk;
hdcDesk = GetDC(AfxGetMainWnd()->GetSafeHwnd());
this->D_y = PixelY * (GetDeviceCaps(hdcDesk, VERTSIZE) /
GetDeviceCaps(hdcDesk, VERTRES));
ReleaseDC(AfxGetMainWnd()->GetSafeHwnd(),hdcDesk);
return this->D_y;
}
void CDoublePoint::PixelPointToMM(CPoint PixelPt)
{
this->D_x = PixelHorizToMM(PixelPt.x);
this->D_y = PixelVertToMM(PixelPt.y);
}
I tried to displayed the values on the screen
//inside OnDraw method
...
....
....
PixelinMM.PixelPointToMM(CPoint(10,10));
temp_String.Format("Value of 10 Pixel in MM for Horizontal Resolution: %g",PixelinMM.D_x);
pDC->TextOut(400,400,temp_String);
temp_String.Format("Value of 10 Pixel in MM for Vertical Resolution : %g",PixelinMM.D_y);
pDC->TextOut(400,430,temp_String);
}
May be...... i didn't get the proper handle for the window inspite of using AfxGetMainWnd().....
Moreover this code seems complex to me......
How do i make it a simple one?
How to get the units in Meters? I mean.... provided ne amount of pixels units i want it to be displayed in Meters...
I made use of thid code which is actually a Delphi program
I modified it to MFC code..... (and this is an SDI Application)
class CDoublePoint : CObject
{
public:
CDoublePoint();
virtual ~CDoublePoint()
{
}
CDoublePoint(double X,double Y); //Parameter Constructor
double PixelHorizToMM(int PixelX);
double PixelVertToMM(int PixelY);
CDoublePoint(const CDoublePoint& D_PointSrc);
void PixelPointToMM(CPoint PixelPt);
public:
double D_x,D_y;
};
CDoublePoint::CDoublePoint()
{
}
CDoublePoint::CDoublePoint(const CDoublePoint& D_PointSrc) //Copy Constructor
{
this->D_x = D_PointSrc.D_x;
this->D_y = D_PointSrc.D_y;
}
CDoublePoint::CDoublePoint(double X,double Y) //Parameter Constructor
{
this->D_x = X;
this->D_y = Y;
}
double CDoublePoint::PixelHorizToMM(int PixelX)
{
HDC hdcDesk;
hdcDesk = GetDC(AfxGetMainWnd()->GetSafeHwnd());
//GetDC(0) was used in Delphi
this->D_x = PixelX * (GetDeviceCaps(hdcDesk, HORZSIZE) /
GetDeviceCaps(hdcDesk, HORZRES));
ReleaseDC(AfxGetMainWnd()->GetSafeHwnd(),hdcDesk);
// and ReleaseDC(0,hdcDesk) was used here
return this->D_x;
}
double CDoublePoint::PixelVertToMM(int PixelY)
{
HDC hdcDesk;
hdcDesk = GetDC(AfxGetMainWnd()->GetSafeHwnd());
this->D_y = PixelY * (GetDeviceCaps(hdcDesk, VERTSIZE) /
GetDeviceCaps(hdcDesk, VERTRES));
ReleaseDC(AfxGetMainWnd()->GetSafeHwnd(),hdcDesk);
return this->D_y;
}
void CDoublePoint::PixelPointToMM(CPoint PixelPt)
{
this->D_x = PixelHorizToMM(PixelPt.x);
this->D_y = PixelVertToMM(PixelPt.y);
}
I tried to displayed the values on the screen
//inside OnDraw method
...
....
....
PixelinMM.PixelPointToMM(CPoint(10,10));
temp_String.Format("Value of 10 Pixel in MM for Horizontal Resolution: %g",PixelinMM.D_x);
pDC->TextOut(400,400,temp_String);
temp_String.Format("Value of 10 Pixel in MM for Vertical Resolution : %g",PixelinMM.D_y);
pDC->TextOut(400,430,temp_String);
}
May be...... i didn't get the proper handle for the window inspite of using AfxGetMainWnd().....
Moreover this code seems complex to me......
How do i make it a simple one?