⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 一个简单的个人所得税计算器,可以编辑税率表和所在地列表.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	pCmdUI->Enable(m_bCessDelete);
}

void CMainFrame::OnUpdateCessEdit(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_bCessEdit);
}

void CMainFrame::OnAreaAdd() 
{
	// TODO: Add your command handler code here
	areaFlag="ADD";
    CAreaDlg dlg;
	dlg.DoModal();
}



void CMainFrame::OnAreaClear() 
{
	// TODO: Add your command handler code here
	CString str;
	str="确认要删除所在地列表中所有的数据吗?";
	if (MessageBox(str,"用户信息",MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2)==IDNO)
		    return;
    CListCtrl *pListCtrl;
	pListCtrl=&(this->m_pConfigViewArea->m_wndListCtrlArea);
	if(pListCtrl->GetItemCount()>0)
	{
	    pListCtrl->DeleteAllItems();
	    modified=TRUE;

	    this->m_pComputView->UpdateDisplay();
	}
	
    
}

void CMainFrame::OnAreaDelete() 
{
	// TODO: Add your command handler code here
	CListCtrlArea *pListCtrl;
	pListCtrl=(CListCtrlArea *)(&(this->m_pConfigViewArea->m_wndListCtrlArea));
	int count=pListCtrl->GetSelectedCount();
	if(0==count)
	{
		AfxMessageBox("请在所在地列表中选中一行要删除的数据!");
		return ;
	}
	
    POSITION pos = pListCtrl->GetFirstSelectedItemPosition();
	int m=pListCtrl->GetNextSelectedItem(pos);
	CString str;
	str.Format("确认要删除所在地列表第%d行数据吗?",m+1);
	if (MessageBox(str,"用户信息",MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2)==IDNO)
		    return;
	
	pListCtrl->DeleteItem(m);
	modified=TRUE;
	////
	this->m_pComputView->UpdateDisplay();  
    
}

void CMainFrame::OnUpdateAreaDelete(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_bAreaDelete);
}

void CMainFrame::OnAreaEdit() 
{
	// TODO: Add your command handler code here
	CListCtrlArea *pListCtrl;
	pListCtrl=(CListCtrlArea *)(&(this->m_pConfigViewArea->m_wndListCtrlArea));
	int count=pListCtrl->GetSelectedCount();
	if(0==count)
	{
		AfxMessageBox("请在所在地列表中选中一行要修改的数据!");
		return ;
	}
	////
	areaFlag="EDIT";
    CAreaDlg dlg;
	dlg.DoModal();
	this->m_pComputView->UpdateDisplay();
    
}

void CMainFrame::OnUpdateAreaEdit(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_bAreaEdit);
}

void CMainFrame::OnKromo() 
{
	// TODO: Add your command handler code here
	LoadSkinFromResource( AfxGetInstanceHandle()  , "KROMO" ,"SKINMAGIC") ; 
	if( !m_bSkinned )
	{
		VERIFY( 1 == SetWindowSkin( m_hWnd , "MainFrame" ));
		VERIFY( 1 == SetDialogSkin( "Dialog" ) );
		m_nIndex = 0 ;
	}	
	
	m_nIndex = 0;
}

void CMainFrame::OnUpdateKromo(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_nIndex == 0 );
}

void CMainFrame::OnDevior() 
{
	// TODO: Add your command handler code here
	LoadSkinFromResource( AfxGetInstanceHandle()  , "DEVIOR" ,"SKINMAGIC") ; 	
    m_nIndex = 1;
}

void CMainFrame::OnUpdateDevior(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_nIndex == 1 );
}

void CMainFrame::OnCorona() 
{
	// TODO: Add your command handler code here
	LoadSkinFromResource( AfxGetInstanceHandle()  , "CORONA" ,"SKINMAGIC") ; 	
    m_nIndex = 2;
}

void CMainFrame::OnUpdateCorona(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_nIndex == 2 );
}

void CMainFrame::OnCalc() 
{
	// TODO: Add your command handler code here
	WinExec("calc",SW_SHOW);
}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if(modified)
	{
		CString str="配置文件已修改,要保存吗?";
		int message;
		message=MessageBox(str,"用户信息",MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON1);
		if (message==IDYES)
		{
		    BOOL flag;
		    flag=SaveModified();
		    if(flag==FALSE)//取消保存或者保存失败
			    return;
		}
		else if(message==IDCANCEL)
			return;
	}
    //////////////////
	CFrameWnd::OnClose();
}

void CMainFrame::OnConfigNew() 
{
	// TODO: Add your command handler code here
	if(modified)
	{
		CString str="配置文件已修改,要保存吗?";
		int message;
		message=MessageBox(str,"用户信息",MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON1);
		if (message==IDYES)
		{
		    BOOL flag;
		    flag=SaveModified();
		    if(flag==FALSE)//取消保存或者保存失败
			    return;
		}
		else if(message==IDCANCEL)
			return;
	}

	////
	if(m_pConfigDoc->OnNewDocument())
 	{
		modified=FALSE;
		pathname="";
		//m_pConfigViewCess->m_wndListCtrlCess.DeleteAllItems();
		//m_pConfigViewArea->m_wndListCtrlArea.DeleteAllItems();
 	    //this->m_pConfigViewCess->m_wndListCtrlCess.m_cToolTipCtrl.UpdateTipText("新建未命名配置",&(this->m_pConfigViewCess->m_wndListCtrlCess));
 	    this->m_pComputView->UpdateDisplay();
		CString title;
		title.LoadString(AFX_IDS_APP_TITLE);
		title=title+"-"+m_pConfigDoc->GetTitle();
		this->SetWindowText(title);
 	}
	////
	m_bCessEdit=m_bCessDelete=m_bAreaEdit=m_bAreaDelete=FALSE;
	
}

