📄 editidlg.cpp
字号:
//通过给内存句柄加锁,获得指向指定格式数据的指针
char *pchData = (char*)GlobalLock(hClipboardData);
//本地变量获得数据
CString strFromClipboard = pchData;
int n; CString str0;
str0="";
str0=str0+char(13)+char(10)+":";
n = strFromClipboard.Replace(str0.Mid(0,2), str0.Mid(0,1));
if(m_edit->GetSafeHwnd()!=NULL) m_edit->DestroyWindow(); //销毁编辑框窗口
m_gridCtrl.SetClip(strFromClipboard);
GlobalUnlock(hClipboardData); //给内存句柄解锁
}
else
{
AfxMessageBox("There is no text (ANSI) data on the Clipboard.");
}
CloseClipboard(); //使用完后关闭剪贴板
}
}
void CEditiDlg::OnScrollMsflexgrid1()
{
// TODO: Add your control notification handler code here
//销毁编辑框窗口
if (m_edit->GetSafeHwnd()!=NULL)
m_edit->DestroyWindow();
}
void CEditiDlg::OnBtnSetCellAlignment()
{
// TODO: Add your control notification handler code here
m_AlignHV=m_gridCtrl.GetCellAlignment();
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;
}
CDlgAlignment CDlg;
CDlg.DoModal(); //调出设置Cell内文本对齐方式对话框
int i,j;
for(i=iRowStart;i<=iRowEnd;i++)
{
m_gridCtrl.SetRow(i);
for(j=iColStart;j<=iColEnd;j++)
{
m_gridCtrl.SetCol(j);
m_gridCtrl.SetCellAlignment(m_AlignHV);
}
}
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::OnBtnColor()
{
// TODO: Add your control notification handler code here
CRect oRect(0,0,0,0);
CWnd* pWnd = this->GetDlgItem(IDC_BtnColor);
ASSERT(pWnd);
pWnd->GetWindowRect(&oRect);
CPoint point;
point.x = oRect.left+(oRect.right-oRect.left)/2;
point.y = oRect.top+(oRect.bottom-oRect.top)/2;
CMenu* pPopMenu = new CMenu;
pPopMenu->LoadMenu(IDR_mnuColor);
CMenu* pFileMenu = pPopMenu->GetSubMenu(0);
pFileMenu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this);
delete pPopMenu;
}
void CEditiDlg::OnBtnClear()
{
// TODO: Add your control notification handler code here
if(m_edit->GetSafeHwnd()!=NULL) m_edit->DestroyWindow(); //销毁编辑框窗口
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++)
for(j=iColStart;j<=iColEnd;j++)
{
m_gridCtrl.SetTextMatrix(i,j,"");
}
// bMultiSel=false;
}
void CEditiDlg::OnReleasedcaptureCellSize(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
// MessageBox("CGridi0Dlg::OnReleasedcaptureCellSize");
// Invalidate(TRUE);
*pResult = 0;
}
void CEditiDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
//不是拖动的消息不处理
if(nSBCode != SB_THUMBTRACK) return;
//to Adjust if the selection of Cell Range is effective
long iRow,iCol,iRowSel,iColSel,iRows,iCols;
iRow=m_gridCtrl.GetRow(); iCol=m_gridCtrl.GetCol();
iRows=m_gridCtrl.GetRows(); iCols=m_gridCtrl.GetCols();
iRowSel=m_gridCtrl.GetRowSel(); iColSel=m_gridCtrl.GetColSel();
if((iRowSel==iRows-1) && (iRow==1) && (iCol==iColSel))
{
if(m_edit->GetSafeHwnd()!=NULL) m_edit->DestroyWindow(); //销毁编辑框窗口
long iColWidth;
iColWidth=long(nPos/10.0*iColWidth0);
m_gridCtrl.SetColWidth(iCol,iColWidth);
m_gridCtrl.Refresh();
CRect oRect(0,0,0,0);
CWnd* pWnd = this->GetDlgItem(IDC_MSFLEXGRID1);
ASSERT(pWnd);
pWnd->GetWindowRect(&oRect);
this->ScreenToClient(&oRect);
CPoint point;
point.x= oRect.left;
point.y= oRect.top;
if(m_timerID != 0)
{
KillTimer(m_timerID);
m_timerID=0;
}
//Below for ToolTip of Column Width
m_toolTip.Create(this);
CStringArray straInfo;
CString str;
str.Format("Width: %d",iColWidth);
straInfo.RemoveAll();
straInfo.Add(str);
// m_toolTip.AddControlInfo(IDC_MSFLEXGRID1, straInfo, RGB(0xFF,0xFF,0xE1));
m_toolTip.AddControlInfo(IDC_MSFLEXGRID1, straInfo, RGB(255,255,0));
m_toolTip.ShowToolTip((CPoint)point);
// set the timer to fire after 2 seconds
if(m_timerID==0)
m_timerID = this->SetTimer(1,2000,NULL);
}
else if((iColSel==iCols-1) && (iCol==1) && (iRow==iRowSel))
{
if(m_edit->GetSafeHwnd()!=NULL) m_edit->DestroyWindow(); //销毁编辑框窗口
long iRowHeight;
iRowHeight=long(nPos/10.0*iRowHeight0);
m_gridCtrl.SetRowHeight(iRow,iRowHeight);
CRect oRect(0,0,0,0);
CWnd* pWnd = this->GetDlgItem(IDC_MSFLEXGRID1);
ASSERT(pWnd);
pWnd->GetWindowRect(&oRect);
this->ScreenToClient(&oRect);
CPoint point;
point.x= oRect.left;
point.y= oRect.top;
if(m_timerID != 0)
{
KillTimer(m_timerID);
m_timerID=0;
}
//Below for ToolTip of Column Width
m_toolTip.Create(this);
CStringArray straInfo;
CString str;
str.Format("Height: %d",iRowHeight);
straInfo.RemoveAll();
straInfo.Add(str);
m_toolTip.AddControlInfo(IDC_MSFLEXGRID1, straInfo, RGB(255,255,0));
m_toolTip.ShowToolTip((CPoint)point);
// set the timer to fire after 2 seconds
if(m_timerID==0) m_timerID = this->SetTimer(1,2000,NULL);
}
else
{
MessageBox("The selected is not a Row or Column!");
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CEditiDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//设定滚动条的滚动范围和初始位置
CSliderCtrl* pCellSize = (CSliderCtrl*)GetDlgItem(IDC_CellSize);
//pCellSize->SetRange(0,20);
pCellSize->SetPos(10);
iColWidth0=m_gridCtrl.GetColWidth(m_gridCtrl.GetCol());
iRowHeight0=m_gridCtrl.GetRowHeight(m_gridCtrl.GetRow());
Invalidate(TRUE);
MessageBox("CGridi0Dlg::OnTimer(UINT nIDEvent)");
if(m_timerID != 0)
{
KillTimer(m_timerID);
m_timerID=0;
}
CDialog::OnTimer(nIDEvent);
}
void CEditiDlg::OnClickMsflexgrid1()
{
// TODO: Add your control notification handler code here
short ks;
ks=GetKeyState(VK_CONTROL);
// if(ks&0xF000) MessageBox("In CGridi0Dlg::OnDblClickMsflexgrid1()");
bool iCtrlKey=false;
if(ks&0xF000) iCtrlKey=true;
CString str,str2; int ips,ips2,i;
CString str3; int num,iResid; int iColi, iRowi;
//to Adjust if the selection of Cell Range is effective
long iRow,iCol,iRowSel,iColSel,iRows,iCols;
iRow=m_gridCtrl.GetRow(); iCol=m_gridCtrl.GetCol();
iRows=m_gridCtrl.GetRows(); iCols=m_gridCtrl.GetCols();
iRowSel=m_gridCtrl.GetRowSel(); iColSel=m_gridCtrl.GetColSel();
if((iRowSel==iRows-1) && (iRow==1) && (iCol==iColSel))
{
bMultiSel=true;
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.SetColSel(iColSel);
strRowSel=";";
//above to Recover selected Rows to Normal state
if(iCtrlKey)
{
if(strColSel=="") strColSel=":";
str.Format("%d:",iCol);
ips=strColSel.Find(":"+str);
if(ips!=-1)
{
ips2=ips+str.GetLength();
str2=strColSel.Mid(0,ips)+strColSel.Mid(ips2,strColSel.GetLength()-ips2);
strColSel=str2;
num=-1;
str2=strColSel.Mid(1,strColSel.GetLength()-1);
ips2=str2.Find(":");
while(ips2!=-1)
{
num=num+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(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.SetRowSel(iRowSel);
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));
}
m_gridCtrl.SetRow(iRow);
if(str2==":") m_gridCtrl.SetRowSel(iRow);
}
else
{
str2=strColSel.Mid(0,strColSel.GetLength()-1);
ips2=str2.ReverseFind(char(0x3A)); // char(0x3A)-- ":"
if(ips2!=-1)
{
ips2=ips2+1;
str3=str2.Mid(ips2,str2.GetLength()-ips2);
iColi=atoi(str3.GetBuffer(0));
m_gridCtrl.SetCol(iColi);
for(i=1;i<iRows;i++)
{
m_gridCtrl.SetRow(long(i));
m_gridCtrl.SetCellBackColor(m_gridCtrl.GetBackColorSel());
m_gridCtrl.SetCellForeColor(m_gridCtrl.GetForeColorSel());
}
}
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetCol(iCol);
m_gridCtrl.SetRowSel(iRowSel);
strColSel=strColSel+str;
}
MessageBox(strColSel);
} //"Ctrl" is pushed
else
{
str2="";
if(strColSel!="")
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;}
}
m_gridCtrl.SetRow(iRow);
m_gridCtrl.SetCol(iCol);
m_gridCtrl.SetRowSel(iRowSel);
strColSel.Format(":%d:",iCol);
} //"Ctrl" is not pushed
bMultiSel=false;
} // for Whole Col is selcted
//**************************
//Below for Whole Rows is selected
else if((iColSel==iCols-1) && (iCol==1) && (iRow==iRowSel))
{
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())
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -