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

📄 logindlg.cpp

📁 采用MFC+SQLSERVER 2000的图书管理系统,ODBC方式连接数据库。功能包括 书籍管理
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  
	CLoginSet *m_pLogset=new CLoginSet(&m_database);

	//编写SQL语句
	CString strSQL;
	strSQL.Format("select * from MANGEINFORM where Mname='%s' AND Mpassword='%s'",m_strUsername,m_strPassword);
	//编写SQL语句结束

	m_pLogset->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
	
	if(m_pLogset->GetRecordCount()==0)
	{
		if(count<5)
		{
			MessageBox("登录失败!","图书管理系统",MB_OK|MB_ICONERROR);
			count++;
			m_strPassword.Empty();
			m_strUsername.Empty();
			UpdateData(FALSE);
		}
		else
		{
			m_database.Close();
			MessageBox("您登录失败超过5次,请与管理员联系!","图书管理系统");
			CDialog::OnOK();
		}
	}
	else
	{
		m_database.Close();
		*b_Login = 0;
		CDialog::OnOK();
	}
	//CDialog::OnOK();
}


HBRUSH CLogInDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
 		//绘制背景
	if (nCtlColor==CTLCOLOR_DLG)
	{
		CBitmap bitmap;
		bitmap.LoadBitmap(IDB_CLIENTBITMAP);

		CBrush brush(&bitmap);
		CRect rect;
		GetClientRect(rect);
		pDC->SelectObject(&brush);
		bitmap.DeleteObject();
		pDC->FillRect(rect,&brush);
		return brush;
	}
	else if (nCtlColor ==CTLCOLOR_STATIC)
	{
		pDC->SetBkMode(TRANSPARENT);
	}
	else   
		return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CLogInDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
		DrawForm();
	m_IsDrawForm = TRUE;
	// Do not call CDialog::OnPaint() for painting messages
}

void CLogInDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
 		CRect rect;
	GetClientRect(rect);

	m_IniRect.CopyRect(CRect(8,(m_CaptionHeight+3*m_BorderHeight -m_ButtonHeight)/2,m_ButtonWidth,m_ButtonHeight));
	m_MinRect.CopyRect(CRect(rect.Width()-45,(m_CaptionHeight+2*m_BorderHeight -m_ButtonHeight)/2,m_ButtonWidth,m_ButtonHeight));
	m_MaxRect.CopyRect(CRect(rect.Width()-32,(m_CaptionHeight+2*m_BorderHeight -m_ButtonHeight)/2,m_ButtonWidth,m_ButtonHeight));
	m_CloseRect.CopyRect(CRect(rect.Width()-19,(m_CaptionHeight+2*m_BorderHeight -m_ButtonHeight)/2,m_ButtonWidth,m_ButtonHeight));
	
	Invalidate();   
}

void CLogInDlg::OnNcLButtonDblClk(UINT nHitTest, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	//CDialog::OnNcLButtonDblClk(nHitTest, point);
}

void CLogInDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
	// TODO: Add your message handler code here
		if (m_FirstShow==FALSE)
	{
		m_FirstShow = TRUE;
		GetWindowRect(m_OrigonRect);
	}
}

void CLogInDlg::OnNcLButtonDown(UINT nHitTest, CPoint point) 
{  	
	// TODO: Add your message handler code here and/or call default
 		switch (m_ButtonState)
	{
	case bsClose: //关闭窗口
		{
			CDialog::OnOK();
		}
		break;
	case bsIni: //还原窗口到初始大小和位置
		{
			m_IsMax = TRUE;
			MoveWindow(m_OrigonRect.left,m_OrigonRect.top,m_OrigonRect.Width(),m_OrigonRect.Height());
		}
		break;
	case bsMin: //
		{
			CWnd* pDesk = GetDesktopWindow();
			CRect rect;
			pDesk->GetClientRect(rect);
			SetWindowPos(0 ,(rect.Width()-m_OrigonRect.Width())/2,2,m_OrigonRect.Width(),0,SWP_SHOWWINDOW);
		}
		break;
	case bsMax:
		{
			m_ButtonState = bsMax;
			ShowWindow(SW_SHOWMAXIMIZED);
			m_IsMax = FALSE;
		}
		break;
	case bsRes:
		{			
			ShowWindow(SW_RESTORE);
			m_IsMax = TRUE;
		}  
		break;
		}   
CDialog::OnNcLButtonDown(nHitTest, point);
}

void CLogInDlg::OnNcPaint() 
{
	// TODO: Add your message handler code here
	DrawForm();
	m_IsDrawForm = TRUE;
	// Do not call CDialog::OnNcPaint() for painting messages
}

