| 首页 | 新闻 | 网页 | 设计 | 色彩 | 原创 | 视觉 | 素材 | 动漫 | 酷站 | 策划 | 文案 | 访谈 | 运营 | 编程 | 数据库 | 服务器 | 下载 | 图库 | 
您的位置: 幽幽天空 > 网页 > 编程开发 > Visual C++教程 > 文章正文 用户登录
TOM ULINK新闻联盟
TinyURL免费缩短网
苏能科技100M/FTP
威客(witkey)的
Flash Remoting -
Flash声音高级篇:
flashremoting实践
Loading制作之 计
Flash8 Remoting 
再探FlashCom的HT

Windows GDI中的坐标系一文所涉及的代码           

Windows GDI中的坐标系一文所涉及的代码

作者:佚名 来源:CSDN 作者: leezy_2000 更新:2006-8-25 21:05:35 错误报告 我要投稿

源码1

/*
 Function:

 把逻辑位置转换为最终的物理坐标空间中的位置

 Parameter:

 hDC---待转换逻辑坐标所处的空间

 lpPoint---待转换的逻辑点转换前为逻辑点,转换后为取整后的毫米

 nCount----待转换点的个数

 RetValue:

 TRUE or FALSE

 History:

 2003-10-25 11:13
*/
void GetPhysicalPosition(HDC hDC,LPPOINT 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;
 }

}

源码2
/*
 Function:

  我们自己的把逻辑坐标转换为设备坐标的函数
*/
BOOL MyLPtoDP(
  HDC 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) //处理启用了世界坐标系的情况
 {
  XFORM curForm;

  GetWorldTransform(hdc,&curForm);

  for(int i=0; i<nCount; ++i)//应用公式一完成世界坐标空间向页面坐标空间的转换
  {
   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;

 //得到窗口、视口的原点和范围
 GetViewportOrgEx(hdc,&pointOrgView);
 GetViewportExtEx(hdc,&viewSize);
 GetWindowOrgEx(hdc,&pointOrgWin);
 GetWindowExtEx(hdc,&winSize);

 //根据公式二进行页面坐标空间到设备坐标空间的转换
 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;
}

文章录入:skyuu    责任编辑:skyuu 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    发表评论:
    姓名:  评 分: 1分 2分 3分 4分 5分
     
  • 严禁发表危害国家安全、政治、黄色淫秽等内容的评论。
  • 用户需对自己在使用幽幽天空服务过程中的行为承担法律责任。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表机友个人观点,与本网站立场无关。