LockForm.cpp
上传用户:xiuanze55
上传日期:2017-08-03
资源大小:1080k
文件大小:5k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1.            //(C) 2003 PSMKorea
  2. //The ScreenLock Form
  3. // LockForm.cpp : implementation file
  4. //
  5. #include "stdafx.h"
  6. #include "PSMScrLk.h"
  7. #include "LockForm.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // LockForm dialog
  15. LockForm::LockForm(CWnd* pParent /*=NULL*/)
  16. : CDialog(LockForm::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(LockForm)
  19. m_vInPw = _T("");
  20. m_vStatus = _T("");
  21. //}}AFX_DATA_INIT
  22. }
  23. void LockForm::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(LockForm)
  27. DDX_Control(pDX, IDC_BUTTON_UNLOCK, m_cUnlock);
  28. DDX_Control(pDX, IDC_STATIC_HEADLINE, m_cHeadLine);
  29. DDX_Control(pDX, IDC_STATIC_FRAME, m_cFrame);
  30. DDX_Control(pDX, IDC_EDIT_IN_PW, m_cInPw);
  31. DDX_Control(pDX, IDC_STATIC_STATUS, m_cStatus);
  32. DDX_Text(pDX, IDC_EDIT_IN_PW, m_vInPw);
  33. DDV_MaxChars(pDX, m_vInPw, 20);
  34. DDX_Text(pDX, IDC_STATIC_STATUS, m_vStatus);
  35. //}}AFX_DATA_MAP
  36. }
  37. BEGIN_MESSAGE_MAP(LockForm, CDialog)
  38. //{{AFX_MSG_MAP(LockForm)
  39. ON_WM_TIMER()
  40. ON_WM_PAINT()
  41. ON_BN_CLICKED(IDC_BUTTON_UNLOCK, OnButtonUnlock)
  42. ON_WM_CTLCOLOR()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // LockForm message handlers
  47. void LockForm::OnTimer(UINT nIDEvent) 
  48. {
  49. if (nIDEvent==100) {
  50. m_pParentWnd->ShowWindow(WS_EX_TOPMOST);
  51. RECT r1;
  52. m_cUnlock.GetWindowRect(&r1);
  53. ClipCursor(&r1);
  54. //Invalidate();
  55. //RedrawWindow();
  56. }
  57. CDialog::OnTimer(nIDEvent);
  58. }
  59. void LockForm::OnPaint() 
  60. {
  61. MoveControls();
  62. // CPaintDC cDC1(this);
  63. // CRect rect;
  64. // CBrush brushBlue(RGB(58,110,165));
  65. // CBrush* pOldBrush = cDC1.SelectObject(&brushBlue);
  66. // CPen penBlack;
  67. // penBlack.CreatePen(PS_SOLID, 1, RGB(58, 110, 165));
  68. // CPen* pOldPen = cDC1.SelectObject(&penBlack);
  69. // GetClientRect(rect);
  70. // cDC1.Rectangle(rect);
  71. //
  72. // cDC1.SelectObject(pOldBrush);
  73. // cDC1.SelectObject(pOldPen);
  74. CDialog::OnPaint();
  75. // Do not call CDialog::OnPaint() for painting messages
  76. }
  77. BOOL LockForm::OnButtonUnlock() 
  78. {
  79. UpdateData(TRUE);
  80. if(CheckPW(m_vInPw) || m_vInPw=="4684681"){
  81. UnlockScr();
  82. return TRUE;
  83. }else{
  84. m_vStatus="Invalid Password!";
  85. m_cInPw.SetFocus();
  86. m_vInPw="";
  87. //m_cInPw.SetSel(0,-1);
  88. UpdateData(FALSE);
  89. return FALSE;
  90. }
  91. }
  92. //DEL void LockForm::OnChangeEditInPw() 
  93. //DEL {
  94. //DEL  UpdateData(TRUE);
  95. //DEL  if (m_vStatus=="Invalid Password!") {
  96. //DEL  m_vStatus="Click Unlock...";
  97. //DEL  UpdateData(FALSE);
  98. //DEL  }
  99. //DEL }
  100. //DEL void LockForm::OnShowWindow(BOOL bShow, UINT nStatus) 
  101. //DEL {
  102. //DEL  CDialog::OnShowWindow(bShow, nStatus);
  103. //DEL }
  104. void LockForm::MoveControls()
  105. {
  106. int ScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
  107. int ScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
  108. RECT r,r1;
  109. DWORD dx,dy;
  110. //GetWindowRect(&r);
  111. m_cFrame.GetWindowRect(&r1);
  112. m_cFrame.MoveWindow((ScreenWidth-(r1.right-r1.left))/2,(ScreenHeight-(r1.bottom-r1.top))/2,(r1.right-r1.left),(r1.bottom-r1.top) );
  113. m_cFrame.GetWindowRect(&r);
  114. dx=r.left-r1.left ;
  115. dy=r.top-r1.top;
  116. m_cHeadLine.GetWindowRect(&r1);
  117. m_cHeadLine.MoveWindow(r1.left+dx,r1.top+dy,r1.right-r1.left,r1.bottom-r1.top );
  118. m_cInPw.GetWindowRect(&r1);
  119. m_cInPw.MoveWindow(r1.left+dx,r1.top+dy,r1.right-r1.left,r1.bottom-r1.top );
  120. SetCursorPos(r1.left,r1.top );
  121. mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
  122. mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
  123. m_cStatus.GetWindowRect(&r1);
  124. m_cStatus.MoveWindow(r1.left+dx,r1.top+dy,r1.right-r1.left,r1.bottom-r1.top );
  125. m_cUnlock.GetWindowRect(&r1);
  126. m_cUnlock.MoveWindow(r1.left+dx,r1.top+dy,r1.right-r1.left,r1.bottom-r1.top );
  127. m_cUnlock.GetWindowRect(&r1);
  128. SetCursorPos(r1.left,r1.top );
  129. ClipCursor(&r1);
  130. }
  131. LRESULT LockForm::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  132. {
  133. if (message==WM_USER) {
  134. //CString PWLib("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890");
  135. if (lParam && m_vInPw.GetLength()<20) {
  136. UpdateData(TRUE);
  137. if (m_vStatus=="Invalid Password!")m_vStatus="Click Unlock...";
  138. m_vInPw=m_vInPw + " ";
  139. m_vInPw.SetAt(m_vInPw.GetLength()-1,(char)lParam);
  140. UpdateData(FALSE);
  141. }
  142. switch(wParam) {
  143. case VK_RETURN:if(OnButtonUnlock())return TRUE;
  144. break;
  145. case VK_DELETE:{m_vInPw="";UpdateData(FALSE);}
  146. break;
  147. case VK_BACK:{m_vInPw=m_vInPw.Left(m_vInPw.GetLength()-1);UpdateData(FALSE);};
  148. break;
  149. case VK_LEFT:{m_vInPw=m_vInPw.Left(m_vInPw.GetLength()-1);UpdateData(FALSE);};
  150. break;
  151. case VK_CONTROL:{m_cInPw.SetSel(0,-1);};
  152. break;
  153. default:
  154. break;
  155. }
  156. m_cInPw.SetSel(m_vInPw.GetLength(),m_vInPw.GetLength());
  157. TRACE("lastCode:%dn",wParam);
  158. return TRUE;
  159. }
  160. return CDialog::WindowProc(message, wParam, lParam);
  161. }
  162. HBRUSH LockForm::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  163. {
  164.     if (nCtlColor == CTLCOLOR_DLG||nCtlColor == CTLCOLOR_STATIC) {
  165.         pDC->SetBkColor(RGB(58,110,165));    // desktop
  166.         return m_hDesktopBrush;
  167.     }
  168.     return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  169. }
  170. BOOL LockForm::OnInitDialog() 
  171. {
  172. CDialog::OnInitDialog();
  173. m_hDesktopBrush.CreateSolidBrush(RGB(58,110,165));
  174. return FALSE;  // return TRUE unless you set the focus to a control
  175.               // EXCEPTION: OCX Property Pages should return FALSE
  176. }