void CLogInDlg::OnNcMouseMove(UINT nHitTest, CPoint point) 
{   
	// TODO: Add your message handler code here and/or call default
		CRect tempIni,tempMin,tempMax,tempClose,ClientRect;
	
	CDC* pWindowDC = this->GetWindowDC();
	CDC memDC;
	memDC.CreateCompatibleDC(pWindowDC);

	BITMAPINFO bInfo;
	CBitmap LeftLine;
	int x,y;

	GetWindowRect(ClientRect);
	//GetClientRect();
	tempIni.CopyRect(CRect(m_IniRect.left+ ClientRect.left,ClientRect.top+m_IniRect.top,m_IniRect.right+m_IniRect.left+ ClientRect.left,m_IniRect.bottom+m_IniRect.top+ClientRect.top));
	tempMin.CopyRect(CRect(m_MinRect.left+ ClientRect.left,ClientRect.top+m_MinRect.top,m_MinRect.right+m_MinRect.left+ ClientRect.left,m_MinRect.bottom+m_MinRect.top+ClientRect.top));
	tempMax.CopyRect(CRect(m_MaxRect.left+ ClientRect.left,ClientRect.top+m_MaxRect.top,m_MaxRect.right+m_MaxRect.left+ ClientRect.left,m_MaxRect.bottom+m_MaxRect.top+ClientRect.top));
	tempClose.CopyRect(CRect(m_CloseRect.left+ ClientRect.left,ClientRect.top+m_CloseRect.top,m_CloseRect.right+m_CloseRect.left+ ClientRect.left,m_CloseRect.bottom+m_CloseRect.top+ClientRect.top));
	
	if (tempIni.PtInRect(point)) //鼠标在初始化按钮上移动时,更改按钮显示的位图
	{

		LeftLine.LoadBitmap(IDB_BITMAP7);
		LeftLine.GetObject(sizeof(bInfo),&bInfo);
		
		x = bInfo.bmiHeader.biWidth;
		y = bInfo.bmiHeader.biHeight;
		memDC.SelectObject(&LeftLine);
		pWindowDC->StretchBlt(m_IniRect.left,m_IniRect.top,m_IniRect.right,m_IniRect.bottom,&memDC,0,0,x,y,SRCCOPY);
		m_IsDrawForm = FALSE;
		m_ButtonState = bsIni;
		LeftLine.DeleteObject();
	}
	else if(tempMin.PtInRect(point))//鼠标在最小化按钮上移动时,更改按钮显示的位图
	{
		LeftLine.LoadBitmap(IDB_BITMAP7);
		LeftLine.GetObject(sizeof(bInfo),&bInfo);
		
		x = bInfo.bmiHeader.biWidth;
		y = bInfo.bmiHeader.biHeight;
		memDC.SelectObject(&LeftLine);
		pWindowDC->StretchBlt(m_MinRect.left,m_MinRect.top,m_MinRect.right,m_MinRect.bottom,&memDC,0,0,x,y,SRCCOPY);
		m_IsDrawForm = FALSE;
		m_ButtonState = bsMin;
		LeftLine.DeleteObject();		
	}
	else if (tempMax.PtInRect(point))
	{
		LeftLine.LoadBitmap(IDB_BITMAP7);
		LeftLine.GetObject(sizeof(bInfo),&bInfo);
		
		x = bInfo.bmiHeader.biWidth;
		y = bInfo.bmiHeader.biHeight;
		memDC.SelectObject(&LeftLine);
		pWindowDC->StretchBlt(m_MaxRect.left,m_MaxRect.top,m_MaxRect.right,m_MaxRect.bottom,&memDC,0,0,x,y,SRCCOPY);
		m_IsDrawForm = FALSE;
		if (m_IsMax)
		{
			m_ButtonState = bsMax;
		}
		else
		{
			m_ButtonState = bsRes;
		}
		
		LeftLine.DeleteObject();		
	}
	else if (tempClose.PtInRect(point))
	{
		LeftLine.LoadBitmap(IDB_BITMAP7);
		LeftLine.GetObject(sizeof(bInfo),&bInfo);
		
		x = bInfo.bmiHeader.biWidth;
		y = bInfo.bmiHeader.biHeight;
		memDC.SelectObject(&LeftLine);
		pWindowDC->StretchBlt(m_CloseRect.left,m_CloseRect.top,m_CloseRect.right,m_CloseRect.bottom,&memDC,0,0,x,y,SRCCOPY);
		m_IsDrawForm = FALSE;
		m_ButtonState = bsClose;
		LeftLine.DeleteObject();			
	}
	else
	{
		m_ButtonState = bsNone;
		if (m_IsDrawForm==FALSE)
			DrawForm();
	//	m_IsDrawForm = TRUE;
	}
	ReleaseDC(&memDC);

	CDialog::OnNcMouseMove(nHitTest, point);
}

void CLogInDlg::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos) 
{
	CDialog::OnWindowPosChanged(lpwndpos);
	
	// TODO: Add your message handler code here
	
}

int CLogInDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	
	return 0;
}

BOOL CLogInDlg::OnNcActivate(BOOL bActive) 
{
	// TODO: Add your message handler code here and/or call default
	OnPaint() ;
	return CDialog::OnNcActivate(bActive);
}

void CLogInDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
{
	CDialog::OnActivate(nState, pWndOther, bMinimized);
	
	// TODO: Add your message handler code here
	OnPaint() ;	
}

⌨️ 快捷键说明

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