Code involved in the coordinate system in Windows GDI

Source: Internet
Author: User
Tags xpage

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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.