studydlg.cpp

来自「这是一个学生信息管理系统」· C++ 代码 · 共 470 行 · 第 1/2 页

CPP
470
字号

	}
	*pResult = 0;
}

void CStudyDlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	//显示英语单词
	CString StrWord;
	if(m_pWordListSet.IsOpen())
		m_pWordListSet.Close();
	m_pWordListSet.Open();
	int Count;
	m_pWordListSet.m_strFilter .Empty ();
	Count=m_pWordListSet.GetRecordCount();
	if(Count==0)//如果没有单词,则显示默认的单词,要很经典才行
	{
		StrWord=L"Software Engineer\n(计算机)软件工程师\n常见职务";
		SetDlgItemText(IDC_TODAY_WORD_STATIC,StrWord);
		m_pWordListSet.Close ();
	}
	else//否则随机选择显示
	{	
		Count=0;
		m_pWordListSet.MoveFirst();
		while(!m_pWordListSet.IsEOF())
		{
			m_pWordListSet.MoveNext();
			Count++;//先计算总数
		}
		m_pWordListSet.MoveFirst();//再跳回到第一个
		srand((unsigned)time(NULL)*rand());
		srand((unsigned) time(NULL)*rand());
		srand(rand());//再种多一个随机种子
		int rth=rand()%Count;//随机找到那个
		int i=0;
		while(!m_pWordListSet.IsEOF())
		{   
			if(i==rth)//随机取一个
			{
				StrWord=m_pWordListSet.m_wWord +L"\n"+m_pWordListSet.m_wMean +L"\n"+m_pWordListSet.m_wGroup ;
				break;
			}
			i++;
			m_pWordListSet.MoveNext();
		}
		m_pWordListSet.Close();
	}
	SetDlgItemText(IDC_TODAY_WORD_STATIC,StrWord);
	CDialog::OnTimer(nIDEvent);
}

void CStudyDlg::OnClose()
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
    KillTimer(STUDY_TIMER);
	CDialog::OnClose();
}

void CStudyDlg::OnCancel()
{
	// TODO: 在此添加专用代码和/或调用基类

	DestroyWindow();
}

void CStudyDlg::PostNcDestroy()
{
	// TODO: 在此添加专用代码和/或调用基类

	CDialog::PostNcDestroy();
	AfxGetMainWnd()->SendMessage(WM_USER_STUDYDLG_DESTROYED,0,0);
	delete this;
}

HBRUSH CStudyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何属性
	if(m_bColor)//如果用系统的,则直接返回
		return hbr;
	pDC->SetTextColor (m_RGB_CtrlColor);
	pDC->SetBkMode(BKMODE_LAST);pDC->SetBkColor (m_RGB_BkColor);
	return (HBRUSH)m_brush.GetSafeHandle ();
	// TODO:  如果默认的不是所需画笔,则返回另一个画笔
