?? supersaverdlg.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 + -