我在程序中使用msflexgrid控件调用行列宽度的函数SetColWidth(行号,大小),SetRowHeight(列号,大小),但是控件的大小非象素坐标,发现是一种Twips坐标,请问如何与象素坐标转换!拜谢!

解决方案 »

  1.   

    转载一下别人的原话:
    a TWIP is 1/20 of a point and 1/1440 of an inch, the conversion between twips and pixels is done as follows:Pixels=TWIPS*pixelsperinch/1440
      

  2.   

    是的。1象素=20twips.我原先也用了这个控件。
    我以前的部分程序是这样的:
    long lRow = m_Points.GetRowSel();//m_Points就是CMSFlexGrid类型
    long lCol = m_Points.GetColSel();
    // MSFlexGrid 控件的函数的长度单位是"缇(twips)",
    //需要将其转化为像素,1440 缇 = 1 英寸
    CDC* pDC =GetDC();
    int nTwipsPerDotX = 1440 / pDC->GetDeviceCaps(LOGPIXELSX) ;
    int nTwipsPerDotY = 1440 / pDC->GetDeviceCaps(LOGPIXELSY) ;
    //
    long y = m_Points.GetRowPos(lRow)/nTwipsPerDotY;
    long x = m_Points.GetColPos(lCol)/nTwipsPerDotX;
    long width = m_Points.GetColWidth(lCol)/nTwipsPerDotX+1;
    long height = m_Points.GetRowHeight(lRow)/nTwipsPerDotY+1;
      

  3.   

    CDC* pDC = GetDC();
            m_nLogX = pDC->GetDeviceCaps(LOGPIXELSX);
            m_nLogY = pDC->GetDeviceCaps(LOGPIXELSY);
    pDC->SetWindowOrg(CPoint(x0*m_nLogX/1440,y0*m_nLogY/1440));//设置相对坐标原点
    ReleaseDC(pDC);
    MoveWindow(((m_fgrid.GetCellLeft() - x0+m_fgrid.GetCellHeight()) * m_nLogX)/1440,
                ((m_fgrid.GetCellTop() - y0+m_fgrid.GetCellHeight()) * m_nLogY)/1440,
                (m_fgrid.GetCellWidth()* m_nLogX)/1440,
                (m_fgrid.GetCellHeight()* m_nLogY)/1440, FALSE);
    //x0和y0的值如下:m_fgrid.SetRow(0);m_fgrid.SetRow(0);x0=m_fgrid.GetCellLe();
    //y0=m_fgrid.GetCellTop() ;x0和y0是相对原点的象素坐标