DialogLogin.cpp
上传用户:xiaoke98
上传日期:2014-06-29
资源大小:5718k
文件大小:3k
源码类别:

家庭/个人应用

开发平台:

Visual C++

  1. // DialogLogin.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "HomeFinanceManager.h"
  5. #include "DialogLogin.h"
  6. #include "DBOperator.h"
  7. #include "SysStatus.h"
  8. #include "HomeFinanceManagerView.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CDialogLogin dialog
  16. CDialogLogin::CDialogLogin(CWnd* pParent /*=NULL*/)
  17. : CDialog(CDialogLogin::IDD, pParent)
  18. {
  19. //{{AFX_DATA_INIT(CDialogLogin)
  20. m_strPasswd = _T("");
  21. m_strUserName = _T("");
  22. //}}AFX_DATA_INIT
  23. }
  24. void CDialogLogin::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CDialogLogin)
  28. DDX_Control(pDX, IDC_LOGIN, m_btnLogin);
  29. DDX_Text(pDX, IDC_PASSWD, m_strPasswd);
  30. DDX_Text(pDX, IDC_USERNAME, m_strUserName);
  31. //}}AFX_DATA_MAP
  32. }
  33. BEGIN_MESSAGE_MAP(CDialogLogin, CDialog)
  34. //{{AFX_MSG_MAP(CDialogLogin)
  35. ON_BN_CLICKED(IDC_LOGIN, OnLogin)
  36. //}}AFX_MSG_MAP
  37. ON_WM_CTLCOLOR()
  38. ON_WM_ERASEBKGND() 
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CDialogLogin message handlers
  42. BOOL CDialogLogin::PreTranslateMessage( MSG* pMsg )
  43. {
  44. if(pMsg->message == WM_KEYDOWN)
  45. {
  46. int nVirtKey = pMsg->wParam;
  47. int nScanCode = pMsg->lParam &0x00FF0000;
  48. int bChar = MapVirtualKey(nVirtKey,0);
  49. if(nVirtKey == VK_RETURN)
  50. {
  51. OnLogin();
  52. return TRUE;
  53. }
  54. }
  55. return CDialog::PreTranslateMessage(pMsg);
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. void CDialogLogin::OnOK( )
  59. {
  60. //OnLogin();
  61. }
  62. //-----------------------------------------------------------------------------
  63. BOOL CDialogLogin::OnEraseBkgnd( CDC* pDC )
  64. {
  65. DispalyBackBmp(pDC);
  66. return TRUE;
  67. }
  68. //-----------------------------------------------------------------------------
  69. void  CDialogLogin::DispalyBackBmp(CDC* pDC)
  70. {
  71. CBitmap Bitmap;
  72. Bitmap.LoadBitmap(IDB_MAINBACK);
  73. BITMAP bmpInfo;
  74. Bitmap.GetBitmap(&bmpInfo);
  75. CDC* pDlgDC = this->GetDC();
  76. CDC MemDC;
  77. MemDC.CreateCompatibleDC(pDlgDC);
  78. MemDC.SelectObject(Bitmap);
  79. RECT rcClient;
  80. this->GetClientRect(&rcClient);
  81. int iWidth = rcClient.right - rcClient.left;
  82. int iHeight = rcClient.bottom - rcClient.top;
  83. pDC->BitBlt(0, 0, iWidth, iHeight, &MemDC, 0, 0,SRCCOPY);
  84. }
  85. //-----------------------------------------------------------------------------
  86. HBRUSH CDialogLogin::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  87. {
  88. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  89. //改变控件的颜色
  90. if(nCtlColor == CTLCOLOR_STATIC)
  91. {
  92. pDC->SetBkMode(TRANSPARENT);
  93. pDC->SetTextColor(RGB(255,255,0));
  94. LOGBRUSH  logBrush;
  95. logBrush.lbStyle = BS_HOLLOW;
  96. hbr = CreateBrushIndirect(&logBrush);
  97. }
  98. if(nCtlColor == CTLCOLOR_EDIT)
  99. {
  100. pDC->SetTextColor(RGB(200,0,0));//字体色
  101. //pDC->SetBkColor(RGB(170, 243, 162));
  102. }
  103. return hbr;
  104. }
  105. void CDialogLogin::OnLogin() 
  106. {
  107. // TODO: Add your control notification handler code here
  108. UpdateData();
  109. if(gDBOperator.VerifyUser(m_strUserName, m_strPasswd))
  110. {
  111. gSysStatus.setLoginStatus(TRUE);
  112. gSysStatus.setUserName(m_strUserName);
  113. m_pParentView->VerifyUser();
  114. }
  115. else
  116. {
  117. AfxMessageBox("用户名或密码不正确,请查实!");
  118. }
  119. }
  120. void  CDialogLogin::setParentView(CHomeFinanceManagerView* pView)
  121. {
  122. m_pParentView = pView;
  123. }