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

📄 myclockdlg.cpp

📁 这是多功能时钟的源程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MyClockDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "MyClock.h"
#include "MyClockDlg.h"
#include "About.h"
#include <cmath>
#include "ZLDDLG.h"
#include "SETTIME.h"
#include "LockComputer.h"
#include "ZYSQTS.h"
#include "TiShiDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define pi 2.0*asin(1.0)

// CMyClockDlg 对话框

CMyClockDlg::CMyClockDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyClockDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_BDBSTime=true;
	m_ZDBSTime=true;
	m_IsAutoRun=true;
	m_IsTopMost=true;
	m_strBDBS=_T("1");
	m_strZDBS=_T("1");
	m_strAutoRun=_T("1");
	m_strTopMost=_T("1");
	str="隐藏时钟";
}

void CMyClockDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CMyClockDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_WM_LBUTTONDOWN()
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_ABOUT, &CMyClockDlg::OnAbout)
	ON_COMMAND(ID_EXIT, &CMyClockDlg::OnExit)
	ON_WM_TIMER()
	ON_COMMAND(ID_BSTIME, &CMyClockDlg::OnBstime)
	ON_UPDATE_COMMAND_UI(ID_32788, &CMyClockDlg::OnUpdate32788)
	ON_UPDATE_COMMAND_UI(ID_ZDBS, &CMyClockDlg::OnUpdateZdbs)
	ON_WM_INITMENUPOPUP()
	ON_COMMAND(ID_32788, &CMyClockDlg::On32788)
	ON_COMMAND(ID_ZDBS, &CMyClockDlg::OnZdbs)
	ON_COMMAND(ID_ZL, &CMyClockDlg::OnZl)
	ON_COMMAND(ID_AUTORUN, &CMyClockDlg::OnAutorun)
	ON_UPDATE_COMMAND_UI(ID_AUTORUN, &CMyClockDlg::OnUpdateAutorun)
	ON_COMMAND(ID_TOPMOST, &CMyClockDlg::OnTopmost)
	ON_UPDATE_COMMAND_UI(ID_TOPMOST, &CMyClockDlg::OnUpdateTopmost)
	ON_MESSAGE(WM_TRARMESSAGE,OnTrayMessage)
	ON_COMMAND(ID_DSGJ, &CMyClockDlg::OnDsgj)
	ON_COMMAND(ID_KSGJ, &CMyClockDlg::OnKsgj)
	ON_COMMAND(ID_ISHIDE, &CMyClockDlg::OnIshide)
	ON_UPDATE_COMMAND_UI(ID_ISHIDE, &CMyClockDlg::OnUpdateIshide)
	ON_COMMAND(ID_ZYSQTS, &CMyClockDlg::OnZysqts)
	ON_COMMAND(ID_LockComputer, &CMyClockDlg::OnLockcomputer)
END_MESSAGE_MAP()


// CMyClockDlg 消息处理程序

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

	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码
	ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);//窗口不在任务栏显示
	this->AddIcon(true);
	this->ReadFile1();
	this->ReadFile2();
	this->TopMost(m_IsTopMost);//窗口置于最顶层
	this->AutoRun(m_IsAutoRun);//开机自动运行本程序
	CDC *pDC;
	CDC memDC;
	pDC=GetDC();
	CBitmap bitmap;
	CBitmap *pOldBitmap=NULL;
	bitmap.LoadBitmap(IDB_BITMAP1);
	memDC.CreateCompatibleDC(pDC);
	pOldBitmap=memDC.SelectObject(&bitmap);
	CRect rect;
	CRgn rgn,temp;
	GetWindowRect(rect);
	rgn.CreateRectRgn(0,0,rect.Width(),rect.Height());
	int x,y;
	COLORREF color;
	for(x=0;x<rect.Width();x++)
	{
		for(y=0;y<rect.Height();y++)
		{
			color=memDC.GetPixel(x,y);
			if(color==RGB(0,0,0))
			{
				temp.CreateRectRgn(x,y,x+1,y+1);
				rgn.CombineRgn(&rgn,&temp,RGN_XOR);
				temp.DeleteObject();
			}
		}
	}
	if(pOldBitmap)
	{
		memDC.SelectObject(pOldBitmap);
	}
	CenterWindow();
	SetWindowRgn((HRGN)rgn,true);
	ReleaseDC(pDC);
	rect.right=rect.left+200;
	rect.bottom=rect.top+200;
	MoveWindow(rect,true);

	time = CTime::GetCurrentTime();
	if(hour>12)
	{
		hour=hour-12;
	}
	sec = time.GetSecond();
	min = time.GetMinute();
	hour = time.GetHour();
	SetTimer(1,1000,NULL);

	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。

void CMyClockDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		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;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		this->ShowTime();
		CDialog::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CMyClockDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CMyClockDlg::ShowClock(UINT id)
{
	
}

void CMyClockDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));

	CDialog::OnLButtonDown(nFlags, point);
}

void CMyClockDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	CMenu menu;
	menu.LoadMenu(IDR_MENU1);
	CMenu *pmenu=menu.GetSubMenu(0);
	ClientToScreen(&point);
	pmenu->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN,point.x,point.y,this);
	pmenu->DestroyMenu();
	CDialog::OnRButtonDown(nFlags, point);
}

void CMyClockDlg::OnAbout()
{
	// TODO: Add your command handler code here
	CAbout dlg;
	dlg.DoModal();
}

