DialogLogin.cpp
上传用户:xiaoke98
上传日期:2014-06-29
资源大小:5718k
文件大小:3k
- // DialogLogin.cpp : implementation file
- //
- #include "stdafx.h"
- #include "HomeFinanceManager.h"
- #include "DialogLogin.h"
- #include "DBOperator.h"
- #include "SysStatus.h"
- #include "HomeFinanceManagerView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDialogLogin dialog
- CDialogLogin::CDialogLogin(CWnd* pParent /*=NULL*/)
- : CDialog(CDialogLogin::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDialogLogin)
- m_strPasswd = _T("");
- m_strUserName = _T("");
- //}}AFX_DATA_INIT
- }
- void CDialogLogin::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDialogLogin)
- DDX_Control(pDX, IDC_LOGIN, m_btnLogin);
- DDX_Text(pDX, IDC_PASSWD, m_strPasswd);
- DDX_Text(pDX, IDC_USERNAME, m_strUserName);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDialogLogin, CDialog)
- //{{AFX_MSG_MAP(CDialogLogin)
- ON_BN_CLICKED(IDC_LOGIN, OnLogin)
- //}}AFX_MSG_MAP
- ON_WM_CTLCOLOR()
- ON_WM_ERASEBKGND()
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDialogLogin message handlers
- BOOL CDialogLogin::PreTranslateMessage( MSG* pMsg )
- {
- if(pMsg->message == WM_KEYDOWN)
- {
- int nVirtKey = pMsg->wParam;
- int nScanCode = pMsg->lParam &0x00FF0000;
- int bChar = MapVirtualKey(nVirtKey,0);
- if(nVirtKey == VK_RETURN)
- {
- OnLogin();
- return TRUE;
- }
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- /////////////////////////////////////////////////////////////////////////////
- void CDialogLogin::OnOK( )
- {
- //OnLogin();
- }
- //-----------------------------------------------------------------------------
- BOOL CDialogLogin::OnEraseBkgnd( CDC* pDC )
- {
- DispalyBackBmp(pDC);
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- void CDialogLogin::DispalyBackBmp(CDC* pDC)
- {
- CBitmap Bitmap;
- Bitmap.LoadBitmap(IDB_MAINBACK);
-
- BITMAP bmpInfo;
- Bitmap.GetBitmap(&bmpInfo);
-
-
- CDC* pDlgDC = this->GetDC();
- CDC MemDC;
- MemDC.CreateCompatibleDC(pDlgDC);
- MemDC.SelectObject(Bitmap);
-
- RECT rcClient;
- this->GetClientRect(&rcClient);
- int iWidth = rcClient.right - rcClient.left;
- int iHeight = rcClient.bottom - rcClient.top;
-
-
- pDC->BitBlt(0, 0, iWidth, iHeight, &MemDC, 0, 0,SRCCOPY);
- }
- //-----------------------------------------------------------------------------
- HBRUSH CDialogLogin::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- //改变控件的颜色
- if(nCtlColor == CTLCOLOR_STATIC)
- {
- pDC->SetBkMode(TRANSPARENT);
- pDC->SetTextColor(RGB(255,255,0));
-
- LOGBRUSH logBrush;
- logBrush.lbStyle = BS_HOLLOW;
- hbr = CreateBrushIndirect(&logBrush);
- }
- if(nCtlColor == CTLCOLOR_EDIT)
- {
- pDC->SetTextColor(RGB(200,0,0));//字体色
- //pDC->SetBkColor(RGB(170, 243, 162));
- }
-
- return hbr;
- }
- void CDialogLogin::OnLogin()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- if(gDBOperator.VerifyUser(m_strUserName, m_strPasswd))
- {
- gSysStatus.setLoginStatus(TRUE);
- gSysStatus.setUserName(m_strUserName);
- m_pParentView->VerifyUser();
- }
- else
- {
- AfxMessageBox("用户名或密码不正确,请查实!");
- }
-
- }
- void CDialogLogin::setParentView(CHomeFinanceManagerView* pView)
- {
- m_pParentView = pView;
- }