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

📄 yszmrkdlg.cpp

📁 这是一套学校设备管理系统的源码 里面有树形结构使用的很棒的方法
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{
	// TODO: Add extra validation here
	CWnd *wn_pyjx;
	CWnd *wn_sbmc;
	CWnd *wn_rkfs;
	CWnd *wn_sfdzp;
	CWnd *wn_cjpp;
	CWnd *wn_xhgg;
	CWnd *wn_wpdj;
	CWnd *wn_wpsl;
	CWnd *wn_zje;
	CWnd *wn_ssbm;
	CWnd *wn_jbr;
	CWnd *wn_ghdw;
	CWnd *wn_gdbh;
	CWnd *wn_jfxs;
	CWnd *wn_yzf;
	CWnd *wn_rkn;
	CWnd *wn_rky;
	CWnd *wn_rkr;
	CWnd *wn_save;

    wn_pyjx = GetDlgItem(IDC_byjx);
    wn_sbmc = GetDlgItem(IDC_sbmc);
    wn_rkfs = GetDlgItem(IDC_rkfs);
    wn_sfdzp= GetDlgItem(IDC_sfdzp);
    wn_cjpp = GetDlgItem(IDC_cjpp);
    wn_xhgg = GetDlgItem(IDC_xhgg);
    wn_wpdj = GetDlgItem(IDC_wpdj);
    wn_wpsl = GetDlgItem(IDC_wpsl);
    wn_zje  = GetDlgItem(IDC_zje);
    wn_ssbm = GetDlgItem(IDC_ssbm);
    wn_jbr  = GetDlgItem(IDC_jbr);
    wn_ghdw = GetDlgItem(IDC_ghdw);
    wn_gdbh = GetDlgItem(IDC_gdbh);
    wn_jfxs  = GetDlgItem(IDC_jfxs);
    wn_yzf  = GetDlgItem(IDC_yzf);
    wn_rkn  = GetDlgItem(IDC_rkn);
    wn_rky  = GetDlgItem(IDC_rky);
    wn_rkr  = GetDlgItem(IDC_rkr);
    wn_save = GetDlgItem(IDSAVE);
    

	if (cur_focus == 1){
		wn_sbmc->SetFocus();
		cur_focus = 2;
		return ;
    }
	if (cur_focus == 2){
		wn_gdbh->SetFocus();
		cur_focus = 12;
		return ;
    }
	if (cur_focus == 12){
		wn_rkfs->SetFocus();
		cur_focus = 3;
		return ;
    }
//	if (cur_focus == 3){
//		wn_sfdzp->SetFocus();
//		cur_focus = 4;
//		return ;
//    }
	if (cur_focus == 3){
		wn_cjpp->SetFocus();
		cur_focus = 5;
		return ;
    }
	if (cur_focus == 5){
		wn_xhgg->SetFocus();
		cur_focus = 6;
		return ;
    }
	if (cur_focus == 6){
		wn_wpdj->SetFocus();
		cur_focus = 7;
		return ;
    }
	if (cur_focus == 7){
		wn_wpsl->SetFocus();
		cur_focus = 8;
		return ;
    }
	if (cur_focus == 8){
		wn_zje->SetFocus();
		cur_focus = 9;
		return ;
    }
	if (cur_focus == 9){
		if (g_yszm_flag == 0){
		  wn_jfxs->SetFocus();
		  cur_focus = 13;
		}
		else{
		  wn_rkn->SetFocus();
		  cur_focus = 15;
		}
		return ;
    }
	if (cur_focus == 13){
		wn_rkn->SetFocus();
		cur_focus = 15;
		return ;
    }
	if (cur_focus == 15){
		wn_rky->SetFocus();
		cur_focus = 16;
		return ;
    }
	if (cur_focus == 16){
		wn_rkr->SetFocus();
		cur_focus = 17;
		return ;
    }
	if (cur_focus == 17){
		wn_ssbm->SetFocus();
		cur_focus = 20;
		return ;
    }
	if (cur_focus == 20){
		wn_ghdw->SetFocus();
		cur_focus = 11;
		return ;
    }
	if (cur_focus == 11){
		wn_jbr->SetFocus();
		cur_focus = 10;
		return ;
    }
	if (cur_focus == 10){
		if (g_yszm_flag == 0){
		  wn_yzf->SetFocus();
		  cur_focus = 14;
		}
		else{
		  wn_save->SetFocus();
		  cur_focus = 18;
		}
		return ;
    }
	if (cur_focus == 14){
		wn_save->SetFocus();
		cur_focus = 18;
		return ;
    }
	free_sbtree(m_tree);
	CDialog::OnCancel();
}