void CMainFrame::OnConfigLoad() 
{
	// TODO: Add your command handler code here
	////
	if(modified)
	{
		CString str="配置文件已修改,要保存吗?";
		int message;
		message=MessageBox(str,"用户信息",MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON1);
		if (message==IDYES)
		{
		    BOOL flag;
		    flag=SaveModified();
		    if(flag==FALSE)//取消保存或者保存失败
			    return;
		}
		else if(message==IDCANCEL)
			return;
	}
	////
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
 					"配置文件(*.pit)|*.pit||" );
 	CString path,name;
 	dlg.m_ofn.lpstrTitle="加载配置文件";
	do
	{
		if(dlg.DoModal() == IDOK)
		{
 		    path = dlg.GetPathName(); //获取文件路径
			name=dlg.GetFileName();
		}
	    else
		{
		    return;
		}
	}
	while(!m_pConfigDoc->OnOpenDocument(path));//直到加载成功

	filename=name;
	CString title;
	title.LoadString(AFX_IDS_APP_TITLE);
	title=title+"-"+filename;
	this->SetWindowText(title);
	//////////////
		pathname=path;
		modified=FALSE;
	    ////
 	    FilePath pitfilepath;
	    pitfilepath=((CPITCApp*)AfxGetApp())->GetExeFilePath();
	    ::WritePrivateProfileString("Load","PITFileName",pathname,pitfilepath.driver+pitfilepath.dir+"config.ini");
    
	    ///
        //this->m_pConfigViewCess->m_wndListCtrlCess.m_cToolTipCtrl.UpdateTipText(filename,&(this->m_pConfigViewCess->m_wndListCtrlCess));
	    this->m_pComputView->UpdateDisplay();

		////
		m_bCessEdit=m_bCessDelete=m_bAreaEdit=m_bAreaDelete=FALSE;
	
}


void CMainFrame::OnConfigSaveas() 
{
	// TODO: Add your command handler code here
	DoFileSave(TRUE);
}

BOOL CMainFrame::SaveModified()//保存修改后的文件
{
	
	if(pathname=="")//如果是新建(未命名)的文件
	{
		CString filename;
		return DoFileSave(FALSE);//弹出对话框输入文件名
	}
	else//已存在(有文件名)的文件
	{
		return (DoSave(pathname));
	}

}

BOOL CMainFrame::DoFileSave(BOOL isSaveAs)//弹出对话框
{
	CFileDialog dlg(FALSE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
 					"配置文件(*.pit)|*.pit||" );
 	CString name,path;
	if (isSaveAs)
	    dlg.m_ofn.lpstrTitle="配置文件另存为";
	else
        dlg.m_ofn.lpstrTitle="保存配置文件";
 	if(dlg.DoModal() == IDOK)
 	{
 		  path = dlg.GetPathName(); //获取文件路径
		  name=dlg.GetFileName();
		  path.TrimRight();
		  CString filter;
		  filter=path.Right(4);
		  filter.MakeLower();
		  if(filter!=".pit")//点击一个已经存在的文件,pathname会包含这个文件的名称以及后缀名。  
		  {
			  path += ".pit";
			  name+=".pit";
		  }
          filename=name;
		  return DoSave(path);
	}
	else
	{
		return FALSE;
	}
	

}

BOOL CMainFrame::DoSave(CString filepathname)//保存文件
{
	if(m_pConfigDoc->OnSaveDocument(filepathname))
	{
		modified=FALSE;
		pathname=filepathname;
		FilePath pitfilepath;
	    pitfilepath=((CPITCApp*)AfxGetApp())->GetExeFilePath();
	    ::WritePrivateProfileString("Load","PITFileName",filename,pitfilepath.driver+pitfilepath.dir+"config.ini");
    
		this->m_pConfigViewCess->m_wndListCtrlCess.m_cToolTipCtrl.UpdateTipText(filepathname,&(this->m_pConfigViewCess->m_wndListCtrlCess));
	    this->m_pComputView->UpdateDisplay();
		
		CString title;
		title.LoadString(AFX_IDS_APP_TITLE);
		title=title+"-"+GetNameFromPath(filepathname);
		this->SetWindowText(title);
		
		return TRUE;//保存成功
	}
	else
	{
		return FALSE;//保存失败
	}

}

HMENU CMainFrame::NewDefaultMenu()
{
	m_menu.LoadMenu(IDR_MAINFRAME);
	m_menu.LoadToolbar(IDR_MENU);
	
	////////
	return(m_menu.Detach());
}

void CMainFrame::OnComputviewReset() 
{
	// TODO: Add your command handler code here
	this->m_pComputView->OnInitialUpdate();
}


CString CMainFrame::GetNameFromPath(CString path)
{
	path.TrimLeft();
	path.TrimRight();

	if(path=="")
	{
		return "";
	}
	CString name;
	
	int i,pos,len;
	pos=-1;
	len=path.GetLength();
	for(i=len-1;i>=0;i--)
	{
		if(path.Mid(i,1)=="\\")
		{
			pos=i;
			break;
		}
	}
	if(pos!=-1)
	{
		name=path.Mid(pos+1);
	}

	CString str;
	str.Format("path=%s,name=%s",path,name);
	//AfxMessageBox(str);

	return name;


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -