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

📄 starclockdlg.cpp

📁 用DE2开发交通灯控制器
💻 CPP
字号:
// starclockDlg.cpp : implementation file
//

#include "stdafx.h"
#include "starclock.h"
#include "starclockDlg.h"
#include "resource.h"

#include "MyDlg.h"
#include <Mmsystem.h>				//
#pragma comment(lib,"winmm.lib")	//sndPlaySound()

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

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

void showtime()
{
	CTime time;
	CString strTime;
	while(1)
	{
		time=CTime::GetCurrentTime();
		strTime=time.Format("%H:%M:%S");
		::SetDlgItemText(AfxGetMainWnd()->m_hWnd,IDC_EDIT1,strTime);
		Sleep(1000);
	}
}

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()

/////////////////////////////////////////////////////////////////////////////
// CStarclockDlg dialog

CStarclockDlg::CStarclockDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStarclockDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStarclockDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	this->nCheck = 1;
}

void CStarclockDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStarclockDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CStarclockDlg, CDialog)
	ON_WM_CONTEXTMENU()
	//{{AFX_MSG_MAP(CStarclockDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(IDC_GIVE_TIME, OnGiveTime)
	ON_COMMAND(IDC_NOT_GIVE_TIME, OnNotGiveTime)
	ON_BN_CLICKED(IDC_GIVE_TIME, OnGiveTime)
	ON_BN_CLICKED(IDC_NOT_GIVE_TIME, OnNotGiveTime)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStarclockDlg message handlers

BOOL CStarclockDlg::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
	SetWindowPos(&wndTopMost,600,-3,110,23,SWP_HIDEWINDOW);				//设置窗口大小位置
	SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,WS_EX_TOOLWINDOW);	//隐藏任务栏
//*************************************
//拒绝输入
//*************************************

	//BlockInput(TRUE);		//屏蔽键盘和鼠标 (整个系统) 除 Ctrl+Alt+Del
	//BlockInput(FALSE);	//解除屏蔽

	//CWnd * pWnd=(CWnd *)AfxGetApp()->GetMainWnd();
	//::EnableWindow(*pWnd,FALSE);		//屏蔽窗口, 对键盘不起作用

	//在PreTranslateMessage(MSG *pMsg) 中已经实现

//*************************************
//拒绝输入
//*************************************

	hThread=CreateThread(NULL,
		0,
		(LPTHREAD_START_ROUTINE)showtime,
		NULL,
		0,
		&ThreadID);

	
	SetTimer(1,1000,NULL);
	GetDlgItem(IDC_GIVE_TIME)->EnableWindow(FALSE);
	GetDlgItem(IDC_NOT_GIVE_TIME)->EnableWindow(TRUE);

	CMyDlg * pdlg = new CMyDlg();
	pdlg->DoModal();
	delete []pdlg;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CStarclockDlg::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 CStarclockDlg::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 CStarclockDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CStarclockDlg::OnGiveTime() 
{
	// TODO: Add your command handler code here	
	nCheck = 0;
	SetTimer(1,1000,NULL);
	GetDlgItem(IDC_GIVE_TIME)->EnableWindow(FALSE);
	GetDlgItem(IDC_NOT_GIVE_TIME)->EnableWindow(TRUE);
}

void CStarclockDlg::OnNotGiveTime() 
{
	// TODO: Add your command handler code here
	nCheck = 1;
	KillTimer(1);
	GetDlgItem(IDC_GIVE_TIME)->EnableWindow(TRUE);
	GetDlgItem(IDC_NOT_GIVE_TIME)->EnableWindow(FALSE);
}

BOOL CStarclockDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message == WM_KEYDOWN && 
		(pMsg->wParam == VK_ESCAPE
		|| pMsg->wParam == VK_RETURN
		|| pMsg->wParam == VK_SPACE
		))
		return TRUE;
	return CDialog::PreTranslateMessage(pMsg);
}


void CStarclockDlg::swit(int thour)
{
	int hour = thour;
	switch(hour)
	{
	case 6:  sndPlaySound("c:\\clock\\06.wav",SND_SYNC);break;
	case 7:  sndPlaySound("c:\\clock\\07.wav",SND_SYNC);break;
	case 8:  sndPlaySound("c:\\clock\\08.wav",SND_SYNC);break;
	case 9:  sndPlaySound("c:\\clock\\09.wav",SND_SYNC);break;
	case 10: sndPlaySound("c:\\clock\\10.wav",SND_SYNC);break;
	case 11: sndPlaySound("c:\\clock\\11.wav",SND_SYNC);break;
	case 12: sndPlaySound("c:\\clock\\12.wav",SND_SYNC);break;
	case 13: sndPlaySound("c:\\clock\\13.wav",SND_SYNC);break;
	case 14: sndPlaySound("c:\\clock\\14.wav",SND_SYNC);break;
	case 15: sndPlaySound("c:\\clock\\15.wav",SND_SYNC);break;
	case 16: sndPlaySound("c:\\clock\\16.wav",SND_SYNC);break;
	case 17: sndPlaySound("c:\\clock\\17.wav",SND_SYNC);break;
	case 18: sndPlaySound("c:\\clock\\18.wav",SND_SYNC);break;
	case 19: sndPlaySound("c:\\clock\\19.wav",SND_SYNC);break;
	case 20: sndPlaySound("c:\\clock\\20.wav",SND_SYNC);break;
	case 21: sndPlaySound("c:\\clock\\21.wav",SND_SYNC);break;
	case 22: sndPlaySound("c:\\clock\\22.wav",SND_SYNC);break;
	case 23: sndPlaySound("c:\\clock\\23.wav",SND_SYNC);break;
	case 0:
	case 1:
	case 2:
	case 3:
	case 4:
	case 5:  sndPlaySound("c:\\clock\\00.wav",SND_SYNC);break;
	default: break;
	}
}

void CStarclockDlg::saytime()
{
	CTime time;
	CString strTime;
	time=CTime::GetCurrentTime();
	if(time.GetMinute()==0 && time.GetSecond()==0)
	{
		int hour = time.GetHour();
		KillTimer(1);
		swit(hour);
		SetTimer(1,1000,NULL);
	}
}

void CStarclockDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	saytime();
	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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