void Cyszmrkdlg::OnSetfocusrkfs() 
{
	// TODO: Add your control notification handler code here
	CWnd *wnd;

	wnd = GetDlgItem(IDC_rkfs);
	switch_to_chinese_mode(wnd);
	cur_focus = 3;	
}

void Cyszmrkdlg::OnSetfocusssbm() 
{
	// TODO: Add your control notification handler code here
	CWnd *wnd;

	wnd = GetDlgItem(IDC_rkfs);
	switch_to_english_mode(wnd);
	cur_focus = 20;		
}

void Cyszmrkdlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

BEGIN_EVENTSINK_MAP(Cyszmrkdlg, CDialog)
    //{{AFX_EVENTSINK_MAP(Cyszmrkdlg)
	ON_EVENT(Cyszmrkdlg, IDC_yszm, -602 /* KeyDown */, OnKeyDownyszm, VTS_PI2 VTS_I2)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void Cyszmrkdlg::OnKeydownTree1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR;
/*	// TODO: Add your control notification handler code here
	
	if (pTVKeyDown->wVKey == 113){
		OnSave();
    }
*/
	*pResult = 0;
}

void Cyszmrkdlg::OnKeyDownyszm(short FAR* KeyCode, short Shift) 
{
	// TODO: Add your control notification handler code here
/*	if (*KeyCode == 113){
		OnSave();
    }
*/
}

void yszm_load_sbs(CTreeCtrl &m_tree)
{
  FILE *fpe;

  if (g_come_in_flag == 0){
    g_come_in_flag = 1;
	if (g_yszm_flag == 1){
	  fpe = fopen("c:\\xxsbgl\\yszmbh.txt","rb");
	}
	else{
	  fpe = fopen("c:\\xxsbgl\\sbrkbh.txt","rb");
    }
	if (fpe == NULL){
		MessageBox(NULL,"","系统被破坏,请恢复备份数据.",MB_OK);
		return ;
    }
	fscanf(fpe,"%ld",&g_end_of_yszm);
	fclose(fpe);
	load_sbtree(m_tree);
  } 
}

