⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 secdialog.cpp

📁 操作系统上的动态连接
💻 CPP
字号:
// SecDialog.cpp : implementation file
//

#include "stdafx.h"
#include "GOGO.h"
#include "SecDialog.h"

#include <MMSYSTEM.h>
#pragma comment(lib,"winmm.lib")//媒体库~
#undef WINVER
#define WINVER 0X500 


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int length;
int key[5][10]={
		0,1,2,3,4,5,6,7,8,9,
		0,2,4,6,8,1,3,5,7,9,
		1,3,5,7,9,0,2,4,6,8,
		9,7,5,3,1,8,6,4,2,0,
		8,6,4,2,0,9,7,5,3,1	};//设置密码

SecDialog pt;

/////////////////////////////////////////////////////////////////////////////
// SecDialog dialog


SecDialog::SecDialog(CWnd* pParent /*=NULL*/)
	: CDialog(SecDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(SecDialog)
	m_check = _T("");
	//}}AFX_DATA_INIT
}


void SecDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(SecDialog)
	DDX_Control(pDX, IDC_KEY, m_key);
	DDX_Control(pDX, IDC_TIME, m_time);
	DDX_Text(pDX, IDC_CHECK, m_check);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(SecDialog, CDialog)
	//{{AFX_MSG_MAP(SecDialog)
	ON_WM_CREATE()
	ON_WM_TIMER()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// SecDialog message handlers

int SecDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	SetTimer(1,1000,NULL);//设置时间
	
	return 0;
}

BOOL SecDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	srand((unsigned)time(NULL));
    i=rand()%5;
	pr=key[i];
	strcpy(str,"");
	length=10;
	LeftTime=30;
	CEdit *pwnd=(CEdit*)GetDlgItem(IDC_CHECK);
	CButton *pwnd2=(CButton*)GetDlgItem(IDOK);
	pwnd2->EnableWindow(false);//按钮不可用
	pwnd->EnableWindow(false);
	PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(), SND_ASYNC|SND_RESOURCE|SND_NODEFAULT|SND_LOOP); //播放音乐
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void SecDialog::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnTimer(nIDEvent);
	char str2[15];
	if(LeftTime>=0)
	{
		if(length>0)
		{
			itoa(key[i][length-1],mystr,10);
			strcat(str,mystr);
			m_key.SetWindowText(CString(str));//显示内容
			length--;
		}
		else
		{
			m_key.SetWindowText(CString("**********"));
			CEdit *pwnd=(CEdit*)GetDlgItem(IDC_CHECK);
			CButton* pwnd2=(CButton*)GetDlgItem(IDOK);
			pwnd->SetFocus();
			pwnd->EnableWindow(true);
			pwnd2->EnableWindow(true);
		}
		
        itoa(LeftTime,str2,10);
	    m_time.SetWindowText(CString(str2));
	    LeftTime--;
	}
	else
	{
		AfxMessageBox("time out!",MB_ICONSTOP);
	    KillTimer(1);	  
	}

}

void SecDialog::OnOK() 
{
	UpdateData(true);
	char str1[5];
	char str2[50];
	strcpy(str2,"");
	int num=10;
	int num2=10;
    int *password;
	char *compare;
    password=pr;
	compare=(char*)LPCTSTR(m_check);
	while(num>0)
	{
		itoa(*password,str1,10);
		strcat(str2,str1);
		password++;
		num--;
	}
	if(strcmp(str2,compare)==0)
	{
		AfxMessageBox("congretulation!you pass",MB_ICONINFORMATION);
		CDialog::OnOK();
	    
	}
	else
	{
		MessageBox("you are wrong!please go on!");
		CEdit *pwnd=(CEdit*)GetDlgItem(IDC_CHECK);
		pwnd->SetFocus();
		m_check="";
		UpdateData(false);
        strcpy(str,"");
		while(num2>0)
		{
			itoa(key[i][num2-1],mystr,10);
			strcat(str,mystr);
			m_key.SetWindowText(CString(str));//显示内容
			num2--;
		}
	}
}

void SecDialog::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CRect rect;
    GetClientRect(&rect);//得到窗体的大小
    CDC dcMem;
    dcMem.CreateCompatibleDC(&dc);
    CBitmap bmpBackground;
    bmpBackground.LoadBitmap(IDB_BITMAP1);//加载背景图片
    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);//该函数给对话框贴上位图
	
	// Do not call CDialog::OnPaint() for painting messages
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -