MFC 控件通知处理函数:添加和删除区域
该代码是 MFC(Microsoft Foundation Class)框架下的控件通知处理函数,用于处理用户在对话框界面中点击'添加新区域'和'删除当前区域'按钮的操作。
函数 OnChooseNew() 的作用是添加新的区域。首先将全局变量 Areas(表示当前已有多少个区域)加一,然后根据新的区域编号和颜色信息,生成一个新的字符串 str,用于在界面中显示。最后将该字符串添加到列表框控件中。
函数 OnChooseDel() 的作用是删除当前选定的区域。首先获取当前选定的区域在列表框中的索引 nIndex,然后根据该索引获取该区域的信息字符串 string。接着从该字符串中提取出区域编号 str1,以便后续操作。然后获取当前活动的文档视图 CBsqViewView,并通过该视图访问其父窗口 CMainFrame 中的成员变量 bigdlg(表示主窗口中的对话框)。将要删除的区域编号存入 bigdlg 的成员变量 DelAreas 中,并将该区域的标记(即 AreasBool[DelAreas])设置为 false。然后从列表框中删除该区域的信息字符串,并调用 bigdlg 的 Invalidate() 函数,使其重新绘制。
void CChooseAreas::OnChooseNew()
{
// TODO: Add your control notification handler code here
Areas++;
CString str;
str.Format('区域 #%d [%s] 0个点', Areas, ColorString[Areas]);
m_list.AddString(str);
}
void CChooseAreas::OnChooseDel()
{
// TODO: Add your control notification handler code here
int nIndex;
nIndex=m_list.GetCurSel();
CString string;
m_list.GetText(nIndex,string);
CString str='123456789';
CString str1='';
int n=string.FindOneOf(str);
while(string.GetAt(n)!='[')
{
str1+=string.GetAt(n);
string.Delete(n,1);
}
CMainFrame* pframe = (CMainFrame *)AfxGetApp()->GetMainWnd();
CMDIChildWnd* pChildWnd = pframe->MDIGetActive();
CBsqViewView* pView = (CBsqViewView *) pChildWnd->GetActiveView();
pView->bigdlg->DelAreas=atoi(str1);
pView->bigdlg->AreasBool[pView->bigdlg->DelAreas]=false;
m_list.DeleteString(nIndex);
pView->bigdlg->Invalidate();
}
原文地址: https://www.cveoy.top/t/topic/jlXA 著作权归作者所有。请勿转载和采集!