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

📄 supersaverdlg.cpp

📁 Vc书上的一个屏保程序
💻 CPP
字号:
// SuperSaverDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SuperSaver.h"
#include "SuperSaverDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSuperSaverDlg dialog

CSuperSaverDlg::CSuperSaverDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSuperSaverDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSuperSaverDlg)
		// 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);
}

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

BEGIN_MESSAGE_MAP(CSuperSaverDlg, CDialog)
	//{{AFX_MSG_MAP(CSuperSaverDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_KEYDOWN()
	ON_WM_LBUTTONDOWN()
	ON_WM_RBUTTONDOWN()
	ON_WM_TIMER()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSuperSaverDlg message handlers

BOOL CSuperSaverDlg::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
	////////////////////////////////////
	//Add Code
	//------------------------------------
	SetWindowPos(&wndTopMost,0,0,::GetSystemMetrics(SM_CXSCREEN),::GetSystemMetrics(SM_CYSCREEN),SWP_SHOWWINDOW);
     //设置窗口大小

	SetTimer(1,250,NULL);
	//建立时钟
	m_boxes=0;
    //初始化变量
    //----------------------------------------
	//End Add Code
	////////////////////////////////////////
	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 CSuperSaverDlg::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 CSuperSaverDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSuperSaverDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	////////////////////////////////////////////
	//Add Code
	//----------------------------------------
	CDialog::EndDialog(IDOK);
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CSuperSaverDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    //设置关闭屏保的程序代码
	CDialog::EndDialog(IDOK);
	CDialog::OnLButtonDown(nFlags, point);
}

void CSuperSaverDlg::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	//设置关闭屏保的程序代码
	CDialog::EndDialog(IDOK);
	CDialog::OnRButtonDown(nFlags, point);
}

void CSuperSaverDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
		/////////////////////////////////////////
	//Add Code
	//----------------------------------------

	CClientDC dc(this);
    //获得设备环境

	CRect rect;//创建坐标类
	GetClientRect(&rect);
	//获得客户区坐标

    dc.SetROP2(R2_XORPEN);//绘图模式
   CPen randomPen;//创建画笔
   randomPen.CreatePen(PS_SOLID,1,RGB(rand()%255,
	                                  rand()%255,
									  rand()%255));
	//获得画笔属性
	
	dc.SelectObject(&randomPen);
    //载入设备环境
	for(int row=rect.bottom-m_boxes;row>m_boxes;row--)
	{
		dc.MoveTo(m_boxes,row);
		dc.LineTo(rect.right-m_boxes,rect.bottom-row);
	}

	for(int col=m_boxes;col<rect.right-m_boxes;col++)
	{
		dc.MoveTo(col,m_boxes);
		dc.LineTo(rect.right-col,rect.bottom-m_boxes);
	}
   
	m_boxes++;
	m_boxes %=5;
    //实现的相关算法
	dc.SelectStockObject(BLACK_PEN);
	//载入默认画笔
	//-------------------------------------
	//End Add Code
	/////////////////////////////////////////
   
	CDialog::OnTimer(nIDEvent);
}

void CSuperSaverDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	KillTimer(1);
	//删除定时器
}

⌨️ 快捷键说明

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