void load_sbtree(CTreeCtrl &m_tree)
{
	HTREEITEM htreeitem;
	HTREEITEM h1,h2;
	char e_id_buf[50],e_code_buf[50],p_id_buf[50];
	char e_name_buf[50],e_abbr_buf[50],a_id_buf[50];
	char m_un_buf[50],c_pr_buf[50];
	char id_buf[7][3];
	int i,j,n,m;
	long order;
	int flag,flag1;
	int parent,ret;
	float ff;
	int tt;
	FILE *fpe;
	char buf2[100];

    g_cur_sb_search_pos = 0;
    g_old_htreeitem = NULL;

	fpe = fopen("c:\\xxsbgl\\sbqk.txt","rb");
	CImageList * pImageList;
    pImageList = new CImageList();
//	BOOL ret;

	ret = pImageList->Create(IDB_2,16,2,RGB(255,255,255));
    HICON hIcon;

	CWinApp *pApp;

    pApp = AfxGetApp();

	hIcon = pApp->LoadIcon(IDB_1);

	CBitmap* pbmImage;
	pbmImage = new CBitmap();
	ret = pbmImage->LoadBitmap(IDB_1);
	CBitmap* pbmImage1;
	pbmImage1 = new CBitmap();
	ret = pbmImage1->LoadBitmap(IDB_2);
	int t;
	t = pImageList->GetImageCount();
    pImageList->Add(pbmImage,RGB(255,255,255));
    pImageList->Add(pbmImage1,RGB(255,255,255));
	m_tree.SetImageList(pImageList,TVSIL_NORMAL);

	flag = 0;
	i = 0;
	while (flag == 0){
	  ret = get_a_line(fpe,g_e_id[i]);
	  if (ret == -1)
		  break;
	  get_a_line(fpe,g_e_code[i]);
	  get_a_line(fpe,g_p_id[i]);
	  get_a_line(fpe,g_e_name[i]);
	  get_a_line(fpe,g_e_abbr[i]);
	  get_a_line(fpe,g_a_id[i]);
	  get_a_line(fpe,g_m_un[i]);
	  get_a_line(fpe,g_c_pr[i]);
	  get_a_line(fpe,buf2);
	  g_parent[i] = atoi(buf2);
	  if (buf2[0] != '-'){
		  if ((buf2[0] < '0')||(buf2[0] > '9'))
			  j = 0;
	  }
	  order = i;
	  if (g_parent[i] == -1){
        g_htreeitem[i] = m_tree.InsertItem(0,"",0,0,TVIS_BOLD,0xff,order,NULL,TVI_LAST);
	    m_tree.SetItemImage(g_htreeitem[i],1,1);
      }
	  else{
        g_htreeitem[i] = m_tree.InsertItem(0,"",0,0,TVIS_BOLD,0xff,order,g_htreeitem[g_parent[i]],TVI_LAST);
      }
	  m_tree.SetItemText(g_htreeitem[i],g_e_name[i]);
	  DWORD dw;
	  dw = i;
	  m_tree.SetItemData(g_htreeitem[i],dw);
//	  m_tree.SetItemImage(g_htreeitem[i],1,1);
	  i ++;
	}
	fclose(fpe);
	g_end_sbs = i;
	for (i=0;i<g_end_sbs;i++){
	  if (g_parent[i] != -1){
        flag = 0;
        for (j=0;j<g_end_sbs;j++){
          if (g_parent[j] == i)
			  flag = 1;
        }
		if (flag == 0)
	      m_tree.SetItemImage(g_htreeitem[i],0,0);
		else
	      m_tree.SetItemImage(g_htreeitem[i],1,1);
	  }
    }

}

void free_sbtree(CTreeCtrl &m_tree)
{
	int i;
	HTREEITEM h,h1;
	UINT u;

//	m_tree.LockWindowUpdate();
	m_tree.ShowScrollBar(SB_CTL,FALSE);
	m_tree.DeleteAllItems();
//	m_tree.UnlockWindowUpdate();
	m_tree.ShowScrollBar(SB_CTL,TRUE);
}

void Cyszmrkdlg::OnItemexpandedTree1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	
	m_tree.Invalidate(TRUE);

	*pResult = 0;
}

void Cyszmrkdlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	free_sbtree(m_tree);
	CDialog::OnCancel();
}

void Cyszmrkdlg::OnSetfocusjfxs() 
{
	// TODO: Add your control notification handler code here
	CWnd *wnd;

	wnd = GetDlgItem(IDC_jfxs);
	switch_to_english_mode(wnd);	
	cur_focus = 13;
	
}

void Cyszmrkdlg::OnChangejfxs() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	double zje,jfxs,yzf,sjhf,xxhf;
	char buf[40];

	int l,i,flag,j;
	
	GetDlgItemText(IDC_jfxs,buf,12);
    l = strlen(buf);
	if (l > 0){
		if (l > 2){
			if ((buf[0] == '1')&&(buf[1] == '0')&&(buf[2] == '0')){
            }
			else{
			  buf[2] = 0;
	          SetDlgItemText(IDC_rkn,buf);
			  Set_to_item_end(this,IDC_jfxs);
            }
        }
		for (i=0;i<l;i++){
	      if ((buf[i] < '0')||(buf[i] > '9')){
		    buf[i] = 0;
	        SetDlgItemText(IDC_jfxs,buf);
			Set_to_item_end(this,IDC_jfxs);
		  }
		}
	}
	GetDlgItemText(IDC_zje,buf,12);
    zje = atof(buf);
	GetDlgItemText(IDC_jfxs,buf,12);
	jfxs = atof(buf);
	GetDlgItemText(IDC_yzf,buf,12);
	yzf = atof(buf);
    sjhf = zje*jfxs/100.;
	xxhf = zje*(100-jfxs)/100.+yzf;
	sprintf(buf,"%.2lf",sjhf);
	SetDlgItemText(IDC_sjhf,buf);
	sprintf(buf,"%.2lf",xxhf);
	SetDlgItemText(IDC_xxhf,buf);
}

