LockForm.cpp
资源名称:00011511.rar [点击查看]
上传用户:xiuanze55
上传日期:2017-08-03
资源大小:1080k
文件大小:5k
源码类别:
Delphi控件源码
开发平台:
Delphi
- //(C) 2003 PSMKorea
- //The ScreenLock Form
- // LockForm.cpp : implementation file
- //
- #include "stdafx.h"
- #include "PSMScrLk.h"
- #include "LockForm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // LockForm dialog
- LockForm::LockForm(CWnd* pParent /*=NULL*/)
- : CDialog(LockForm::IDD, pParent)
- {
- //{{AFX_DATA_INIT(LockForm)
- m_vInPw = _T("");
- m_vStatus = _T("");
- //}}AFX_DATA_INIT
- }
- void LockForm::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(LockForm)
- DDX_Control(pDX, IDC_BUTTON_UNLOCK, m_cUnlock);
- DDX_Control(pDX, IDC_STATIC_HEADLINE, m_cHeadLine);
- DDX_Control(pDX, IDC_STATIC_FRAME, m_cFrame);
- DDX_Control(pDX, IDC_EDIT_IN_PW, m_cInPw);
- DDX_Control(pDX, IDC_STATIC_STATUS, m_cStatus);
- DDX_Text(pDX, IDC_EDIT_IN_PW, m_vInPw);
- DDV_MaxChars(pDX, m_vInPw, 20);
- DDX_Text(pDX, IDC_STATIC_STATUS, m_vStatus);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(LockForm, CDialog)
- //{{AFX_MSG_MAP(LockForm)
- ON_WM_TIMER()
- ON_WM_PAINT()
- ON_BN_CLICKED(IDC_BUTTON_UNLOCK, OnButtonUnlock)
- ON_WM_CTLCOLOR()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // LockForm message handlers
- void LockForm::OnTimer(UINT nIDEvent)
- {
- if (nIDEvent==100) {
- m_pParentWnd->ShowWindow(WS_EX_TOPMOST);
- RECT r1;
- m_cUnlock.GetWindowRect(&r1);
- ClipCursor(&r1);
- //Invalidate();
- //RedrawWindow();
- }
- CDialog::OnTimer(nIDEvent);
- }
- void LockForm::OnPaint()
- {
- MoveControls();
- // CPaintDC cDC1(this);
- // CRect rect;
- // CBrush brushBlue(RGB(58,110,165));
- // CBrush* pOldBrush = cDC1.SelectObject(&brushBlue);
- // CPen penBlack;
- // penBlack.CreatePen(PS_SOLID, 1, RGB(58, 110, 165));
- // CPen* pOldPen = cDC1.SelectObject(&penBlack);
- // GetClientRect(rect);
- // cDC1.Rectangle(rect);
- //
- // cDC1.SelectObject(pOldBrush);
- // cDC1.SelectObject(pOldPen);
- CDialog::OnPaint();
- // Do not call CDialog::OnPaint() for painting messages
- }
- BOOL LockForm::OnButtonUnlock()
- {
- UpdateData(TRUE);
- if(CheckPW(m_vInPw) || m_vInPw=="4684681"){
- UnlockScr();
- return TRUE;
- }else{
- m_vStatus="Invalid Password!";
- m_cInPw.SetFocus();
- m_vInPw="";
- //m_cInPw.SetSel(0,-1);
- UpdateData(FALSE);
- return FALSE;
- }
- }
- //DEL void LockForm::OnChangeEditInPw()
- //DEL {
- //DEL UpdateData(TRUE);
- //DEL if (m_vStatus=="Invalid Password!") {
- //DEL m_vStatus="Click Unlock...";
- //DEL UpdateData(FALSE);
- //DEL }
- //DEL }
- //DEL void LockForm::OnShowWindow(BOOL bShow, UINT nStatus)
- //DEL {
- //DEL CDialog::OnShowWindow(bShow, nStatus);
- //DEL }
- void LockForm::MoveControls()
- {
- int ScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
- int ScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
- RECT r,r1;
- DWORD dx,dy;
- //GetWindowRect(&r);
- m_cFrame.GetWindowRect(&r1);
- m_cFrame.MoveWindow((ScreenWidth-(r1.right-r1.left))/2,(ScreenHeight-(r1.bottom-r1.top))/2,(r1.right-r1.left),(r1.bottom-r1.top) );
- m_cFrame.GetWindowRect(&r);
- dx=r.left-r1.left ;
- dy=r.top-r1.top;
- m_cHeadLine.GetWindowRect(&r1);
- m_cHeadLine.MoveWindow(r1.left+dx,r1.top+dy,r1.right-r1.left,r1.bottom-r1.top );
- m_cInPw.GetWindowRect(&r1);
- m_cInPw.MoveWindow(r1.left+dx,r1.top+dy,r1.right-r1.left,r1.bottom-r1.top );
- SetCursorPos(r1.left,r1.top );
- mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
- mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
- m_cStatus.GetWindowRect(&r1);
- m_cStatus.MoveWindow(r1.left+dx,r1.top+dy,r1.right-r1.left,r1.bottom-r1.top );
- m_cUnlock.GetWindowRect(&r1);
- m_cUnlock.MoveWindow(r1.left+dx,r1.top+dy,r1.right-r1.left,r1.bottom-r1.top );
- m_cUnlock.GetWindowRect(&r1);
- SetCursorPos(r1.left,r1.top );
- ClipCursor(&r1);
- }
- LRESULT LockForm::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- if (message==WM_USER) {
- //CString PWLib("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890");
- if (lParam && m_vInPw.GetLength()<20) {
- UpdateData(TRUE);
- if (m_vStatus=="Invalid Password!")m_vStatus="Click Unlock...";
- m_vInPw=m_vInPw + " ";
- m_vInPw.SetAt(m_vInPw.GetLength()-1,(char)lParam);
- UpdateData(FALSE);
- }
- switch(wParam) {
- case VK_RETURN:if(OnButtonUnlock())return TRUE;
- break;
- case VK_DELETE:{m_vInPw="";UpdateData(FALSE);}
- break;
- case VK_BACK:{m_vInPw=m_vInPw.Left(m_vInPw.GetLength()-1);UpdateData(FALSE);};
- break;
- case VK_LEFT:{m_vInPw=m_vInPw.Left(m_vInPw.GetLength()-1);UpdateData(FALSE);};
- break;
- case VK_CONTROL:{m_cInPw.SetSel(0,-1);};
- break;
- default:
- break;
- }
- m_cInPw.SetSel(m_vInPw.GetLength(),m_vInPw.GetLength());
- TRACE("lastCode:%dn",wParam);
- return TRUE;
- }
- return CDialog::WindowProc(message, wParam, lParam);
- }
- HBRUSH LockForm::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- if (nCtlColor == CTLCOLOR_DLG||nCtlColor == CTLCOLOR_STATIC) {
- pDC->SetBkColor(RGB(58,110,165)); // desktop
- return m_hDesktopBrush;
- }
- return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- }
- BOOL LockForm::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_hDesktopBrush.CreateSolidBrush(RGB(58,110,165));
- return FALSE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }