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

📄 promptdlg.cpp

📁 实现MFC不规则对话框
💻 CPP
字号:
// PromptDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Clock.h"
#include "PromptDlg.h"
//#include "ClockApp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPromptDlg dialog


CPromptDlg::CPromptDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPromptDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPromptDlg)
	m_Prompt = _T("");
	m_Time = _T("");
	//}}AFX_DATA_INIT
}


void CPromptDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPromptDlg)
	DDX_Text(pDX, IDC_PROMPT, m_Prompt);
	DDX_Text(pDX, IDC_TIME, m_Time);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPromptDlg, CDialog)
	//{{AFX_MSG_MAP(CPromptDlg)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_PAINT()
	ON_WM_TIMER()
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPromptDlg message handlers
BOOL CPromptDlg::OnInitDialog()
{
	CClockApp* cApp = (CClockApp*)AfxGetApp();
	CDialog::OnInitDialog();
	SetWindowPos(&wndTopMost,0,0,0,0,SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
	int   cx=GetSystemMetrics(SM_CXSCREEN);  
	int   cy=GetSystemMetrics(SM_CYSCREEN);
	m_cx = cx;
	m_cy = cy;
	//m_scale = cy/cx;
	CRect   rectWindow;  
	GetWindowRect(&rectWindow);  
	int   w=rectWindow.Width();  
	int   h=rectWindow.Height(); 
	m_CenterPoint = rectWindow.CenterPoint();
	rectWindow.left=cx-w/2;  
	rectWindow.top=cy-h/2;  
	rectWindow.right=cx+w/2;  
	rectWindow.bottom=cy+h/2;  
	MoveWindow(rectWindow,TRUE);

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CRgn wndRgn,rgtemp;
	wndRgn.CreateEllipticRgn(0,0,240,155);
	SetWindowRgn((HRGN)wndRgn,true);
	CTime time = CTime::GetCurrentTime();
	m_Time = time.Format("%Y-%m-%d %H:%M:%S");
	CStatic* m_pTime = (CStatic*)GetDlgItem(IDC_TIME);
	m_pTime->SetWindowText(m_Time);
	CStatic* m_pPrompt = (CStatic*)GetDlgItem(IDC_PROMPT);
	m_pPrompt->SetWindowText("  "+cApp->m_pConfig->GetPrompt());
	m_Subject = cApp->m_pConfig->GetSubject();
	
	return TRUE;
}
void CPromptDlg::OnPaint()
{
	CClockApp* cApp = (CClockApp*)AfxGetApp();
	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;
		GetWindowRect(&rect);
		CDC memDC;
		CBitmap cBitmap;
		CBitmap* pOldMemBmp=NULL;
		switch(cApp->m_Subject)
		{
		case 0:
			cBitmap.LoadBitmap(IDB_BACKGROUND);
			break;
		case 1:
			cBitmap.LoadBitmap(IDB_CARTOON);
			break;
		case 2:
			cBitmap.LoadBitmap(IDB_FICTION);
			break;
		case 3:
			cBitmap.LoadBitmap(IDB_ROMANTIC);
			break;
		case 4:
			cBitmap.LoadBitmap(IDB_SEA);
			break;
		
		}
		memDC.CreateCompatibleDC(&dc);
		pOldMemBmp=memDC.SelectObject(&cBitmap);
		dc.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
		if(pOldMemBmp)
			memDC.SelectObject(pOldMemBmp);
		CDialog::OnPaint();
		SetTimer(1,200,NULL);
		SetTimer(2,1000*20,NULL);
	}
}

void CPromptDlg::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnLButtonDblClk(nFlags, point);
	CDialog::OnCancel();
}
void CPromptDlg::OnTimer(UINT_PTR nIDEvent)
{
    switch (nIDEvent)
    {
    case 1:        
		{
			CRect   rectWindow;  
			GetWindowRect(&rectWindow);  
			//int   w=rectWindow.Width();  
			//int   h=rectWindow.Height();
			int left = rectWindow.left;
			int top = rectWindow.top;
			int right = rectWindow.right;
			int bottom = rectWindow.bottom;
			//CPoint center = rectWindow.CenterPoint();
			if(right > m_cx || bottom > m_cy)
			{
				rectWindow.left=left - 3;  
				rectWindow.top=top - 2;  
				rectWindow.right= right -3;  
				rectWindow.bottom=bottom -2;  
				MoveWindow(rectWindow,TRUE);
			}
			else
				KillTimer(1);  // 删除此计时器,否则计时器中断完后会自动重新开始计时,到下一次中断时还会发生新的中断
			break;
		}
	case 2:
		{
			CDialog::OnCancel();
			KillTimer(2);
			break;
		}
    }
}

HBRUSH CPromptDlg::OnCtlColor(CDC* pDC,CWnd* pWnd,UINT nCtlColor)  
{  
	HBRUSH hbr = CDialog::OnCtlColor(pDC,pWnd,nCtlColor);  
	if(nCtlColor == CTLCOLOR_STATIC)  
	{  
		pDC->SetTextColor(RGB(255,0,0));//设置成你背景的颜色  
		pDC->SetBkColor(RGB(255,255,255));  
		//pDC->SetBkMode(TRANSPARENT); //透明  

		return   (HBRUSH)::GetStockObject(NULL_BRUSH);  
	}  
	//   TODO:     如果默认的不是所需画笔,则返回另一个画笔  
	return   hbr;  
}

⌨️ 快捷键说明

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