龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

做一个可编辑的表格控件(2)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
//需要将其转化为像素,1440 缇 = 1 英寸 CDC* pDC =GetDC(); //计算象素点和缇的转换比例 int nTwipsPerDotX = 1440 / pDC-GetDeviceCaps(LOGPIXELSX) ; int nTwipsPerDotY = 1440 / pDC-

     //需要将其转化为像素,1440 缇 = 1 英寸

       CDC* pDC =GetDC();

    //计算象素点和缇的转换比例

       int nTwipsPerDotX = 1440 / pDC->GetDeviceCaps(LOGPIXELSX) ;

       int nTwipsPerDotY = 1440 / pDC->GetDeviceCaps(LOGPIXELSY) ;

       //计算选中格的左上角的坐标(象素为单位)

       long y = m_FlexGrid.GetRowPos(lRow)/nTwipsPerDotY;

       long x = m_FlexGrid.GetColPos(lCol)/nTwipsPerDotX;

    //计算选中格的尺寸(象素为单位)。加1是实际调试中,发现加1后效果更好

       long width = m_FlexGrid.GetColWidth(lCol)/nTwipsPerDotX+1;

       long height = m_FlexGrid.GetRowHeight(lRow)/nTwipsPerDotY+1;

    //形成选中个所在的矩形区域

       CRect rc(x,y,x+width,y+height);

    //转换成相对对话框的坐标

       rc.OffsetRect(rect.left+1,rect.top+1);

       //清空下拉列表的内容

       m_ChangeCombo.ResetContent( );

    //以下省略哪一列用文本控件,哪一列用下拉列表控件的判断。如果是用下拉列表控件,则会先向下拉列表控件中增加数据,否则为空

  ……………………………….

  ……………………………….

       //获取选中格的文本信息

       CString strValue = m_FlexGrid.GetTextMatrix(lRow,lCol);

       int num = m_ChangeCombo.GetCount();

    //如果下拉列表控件中有数据,则表示使用下拉列表控件来进行数据选择

       if(num!=0)

       {
              m_ChangeCombo.ShowWindow(SW_SHOW);//显示控件

              m_ChangeCombo.MoveWindow(rc);        //移动到选中格的位置,覆盖

              m_ChangeCombo.SelectString(-1,strValue);   //内容全选。方便直接修改

              m_ChangeCombo.SetFocus();              //获取焦点

              UpdateData(false);

            return;

       }

精彩图集

赞助商链接