📄 editidlg.cpp
字号:
for(i=1;i<iRows;i++)
{
m_gridCtrl.SetRow(long(i));
m_gridCtrl.SetCellBackColor(RGB(0xFF,0xFF,0xFF));
m_gridCtrl.SetCellForeColor(RGB(0,0,0));
}
}
iResid=str2.GetLength()-ips2-1;
if(iResid>0)
{
str2=str2.Mid(ips2+1,iResid);
ips2=str2.Find(":");
}
else
{str2="";ips2=-1;}
}
bMultiSel=false;
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetCol(iCol);
m_gridCtrl.SetRowSel(iRowSel);
strColSel=":";
if(iCtrlKey)
{
if(strRowSel=="") strRowSel=";";
str.Format("%d;",iRow);
ips=strRowSel.Find(";"+str);
if(ips!=-1)
{
ips2=ips+str.GetLength();
str2=strRowSel.Mid(0,ips)+strRowSel.Mid(ips2,strRowSel.GetLength()-ips2);
strRowSel=str2;
num=-1;
str2=strRowSel.Mid(1,strRowSel.GetLength()-1);
ips2=str2.Find(";");
while(ips2!=-1)
{
num=num+1;
str3=str2.Mid(0,ips2);
iRowi=atoi(str3.GetBuffer(0));
m_gridCtrl.SetRow(iRowi);
m_gridCtrl.SetCol(1);
if(m_gridCtrl.GetCellBackColor()!=m_gridCtrl.GetBackColorSel())
{
for(i=1;i<iCols;i++)
{
m_gridCtrl.SetCol(long(i));
m_gridCtrl.SetCellBackColor(m_gridCtrl.GetBackColorSel());
m_gridCtrl.SetCellForeColor(m_gridCtrl.GetForeColorSel());
}
}
iResid=str2.GetLength()-ips2-1;
if(iResid>0)
{
str2=str2.Mid(ips2+1,iResid);
ips2=str2.Find(";");
}
else
{str2="";ips2=-1;}
}
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetCol(iCol);
m_gridCtrl.SetColSel(iColSel);
for(i=1;i<iCols;i++)
{
m_gridCtrl.SetCol(long(i));
m_gridCtrl.SetCellBackColor(RGB(0xFF,0xFF,0xFF));
m_gridCtrl.SetCellForeColor(RGB(0,0,0));
}
m_gridCtrl.SetCol(iCol);
if(str2==";") m_gridCtrl.SetColSel(iCol);
}
else
{
str2=strRowSel.Mid(0,strRowSel.GetLength()-1);
ips2=str2.ReverseFind(char(0x3B)); // char(0x3B)-- ";"
if(ips2!=-1)
{
ips2=ips2+1;
str3=str2.Mid(ips2,str2.GetLength()-ips2);
iRowi=atoi(str3.GetBuffer(0));
m_gridCtrl.SetRow(iRowi);
for(i=1;i<iCols;i++)
{
m_gridCtrl.SetCol(long(i));
m_gridCtrl.SetCellBackColor(m_gridCtrl.GetBackColorSel());
m_gridCtrl.SetCellForeColor(m_gridCtrl.GetForeColorSel());
}
}
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetCol(iCol);
m_gridCtrl.SetColSel(iColSel);
strRowSel=strRowSel+str;
}
MessageBox(strRowSel);
} //"Ctrl" is pushed
else
{
str2=strRowSel.Mid(1,strRowSel.GetLength()-1);
ips2=str2.Find(";");
while(ips2!=-1)
{
str3=str2.Mid(0,ips2);
iRowi=atoi(str3.GetBuffer(0));
m_gridCtrl.SetRow(iRowi);
m_gridCtrl.SetCol(1);
if(m_gridCtrl.GetCellBackColor()==m_gridCtrl.GetBackColorSel())
{
for(i=1;i<iCols;i++)
{
m_gridCtrl.SetCol(long(i));
m_gridCtrl.SetCellBackColor(RGB(0xFF,0xFF,0xFF));
m_gridCtrl.SetCellForeColor(RGB(0,0,0));
}
}
iResid=str2.GetLength()-ips2-1;
if(iResid>0)
{
str2=str2.Mid(ips2+1,iResid);
ips2=str2.Find(";");
}
else
{str2="";ips2=-1;}
}
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetCol(iCol);
m_gridCtrl.SetColSel(iColSel);
strRowSel.Format(";%d;",iRow);
} //"Ctrl" is not pushed
}// for Whole Row is selected
//**************************
//Below for only Cell or Cell Range is selected
else
{
bMultiSel=true;
str2=strColSel.Mid(1,strColSel.GetLength()-1);
ips2=str2.Find(":");
while(ips2!=-1)
{
str3=str2.Mid(0,ips2);
iColi=atoi(str3.GetBuffer(0));
m_gridCtrl.SetCol(iColi);
m_gridCtrl.SetRow(1);
if(m_gridCtrl.GetCellBackColor()==m_gridCtrl.GetBackColorSel())
{
for(i=1;i<iRows;i++)
{
m_gridCtrl.SetRow(long(i));
m_gridCtrl.SetCellBackColor(RGB(0xFF,0xFF,0xFF));
m_gridCtrl.SetCellForeColor(RGB(0,0,0));
}
}
iResid=str2.GetLength()-ips2-1;
if(iResid>0)
{
str2=str2.Mid(ips2+1,iResid);
ips2=str2.Find(":");
}
else
{str2="";ips2=-1;}
}
bMultiSel=false;
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetCol(iCol);
m_gridCtrl.SetRowSel(iRowSel);
m_gridCtrl.SetColSel(iColSel);
strColSel=":";
//above to Recover selected Columns to Normal state
str2=strRowSel.Mid(1,strRowSel.GetLength()-1);
ips2=str2.Find(";");
while(ips2!=-1)
{
str3=str2.Mid(0,ips2);
iRowi=atoi(str3.GetBuffer(0));
m_gridCtrl.SetRow(iRowi);
m_gridCtrl.SetCol(1);
if(m_gridCtrl.GetCellBackColor()==m_gridCtrl.GetBackColorSel())
{
for(i=1;i<iCols;i++)
{
m_gridCtrl.SetCol(long(i));
m_gridCtrl.SetCellBackColor(RGB(0xFF,0xFF,0xFF));
m_gridCtrl.SetCellForeColor(RGB(0,0,0));
}
}
iResid=str2.GetLength()-ips2-1;
if(iResid>0)
{
str2=str2.Mid(ips2+1,iResid);
ips2=str2.Find(";");
}
else
{str2="";ips2=-1;}
}
bMultiSel=false;
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetCol(iCol);
m_gridCtrl.SetRowSel(iRowSel);
m_gridCtrl.SetColSel(iColSel);
strRowSel=";";
//above to Recover selected Rows to Normal state
}// for only Cell or Cell Range is selected
}
void CEditiDlg::OnmnuBackColor()
{
// TODO: Add your command handler code here
bool iSelect=true;
SetCellColor(iSelect);
}
void CEditiDlg::OnmnuForeColor()
{
// TODO: Add your command handler code here
bool iSelect=false;
SetCellColor(iSelect);
}
void CEditiDlg::SetCellColor(bool iSelect)
{
COLORREF m_newColor;
CColorDialog colorDlg; //构造颜色通用对话框
if(colorDlg.DoModal())
{
m_newColor = colorDlg.GetColor(); //获得颜色
/*
Invalidate(); //刷新窗口
int iColorRed, iColorGreen, iColorBlue;
iColorRed=GetRValue(m_newColor);
iColorGreen=GetGValue(m_newColor);
iColorBlue=GetBValue(m_newColor);
*/
long iRow,iCol,iRowSel,iColSel;
iRow=m_gridCtrl.GetRow(); iCol=m_gridCtrl.GetCol();
iRowSel=m_gridCtrl.GetRowSel(); iColSel=m_gridCtrl.GetColSel();
long iRowStart,iRowEnd,iColStart,iColEnd;
if(iRow<=iRowSel)
{
iRowStart=iRow; iRowEnd=iRowSel;
}
else
{
iRowStart=iRowSel; iRowEnd=iRow;
}
if(iCol<=iColSel)
{
iColStart=iCol; iColEnd=iColSel;
}
else
{
iColStart=iColSel; iColEnd=iCol;
}
bMultiSel=true;
int i,j;
for(i=iRowStart;i<=iRowEnd;i++)
{
m_gridCtrl.SetRow(i);
for(j=iColStart;j<=iColEnd;j++)
{
m_gridCtrl.SetCol(j);
if(iSelect)
{
m_gridCtrl.SetCellBackColor(m_newColor);
}
else
{
m_gridCtrl.SetCellForeColor(m_newColor);
}
}
}
bMultiSel=false;
if(iRowEnd!=iRow) m_gridCtrl.SetRow(iRow);
if(iColEnd!=iCol) m_gridCtrl.SetCol(iCol);
if(m_edit->GetSafeHwnd()!=NULL) m_edit->DestroyWindow(); //销毁编辑框窗口
m_gridCtrl.SetRowSel(iRowSel);
m_gridCtrl.SetColSel(iColSel);
}
}
void CEditiDlg::OnmnuRowInsert()
{
// TODO: Add your command handler code here
//It need to remove the Selected Rows or Columns first, Recover to original color
CString str,str2; int ips2,i;
CString str3; int iResid; int iRowi; //int iColi;
long iRow,iCol,iRows, iCols, iRowSel,iColSel;
iRow=m_gridCtrl.GetRow(); iCol=m_gridCtrl.GetCol();
iRows=m_gridCtrl.GetRows(); iCols=m_gridCtrl.GetCols();
iRowSel=m_gridCtrl.GetRowSel(); iColSel=m_gridCtrl.GetColSel();
str2=strRowSel.Mid(1,strRowSel.GetLength()-1);
ips2=str2.Find(";");
while(ips2!=-1)
{
str3=str2.Mid(0,ips2);
iRowi=atoi(str3.GetBuffer(0));
m_gridCtrl.SetRow(iRowi);
m_gridCtrl.SetCol(1);
if(m_gridCtrl.GetCellBackColor()==m_gridCtrl.GetBackColorSel())
{
for(i=1;i<iCols;i++)
{
m_gridCtrl.SetCol(long(i));
m_gridCtrl.SetCellBackColor(RGB(0xFF,0xFF,0xFF));
m_gridCtrl.SetCellForeColor(RGB(0,0,0));
}
}
iResid=str2.GetLength()-ips2-1;
if(iResid>0)
{
str2=str2.Mid(ips2+1,iResid);
ips2=str2.Find(";");
}
else
{str2="";ips2=-1;}
}
bMultiSel=false;
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetCol(iCol);
m_gridCtrl.SetRowSel(iRowSel);
m_gridCtrl.SetColSel(iColSel);
strRowSel=";";
//above to Recover selected Rows to Normal state
m_gridCtrl.SetRows(iRows+1);
str.Format("%d",iRows);
m_gridCtrl.SetTextMatrix(iRows,0, str);
CString strClipbord;
bMultiSel=true;
m_gridCtrl.SetCol(1);
m_gridCtrl.SetRow(iRows-1);
m_gridCtrl.SetColSel(m_gridCtrl.GetCols()-1);
strClipbord=m_gridCtrl.GetClip();
m_gridCtrl.SetRow(iRows);
m_gridCtrl.SetColSel(m_gridCtrl.GetCols()-1);
m_gridCtrl.SetClip(strClipbord);
m_gridCtrl.SetRowHeight(iRows,260);
for(i=0;i<iCols;i++)
{
m_gridCtrl.SetCol(i);
m_gridCtrl.SetCellAlignment(4);
}
m_gridCtrl.SetCellForeColor(m_gridCtrl.GetBackColorSel());
m_gridCtrl.SetCol(1);
for(i=iRows-2;i>=iRow;i--)
{
m_gridCtrl.SetRow(i);
m_gridCtrl.SetColSel(m_gridCtrl.GetCols()-1);
strClipbord=m_gridCtrl.GetClip();
m_gridCtrl.SetRow(i+1);
m_gridCtrl.SetColSel(m_gridCtrl.GetCols()-1);
m_gridCtrl.SetClip(strClipbord);
}
for(i=1;i<iCols;i++)
{
m_gridCtrl.SetTextMatrix(iRow,i,"");
}
bMultiSel=false;
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetColSel(m_gridCtrl.GetCols()-1);
}
void CEditiDlg::OnmnuRowDelete()
{
// TODO: Add your command handler code here
//It need to remove the Selected Rows or Columns first, Recover to original color
CString str,str2; int ips2,i;
CString str3; int iResid; int iRowi; //int iColi;
long iRow,iCol,iRows, iCols, iRowSel,iColSel;
iRow=m_gridCtrl.GetRow(); iCol=m_gridCtrl.GetCol();
iRows=m_gridCtrl.GetRows(); iCols=m_gridCtrl.GetCols();
iRowSel=m_gridCtrl.GetRowSel(); iColSel=m_gridCtrl.GetColSel();
str2=strRowSel.Mid(1,strRowSel.GetLength()-1);
ips2=str2.Find(";");
while(ips2!=-1)
{
str3=str2.Mid(0,ips2);
iRowi=atoi(str3.GetBuffer(0));
m_gridCtrl.SetRow(iRowi);
m_gridCtrl.SetCol(1);
if(m_gridCtrl.GetCellBackColor()==m_gridCtrl.GetBackColorSel())
{
for(i=1;i<iCols;i++)
{
m_gridCtrl.SetCol(long(i));
m_gridCtrl.SetCellBackColor(RGB(0xFF,0xFF,0xFF));
m_gridCtrl.SetCellForeColor(RGB(0,0,0));
}
}
iResid=str2.GetLength()-ips2-1;
if(iResid>0)
{
str2=str2.Mid(ips2+1,iResid);
ips2=str2.Find(";");
}
else
{str2="";ips2=-1;}
}
bMultiSel=false;
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetCol(iCol);
// m_gridCtrl.SetRowSel(iRowSel);
m_gridCtrl.SetColSel(iColSel);
strRowSel=";";
//above to Recover selected Rows to Normal state
if(iRows==2)
{
MessageBox("There is Only One effective row!\nCannot remove this row!");
return;
}
if(iRow==iRows-1)
{
//if(m_edit->GetSafeHwnd()!=NULL) m_edit->DestroyWindow(); //销毁编辑框窗口
m_gridCtrl.SetRow(iRow-1);
m_gridCtrl.SetColSel(m_gridCtrl.GetCols()-1);
m_gridCtrl.RemoveItem(iRow);
}
else
{
m_gridCtrl.RemoveItem(iRow);
if(m_edit->GetSafeHwnd()!=NULL) m_edit->DestroyWindow(); //销毁编辑框窗口
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetColSel(m_gridCtrl.GetCols()-1);
}
for(i=iRow;i<iRows-1;i++)
{
str.Format("%d",i);
m_gridCtrl.SetTextMatrix(i,0, str);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -