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

📄 倒计时dlg.cpp

📁 代码Move是一个在屏幕上跑来跑去的小鱼。 代码 倒计时 是一个简单的倒计时控制器
💻 CPP
字号:
// 倒计时Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "倒计时.h"
#include "倒计时Dlg.h"
#define ZEROTIME 57600
#define ID_MYICON  1221
#define MYWM_NOTIFYICON WM_USER+100
#define MAXICON  12
#define SZTIP "倒计时开始,还剩"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
	m_Time=ZEROTIME;
	m_File = _T("");
	m_operation = 0;
	m_type = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER, m_Time);
	DDX_Text(pDX, IDC_FILE, m_File);
	DDX_Radio(pDX, IDC_EXIT, m_operation);
	DDX_CBIndex(pDX, IDC_COMBO1, m_type);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	ON_BN_CLICKED(IDC_APP, OnApp)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	ON_MESSAGE(MYWM_NOTIFYICON,OnMyNotifyIcon)
	ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER, OnDatetimechangeDatetimepicker)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

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

	// 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
	const CWnd * pWndInsertAfter;
	pWndInsertAfter = &wndTopMost;
	SetWindowPos(pWndInsertAfter,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE|SWP_HIDEWINDOW);

	UpdateData(FALSE);m_icon=0;
	m_hMyIcon[0]=AfxGetApp()->LoadIcon(IDI_ICON);
	m_hMyIcon[1]=AfxGetApp()->LoadIcon(IDI_ICON1);
	m_hMyIcon[2]=AfxGetApp()->LoadIcon(IDI_ICON2);
	m_hMyIcon[3]=AfxGetApp()->LoadIcon(IDI_ICON3);
	m_hMyIcon[4]=AfxGetApp()->LoadIcon(IDI_ICON4);
	m_hMyIcon[5]=AfxGetApp()->LoadIcon(IDI_ICON5);
	m_hMyIcon[6]=AfxGetApp()->LoadIcon(IDI_ICON6);
	m_hMyIcon[7]=AfxGetApp()->LoadIcon(IDI_ICON7);
	m_hMyIcon[8]=AfxGetApp()->LoadIcon(IDI_ICON8);
	m_hMyIcon[9]=AfxGetApp()->LoadIcon(IDI_ICON9);
	m_hMyIcon[10]=AfxGetApp()->LoadIcon(IDI_ICON10);
	m_hMyIcon[11]=AfxGetApp()->LoadIcon(IDI_ICON11);

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

// 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 CMyDlg::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
	{
		CDialog::OnPaint();
	}
}

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

void CMyDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	
	CFileDialog m_MyFile(TRUE,
		"exe",
		NULL,
		OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,
		"可执行文件(*.exe) | *.exe|所有文件(*.*)|*.*|",
		AfxGetMainWnd());
	if(m_MyFile.DoModal()==IDOK)
	{
		m_Filename=m_MyFile.GetPathName();
		m_File=m_MyFile.GetFileName();
		UpdateData(FALSE);
	}
}

void CMyDlg::OnExit() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_COMBO1)->EnableWindow(TRUE);
	GetDlgItem(IDC_OPEN)->EnableWindow(FALSE);
	m_operation=0;
	UpdateData(FALSE);
}

void CMyDlg::OnApp() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_COMBO1)->EnableWindow(FALSE);
	GetDlgItem(IDC_OPEN)->EnableWindow(TRUE);
	m_operation=1;
	UpdateData(FALSE);
}

void CMyDlg::OnSelchangeCombo1() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CMyDlg::OnOK() 
{
	// TODO: Add extra validation here

	data.cbSize=sizeof(NOTIFYICONDATA);
	data.hWnd=AfxGetMainWnd()->m_hWnd;
	data.uID=ID_MYICON;
	data.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
	data.uCallbackMessage=MYWM_NOTIFYICON;
	data.hIcon=m_hIcon;
	strcpy(data.szTip,SZTIP);
	Shell_NotifyIcon(NIM_ADD,&data);
	UpdateData();
	ShowWindow(SW_HIDE);
	if(m_Time.GetTime()>=ZEROTIME) count=(m_Time.GetTime()-ZEROTIME)*1000;
		else count=(ZEROTIME-m_Time.GetTime())*1000;
	tick=GetTickCount();tick1=0;
	SetTimer(1,100,NULL);
}
LRESULT CMyDlg::OnMyNotifyIcon(WPARAM wParam,LPARAM lParam)
{
	switch(lParam)
	{
	case WM_LBUTTONDBLCLK:
		{
			if(wParam==ID_MYICON)
			{
				UpdateData(FALSE);
				ShowWindow(SW_SHOW);
				KillTimer(1);
				SetForegroundWindow();
				NOTIFYICONDATA data;
				data.cbSize=sizeof(NOTIFYICONDATA);
				data.hWnd=AfxGetMainWnd()->m_hWnd;
				data.uID=ID_MYICON;
				Shell_NotifyIcon(NIM_DELETE,&data);
			}
			break;
		}
	default: break;
	}
	return 0L;
}

void CMyDlg::OnDatetimechangeDatetimepicker(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	*pResult = 0;
}

void CMyDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	tick1=GetTickCount()-tick;
	if(tick1>=count)
	{
		KillTimer(1);
		switch(m_operation)
		{
		case 0:
			{
				switch (m_type)
				{
				case 0:ExitWindowsEx(EWX_SHUTDOWN,NULL);break;
				case 1:ExitWindowsEx(EWX_REBOOT,NULL);break;
				case 2:ExitWindowsEx(EWX_LOGOFF,NULL);break;
				default:ExitWindowsEx(EWX_POWEROFF,NULL);break;
				}
				break;
			}
		case 1:ShellExecute(NULL,"open",m_Filename,NULL,NULL,SW_SHOW);break;
		}
		
		OnMyNotifyIcon(ID_MYICON,WM_LBUTTONDBLCLK);
	}
	else
	{
		char hour[3],min[3],sec[3];
		int h,m,s;
		h=m_Time.GetHour(); m=m_Time.GetMinute();s=m_Time.GetSecond();
		m_Time=(count-tick1)/1000+ZEROTIME;;
		itoa(h,hour,10);
		itoa(m,min,10);
		itoa(s,sec,10);
		data.hIcon=m_hMyIcon[m_icon];
		strcpy(data.szTip,SZTIP);
		if(h>0) { strcat(data.szTip,hour); strcat(data.szTip,"小时"); }
		if(m>0) { strcat(data.szTip,min); strcat(data.szTip,"分钟"); }
		if(s>0)	{ strcat(data.szTip,sec); strcat(data.szTip,"秒钟"); }
		Shell_NotifyIcon(NIM_MODIFY,&data);
		m_icon++; if(m_icon>=MAXICON) m_icon=0;
	}

	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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