//	return hbr;
}
void CStudyDlg::OnStudyCourse ()
{
    CRect r;
	m_Study_TabCtrl.GetClientRect (&r);
	m_Study_TabCtrl.SetCurSel (0);
	m_StudyTimetableDlg.SetWindowPos (NULL,2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
	m_StudyPlanDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
    m_StudyWordDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
	m_StudyLogionDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
}
void CStudyDlg::OnStudyPlan ()
{
    CRect r;
	m_Study_TabCtrl.GetClientRect (&r);
	m_Study_TabCtrl.SetCurSel (1);
	m_StudyTimetableDlg.SetWindowPos (NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
	m_StudyPlanDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
    m_StudyWordDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
	m_StudyLogionDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
}
void CStudyDlg::OnStudyWord ()
{
    CRect r;
	m_Study_TabCtrl.GetClientRect (&r);
	m_Study_TabCtrl.SetCurSel (2);
	m_StudyTimetableDlg.SetWindowPos (NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
	m_StudyPlanDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
    m_StudyWordDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
	m_StudyLogionDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
}
void CStudyDlg::OnStudyLogion ()
{
    CRect r;
	m_Study_TabCtrl.GetClientRect (&r);
	m_Study_TabCtrl.SetCurSel (3);
	m_StudyTimetableDlg.SetWindowPos (NULL,2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
	m_StudyPlanDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
    m_StudyWordDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_HIDEWINDOW);
	m_StudyLogionDlg.SetWindowPos (NULL, 2,22,r.right -5, r.bottom -25,SWP_SHOWWINDOW);
}
void CStudyDlg::OnStudyClose ()
{
    this->DestroyWindow ();
}
void CStudyDlg::OnUpdateStudyCourse (CCmdUI *pCmdUI)
{
    pCmdUI->SetCheck (m_Study_TabCtrl.GetCurSel ()==0);
}
void CStudyDlg::OnUpdateStudyPlan (CCmdUI *pCmdUI)
{
    pCmdUI->SetCheck (m_Study_TabCtrl.GetCurSel ()==1);
}
void CStudyDlg::OnUpdateStudyWord (CCmdUI *pCmdUI)
{
    pCmdUI->SetCheck (m_Study_TabCtrl.GetCurSel ()==2);
}
void CStudyDlg::OnUpdateStudyLogion (CCmdUI *pCmdUI)
{
    pCmdUI->SetCheck (m_Study_TabCtrl.GetCurSel ()==3);
}
void CStudyDlg::OnContextMenu(CWnd* pWnd, CPoint point)
{
	// TODO: 在此处添加消息处理程序代码
	CMenu menu;
    CPoint pos=point;
	ScreenToClient(&pos);
	CRect rect;
	GetClientRect(&rect);
	if(rect.PtInRect (pos))
	{
	menu.LoadMenu(IDR_STUDY_MENU);
	menu.GetSubMenu (0)->TrackPopupMenu (TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);
	return ;
	}
	CWnd::OnContextMenu (pWnd,point);
}
void CStudyDlg::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
{   
	ASSERT(pPopupMenu != NULL);    // Check the enabled state of various menu items.    
    CCmdUI state;    
	state.m_pMenu = pPopupMenu;    
	ASSERT(state.m_pOther == NULL);    
	ASSERT(state.m_pParentMenu == NULL);    // Determine if menu is popup in top-level menu and set m_pOther to    
	// it if so (m_pParentMenu == NULL indicates that it is secondary popup).    
	HMENU hParentMenu;    
	if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)        state.m_pParentMenu = pPopupMenu;   
	// Parent == child for tracking popup.    
	else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)    
	{        
		CWnd* pParent = this;           
		// Child windows don't have menus--need to go to the top!       
		if (pParent != NULL &&(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)        
		{           
			int nIndexMax = ::GetMenuItemCount(hParentMenu);          
			for (int nIndex = 0; nIndex < nIndexMax; nIndex++)           
			{            
				if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)            
				{               
					// When popup is found, m_pParentMenu is containing menu.                
					state.m_pParentMenu = CMenu::FromHandle(hParentMenu);                
					break;            
				}           
			}        
		}    
	}    
	state.m_nIndexMax = pPopupMenu->GetMenuItemCount();    
	for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;      
		state.m_nIndex++)    
	{        
		state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);        
		if (state.m_nID == 0)           
			continue; // Menu separator or invalid cmd - ignore it.        
		ASSERT(state.m_pOther == NULL);        
		ASSERT(state.m_pMenu != NULL);        
		if (state.m_nID == (UINT)-1)        
		{           
			// Possibly a popup menu, route to first item of that popup.          
			state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);  
			if (state.m_pSubMenu == NULL||(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||state.m_nID == (UINT)-1)           
			{            
				continue;       // First item of popup can't be routed to.           
			}           
			state.DoUpdate(this, TRUE);   // Popups are never auto disabled.       
		}        
		else        
		{           // Normal menu item.           
			// Auto enable/disable if frame window has m_bAutoMenuEnable           
			// set and command is _not_ a system command.           
			state.m_pSubMenu = NULL;           
			state.DoUpdate(this, FALSE);        
		}        
		// Adjust for menu deletions and additions.        
		UINT nCount = pPopupMenu->GetMenuItemCount();        
		if (nCount < state.m_nIndexMax)        
		{           
			state.m_nIndex -= (state.m_nIndexMax - nCount);           
			while (state.m_nIndex < nCount &&            
				pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID) 
			{            
				state.m_nIndex++;          
			}        
		}        
		state.m_nIndexMax = nCount;    
	}
} 

⌨️ 快捷键说明

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