www.gusucode.com > VC++挂机锁屏系统源程序源码程序 > VC++挂机锁屏系统源程序源码程序\code\LOCKDlg.cpp

    // LOCKDlg.cpp : implementation file
/*----------------------------------------------------------------------------*/
//
//	文件:		LOCKDlg.cpp
//  版本:      1.0
//	作者:		蔡亦汤
//	创建时间:	2007 3 26
//  EMAIL:      caiyitang2003@163.com
/*----------------------------------------------------------------------------
/*
/* Copyright (C) 2007-2008 by  LeoSoftware
/* All Rights Reserved.
/*
/*----------------------------------------------------------------------------*/
// Download by http://www.NewXing.com
///////////////////////////////////////功能说明 ////////////////////////////////////////
//登陆窗口
////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "LOCK.h"
#include "LOCKDlg.h"
#include "PINGMUDlg.h"
#include "UNLOCKDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLOCKDlg dialog

CLOCKDlg::CLOCKDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLOCKDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLOCKDlg)
	m_password = _T("");        //设置密码
	m_passwordagain = _T("");   //确认密码
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

CLOCKDlg::~CLOCKDlg()
{
	
	if (m_Shuomingdlg != NULL)
		m_Shuomingdlg->DestroyWindow();    //关闭说明窗口
	delete m_Shuomingdlg;                  //释放窗口指针
	
}

void CLOCKDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLOCKDlg)
	DDX_Text(pDX, IDC_SET, m_password);
	DDX_Text(pDX, IDC_SETAGAIN, m_passwordagain);
	DDX_Control(pDX, IDC_SET, m_password_edit);      //增加有热点的编辑控件
	DDX_Control(pDX, IDC_SETAGAIN, m_passwordagain_edit);    //增加有热点的编辑控件
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CLOCKDlg, CDialog)
	//{{AFX_MSG_MAP(CLOCKDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_LOCKBUTTON, OnLockbutton)
	ON_WM_DESTROY()
	ON_WM_CLOSE()
	ON_WM_MOUSEMOVE()
	ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
	ON_WM_CREATE()
	ON_BN_CLICKED(IDC_HELPBUTTON, OnHelpbutton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLOCKDlg message handlers

BOOL CLOCKDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW);     //使窗口不显示在任务栏

    //退出按钮的设计
	m_Cancel.SubclassDlgItem (IDC_BUTTON_EXIT, this);
	m_Cancel.SetIcon (IDI_CANCEL);
	m_Cancel.SetColor (CButtonST::BTNST_COLOR_BK_IN, RGB(198, 211, 238));
	m_Cancel.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(231,239,245));
    m_Cancel.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(231,239,245));
    m_Cancel.OffsetColor(CButtonST::BTNST_COLOR_BK_IN,30);
    
	//挂机锁屏按钮设计
	m_Lock.SubclassDlgItem (IDC_LOCKBUTTON, this);
	m_Lock.SetIcon (IDI_LOCK);
	m_Lock.SetColor (CButtonST::BTNST_COLOR_BK_IN, RGB(198, 211, 238));
	m_Lock.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(231,239,245));
	m_Lock.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(231,239,245));
	m_Lock.OffsetColor(CButtonST::BTNST_COLOR_BK_IN,30);
    
	//帮助按钮设计
	m_Help.SubclassDlgItem (IDC_HELPBUTTON, this);
	m_Help.SetIcon (IDI_HELP);
	m_Help.SetColor (CButtonST::BTNST_COLOR_BK_IN, RGB(198, 211, 238));
	m_Help.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(231,239,245));
	m_Help.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(231,239,245));
	m_Help.OffsetColor(CButtonST::BTNST_COLOR_BK_IN,30);
    
	//静态控件设计
	m_Static1.SubclassDlgItem(IDC_STATIC1,this);
	m_Static1.SetCaption(" 设置密码:");
	m_Static1.SetBackColor(RGB(208,208,208));
	m_Static1.SetTextColor(RGB(255, 0, 0));

	//静态控件设计
	m_Static2.SubclassDlgItem(IDC_STATIC2,this);
	m_Static2.SetCaption(" 确认:");
	m_Static2.SetBackColor(RGB(208,208,208));
	m_Static2.SetTextColor(RGB(255, 0, 0));

	m_hIcon1 = (HICON)::LoadImage(AfxFindResourceHandle(MAKEINTRESOURCE(IDI_TIP1), RT_GROUP_ICON), MAKEINTRESOURCE(IDI_TIP1), IMAGE_ICON, 0, 0, 0);
	m_hIcon2 = (HICON)::LoadImage(AfxFindResourceHandle(MAKEINTRESOURCE(IDI_TIP2), RT_GROUP_ICON), MAKEINTRESOURCE(IDI_TIP2), IMAGE_ICON, 0, 0, 0);

	// 创建工具提示
	m_Tip.Create(this);

	// 加到要提示的工具里
	m_Tip.AddTool(GetDlgItem(IDC_SET), _T("请输入密码!"), m_hIcon1);
	m_Tip.AddTool(GetDlgItem(IDC_SETAGAIN), _T("请输入密码确认!"), m_hIcon2);
	m_Tip.AddTool(GetDlgItem(IDC_LOCKBUTTON), _T("挂机锁住屏幕!"), m_hIcon1);
	m_Tip.AddTool(GetDlgItem(IDC_BUTTON_EXIT), _T("退出系统!"), m_hIcon1);
	m_Tip.AddTool(GetDlgItem(IDC_HELPBUTTON), _T("帮助说明!"), m_hIcon1);
	
	//创建二进制密码文件
	m_strFile = "psw.DAT";
    
	//创建说明窗口
	m_Shuomingdlg = new CSHUOMINGDlg;
	m_Shuomingdlg->Create(IDD_SHUOMING_DIALOG,NULL);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CLOCKDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CLOCKDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		
		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CPaintDC dc(this);
		CRect rect;
        GetClientRect(&rect);    //得到窗体的大小
        CDC dcMem; 
        dcMem.CreateCompatibleDC(&dc); 
        CBitmap bmpBackground;
        bmpBackground.LoadBitmap(IDB_BITMAPBK);    //加载背景图片
        BITMAP bitMap;
        bmpBackground.GetBitmap(&bitMap);
        CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
        dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);
	}
	
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CLOCKDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CLOCKDlg::OnLockbutton() 
{
	// TODO: Add your control notification handler code here
	CWRONGDlg wrongdlg;    //错误提示窗口

	UpdateData(TRUE);      //更新编辑框
	
	if (m_password == "")  //如果密码为空
	{
        wrongdlg.m_strTitle.Format("欢迎使用小蔡软件!");
		wrongdlg.m_strText.Format("对不起!\r\n密码不能为空!\r\n请输入密码!");
		wrongdlg.DoModal();                 //打开错误提示窗口
	    GetDlgItem(IDC_SET)->SetFocus();    //设置焦点
        UpdateData(FALSE);
		
	}
	else
	{
      if (m_password != m_passwordagain)    //如果两次输入的密码不相同
	  {

        wrongdlg.m_strTitle.Format("欢迎使用小蔡软件!");
		wrongdlg.m_strText.Format("对不起!\r\n两次的密码不相同!\r\n请重新输入!");
		wrongdlg.DoModal();                 //打开错误提示窗口
		m_passwordagain.Empty();            
		GetDlgItem(IDC_SETAGAIN)->SetFocus();//设置焦点
		UpdateData(FALSE);
			
	  }
	  else   //两次密码不为空且一样
	  {

		WriteFile(m_password);     //将密码写入文件
	    ShowWindow(SW_HIDE);       //隐藏登陆窗口
	    CPINGMUDlg pingmudlg;      
	    pingmudlg.DoModal();       //打开挂屏窗口
		//CUNLOCKDlg dlg;
		//dlg.DoModal();
		 
	  }
	}
    

}