void CMyClockDlg::OnExit()
{
	// TODO: Add your command handler code here
	this->AddIcon(false);
	CDialog::OnOK();
}
extern int m_Emonth,m_Eday,m_Ehour,m_Eminute,m_Esecond;
void CMyClockDlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
	this->ShowTime();
	this->BDZDTime();
	CTime time=CTime::GetCurrentTime();
	if(m_Emonth==time.GetMonth()&&m_Eday==time.GetDay()&&m_Ehour==time.GetHour()
		&&m_Eminute==time.GetMinute()&&m_Esecond==time.GetSecond())
	{
		CTiShiDlg dlg;
		dlg.DoModal();
	}
	CDialog::OnTimer(nIDEvent);
}
void CMyClockDlg::FillBitmap()//加载位图
{
	CDC *pDC=GetDC();
	CBitmap bitmap;
	bitmap.LoadBitmap(IDB_BITMAP1);
	CRect rect;
	GetClientRect(rect);
	CBrush brush(&bitmap);
	pDC->SelectObject(&brush);
	pDC->FillRect(rect,&brush);
	this->ReleaseDC(pDC);
}
void CMyClockDlg::ShowTime()//显示表针
{
	int min1;
	min1=min+hour*60;
	
	CDC *pDC=this->GetDC();
	CPen pen1(PS_SOLID,1,RGB(0,0,255));
    CPen pen2(PS_SOLID,2,RGB(0,0,255));
	CPen pen3(PS_SOLID,3,RGB(0,0,255));
	CPen *pOldPen;
	this->FillBitmap();
	int x=102;
    int y=100;
	pOldPen=pDC->SelectObject(&pen1);
	pDC->MoveTo (x,y);
    pDC->LineTo (x+(long)55*cos(pi/2-2*pi*sec/60.0),y-(long)55*sin(pi/2-2*pi*sec/60.0));
	pDC->SelectObject(&pen2);
	pDC->MoveTo (x,y);
    pDC->LineTo (x+(long)45*cos(pi/2-2*pi*min/60.0),y-(long)45*sin(pi/2-2*pi*min/60.0));

	pDC->SelectObject(&pen3);
	pDC->MoveTo (x,y);
    //pDC->LineTo (x+(long)35*cos(pi/2-5*2*pi*hour/60.0),y-(long)35*sin(pi/2-5*2*pi*hour/60.0));
	pDC->LineTo (x+(long)35*cos(pi/2-2*pi*min1/60.0/12.0),y-(long)35*sin(pi/2-2*pi*min1/60.0/12.0));//时针的移动位置
	
	sec = sec+1;
	if(sec==60)
	{
		sec=0;
		min=min+1;
		if(min==60)
		{
			hour=hour+1;
			min=0;
		}
		
	}

	if(pOldPen)
	{
		pDC->SelectObject(pOldPen);
	}
	this->ReleaseDC(pDC);
}

void CMyClockDlg::OnBstime()
{
	// TODO: Add your command handler code here
	ShellExecute(this->m_hWnd,_T("open"),_T("FXTime.exe"),_T(""),_T(""),SW_SHOW);
}

void CMyClockDlg::OnUpdate32788(CCmdUI *pCmdUI)
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_BDBSTime);
}

void CMyClockDlg::OnUpdateZdbs(CCmdUI *pCmdUI)
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_ZDBSTime);
}

void CMyClockDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
	CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
	ASSERT(pPopupMenu != NULL);
    // Check the enabled state of various menu items.

    CCmdUI state;
    state.m_pMenu = pPopupMenu;
    ASSERT(state.m_pOther == NULL);
    ASSERT(state.m_pParentMenu == NULL);

    // Determine if menu is popup in top-level menu and set m_pOther to
    // it if so (m_pParentMenu == NULL indicates that it is secondary popup).
    HMENU hParentMenu;
    if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
        state.m_pParentMenu = pPopupMenu;    // Parent == child for tracking popup.
    else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
    {
        CWnd* pParent = this;
           // Child windows don't have menus--need to go to the top!
        if (pParent != NULL &&
           (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
        {
           int nIndexMax = ::GetMenuItemCount(hParentMenu);
           for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
           {
            if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
            {
                // When popup is found, m_pParentMenu is containing menu.
                state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
                break;
            }
           }
        }
    }

    state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
    for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
      state.m_nIndex++)
    {
        state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
        if (state.m_nID == 0)
           continue; // Menu separator or invalid cmd - ignore it.

        ASSERT(state.m_pOther == NULL);
        ASSERT(state.m_pMenu != NULL);
        if (state.m_nID == (UINT)-1)
        {
           // Possibly a popup menu, route to first item of that popup.
           state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
           if (state.m_pSubMenu == NULL ||
            (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
            state.m_nID == (UINT)-1)
           {
            continue;       // First item of popup can't be routed to.
           }
           state.DoUpdate(this, TRUE);   // Popups are never auto disabled.
        }
        else
        {
           // Normal menu item.
           // Auto enable/disable if frame window has m_bAutoMenuEnable
           // set and command is _not_ a system command.
           state.m_pSubMenu = NULL;
           state.DoUpdate(this, FALSE);
        }

        // Adjust for menu deletions and additions.
        UINT nCount = pPopupMenu->GetMenuItemCount();
        if (nCount < state.m_nIndexMax)
        {
           state.m_nIndex -= (state.m_nIndexMax - nCount);
           while (state.m_nIndex < nCount &&
            pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
           {
            state.m_nIndex++;
           }
        }
        state.m_nIndexMax = nCount;
    }

	// TODO: Add your message handler code here
}

void CMyClockDlg::On32788()
{
	// TODO: Add your command handler code here
	if(m_BDBSTime)
	{
		m_BDBSTime=false;
	}

⌨️ 快捷键说明

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