Source code 1
/*
Function:
Convert the logical location to the location in the final physical coordinate space
Parameter:
HDC --- space of the logical coordinates to be converted
Lppoint --- the logical point to be converted is the logical point before conversion, and the rounded millimeter after conversion
Ncount ---- number of points to be converted
Retvalue:
True or false
History:
*/
Void getphysicalposition (HDC, lppoint, int ncount)
{
Point originpoint;
Int widthmm = getdevicecaps (HDC, horzsize );
Int heightmm = getdevicecaps (HDC, vertsize );
Int widthres = getdevicecaps (HDC, horzres );
Int heightres = getdevicecaps (HDC, vertres );
Lptodp (HDC, lppoint, ncount );
Getdcorgex (HDC, & originpoint );
For (INT I = 0; I <ncount; ++ I)
{
Lppoint [I]. x + = originpoint. X;
Lppoint [I]. Y + = originpoint. Y;
Lppoint [I]. x = lppoint [I]. x * widthmm/widthres;
Lppoint [I]. Y = lppoint [I]. y * heightmm/heightres;
}
}
Source code 2
/*
Function:
Our own function for converting logical coordinates into device coordinates
*/
Bool mylptodp (
HDC, // handle to device context
Lppoint lppoints, // array of points
Int ncount // count of points in array
)
{
Int graphicsmode = getgraphicsmode (HDC );
If (graphicsmode = gm_advanced) // process the situation where the world coordinate system is enabled
{
XForm curform;
Getworldtransform (HDC, & curform );
For (INT I = 0; I <ncount; ++ I) // use the Formula 1 to convert the world coordinate space to the page coordinate space.
{
Float xpage = lppoints [I]. x * curform. em11 + lppoints [I]. y * curform. em21 + curform. edX;
Float ypage = lppoints [I]. x * curform. EM12 + lppoints [I]. y * curform. em22 + curform. Edy;
Lppoints [I]. x = (INT) xpage;
Lppoints [I]. Y = (INT) ypage;
}
}
Point pointorgview, pointorgwin;
Size winsize, viewsize;
// Obtain the origin and range of the window and the view.
Getviewportorgex (HDC, & pointorgview );
Getviewportextex (HDC, & viewsize );
Get1_worgex (HDC, & pointorgwin );
Getwindowextex (HDC, & winsize );
// Convert the page coordinate space to the device coordinate space based on formula 2.
For (INT I = 0; I <ncount; ++ I)
{
Float xdevice = (lppoints [I]. x-pointOrgWin.x) * viewsize. CX/(float) winsize. cx + pointorgview. X;
Float ydevice = (lppoints [I]. y-pointOrgWin.y) * viewsize. cy/(float) winsize. Cy + pointorgview. Y;
Lppoints [I]. x = (INT) xdevice;
Lppoints [I]. Y = (INT) ydevice;
}
Return true;
}