BOOL CLOCKDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CDialog::DestroyWindow();
}


BOOL CLOCKDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	//按下ESC和回车键窗口不退出
	if( pMsg->message == WM_KEYDOWN)   
    {  
		if(pMsg->wParam == VK_ESCAPE)   
            return   TRUE;   
		if(pMsg->wParam == VK_RETURN)
		{
			
			return   TRUE; 
		
		}
     } 
	
	m_Tip.RelayEvent(pMsg);    //响应工具提示消息

	return CDialog::PreTranslateMessage(pMsg);
}

void CLOCKDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	::DestroyIcon(m_hIcon1);   //释放m_hIcon1
	::DestroyIcon(m_hIcon2);   //释放m_hIcon2
	
	DeleteFile(m_strFile);    //删除密码文件

}

//关闭窗口
void CLOCKDlg::OnClose()       
{
	// TODO: Add your message handler code here and/or call default
	CLOCKDlg::OnDestroy();
	CDialog::OnClose();
}


/////////////////////////////////////////////////////////////////////
// 函数:
//      CLOCKDlg::WriteFile()
// 
// 描述:
//     
//		创建密码文件,将密码写入
//
// 返回:
//
//		[void]	
//
// 参数:
//
//		[str]			- 要写入的密码字符串
//     
/////////////////////////////////////////////////////////////////////

void CLOCKDlg::WriteFile(CString str)
{
	CFile file;
	if (file.Open(m_strFile,CFile::modeCreate|CFile::modeWrite))    //创建文件且可以写
	{
		char buffer[1024];    //设置缓存的大小
		int nLen = sprintf(buffer,"%s",str);    //将str写入缓存
		buffer[nLen] = 0;
		file.Write(buffer,1024);    //将str写入文件
		file.Close();
	}
	

}

void CLOCKDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CRect rect;
	if (m_Shuomingdlg != NULL)
	{
		GetDlgItem(IDC_STATIC_SHUOMING)->GetWindowRect(&rect);  //得到控件IDC_STATIC_SHUOMING的大小
		ScreenToClient(&rect);    //转化为客户坐标

		if (rect.PtInRect(point))    //如果鼠标在控件IDC_STATIC_SHUOMING上
		{
			ClientToScreen(&rect);   //转化为屏幕坐标
			m_Shuomingdlg->SetWindowPos(this, rect.left, rect.top, 100, 100, SWP_NOSIZE);
			m_Shuomingdlg->SetActiveWindow();
			m_Shuomingdlg->UpdateWindow();
			m_Shuomingdlg->ShowWindow(SW_SHOW);	   //显示说明窗口
		}
		else
			m_Shuomingdlg->ShowWindow(SW_HIDE);	  //光标不在图上,则隐藏说明窗口
	}

	CDialog::OnMouseMove(nFlags, point);
}

void CLOCKDlg::OnButtonExit() 
{
	// TODO: Add your control notification handler code here
	OnDestroy();
	OnCancel();
}

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

	return 0;
}

void CLOCKDlg::OnHelpbutton() 
{
	// TODO: Add your control notification handler code here
	TCHAR bufDir[_MAX_PATH];
	CString dS1,dS2;
	dS1 += "帮助.txt";
	GetWindowsDirectory(bufDir,_MAX_PATH);    //得到"帮助.txt"的路径
	dS2.Format("%s\\NOTEPAD.exe  %s",bufDir,dS1);
	WinExec(dS2,SW_NORMAL);                   //调用程序NOTEPAD.exe打开"帮助.txt"
}