void Cyszmrkdlg::OnSetfocusyzf() 
{
	// TODO: Add your control notification handler code here
	CWnd *wnd;

	wnd = GetDlgItem(IDC_yzf);
	switch_to_english_mode(wnd);	
	cur_focus = 14;
	
}

void Cyszmrkdlg::OnChangeyzf() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	double zje,jfxs,yzf,sjhf,xxhf;
	char buf[40];
	int l,i,flag,j;
	
	GetDlgItemText(IDC_yzf,buf,12);
    l = strlen(buf);
	if (l > 0){
		if (l > 8){
			buf[8] = 0;
	        SetDlgItemText(IDC_yzf,buf);
			Set_to_item_end(this,IDC_yzf);
        }
		for (i=0;i<l;i++){
	      if (((buf[i] < '0')||(buf[i] > '9'))&&(buf[i] != '.')){
		    buf[i] = 0;
	        SetDlgItemText(IDC_yzf,buf);
			Set_to_item_end(this,IDC_yzf);
		  }
		}
    }	
	GetDlgItemText(IDC_zje,buf,12);
    zje = atof(buf);
	GetDlgItemText(IDC_jfxs,buf,12);
	jfxs = atof(buf);
	GetDlgItemText(IDC_yzf,buf,12);
	yzf = atof(buf);
    sjhf = zje*jfxs/100.;
	xxhf = zje*(100-jfxs)/100.+yzf;
	sprintf(buf,"%.2lf",sjhf);
	SetDlgItemText(IDC_sjhf,buf);
	sprintf(buf,"%.2lf",xxhf);
	SetDlgItemText(IDC_xxhf,buf);
}

void Cyszmrkdlg::OnChangegdbh() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	char buf[20];
	int i;

	if (g_yszm_xzsb_flag == 0){
	  GetDlgItemText(IDC_gdbh,buf,20);
	  Cyszmxzsbdlg dlg;
	  g_yszm_xzsb_flag = 1;
	  g_xzxzsb_flag = 1;
      strcpy(g_yszm_xzsb_pass_buf,buf);
	  g_gdbh_sel_flag = 1;
	  if (dlg.DoModal() == IDOK){
	    g_xzxzsb_flag = 0;
		i = g_yszm_sel_sb;
	    g_yszm_xzsb_flag = 1;
		SetDlgItemText(IDC_byjx,g_e_abbr[i]);
		SetDlgItemText(IDC_sbmc,g_e_name[i]);
        g_yszm_xzsb_flag = 1;
		SetDlgItemText(IDC_gdbh,g_a_id[i]);
		SetDlgItemText(IDC_yqdm,g_e_code[i]);
		SetDlgItemText(IDC_scdm,g_p_id[i]);
	    m_tree.SelectDropTarget(g_htreeitem[i]);
	    m_tree.SelectItem(g_htreeitem[i]);
	    CWnd *wnd;
	    wnd = GetDlgItem(IDC_rkfs);
	    wnd->SetFocus();
	  }
	  else{
	    g_xzxzsb_flag = 0;
      }
	  g_gdbh_sel_flag = 0;
	  GetDlgItemText(IDC_gdbh,buf,20);
	  if (buf[3] == '2')
	    CheckDlgButton(IDC_sfdzp,TRUE);
	  else
	    CheckDlgButton(IDC_sfdzp,FALSE);
	}
	else{
      g_yszm_xzsb_flag = 0;
    }
}

void Cyszmrkdlg::OnSetfocusfocus() 
{
  CWnd *wd;
  
  wd = GetDlgItem(IDC_byjx);
  wd->SetFocus();
}

⌨️ 快捷键说明

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