上传用户:jinxin
上传日期:2022-06-07
资源大小:2203k
文件大小:4k
- // 屏幕保护程序2Dlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "屏幕保护程序2.h"
- #include "屏幕保护程序2Dlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMy2Dlg dialog
- CMy2Dlg::CMy2Dlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMy2Dlg::IDD, pParent)
- {srand((unsigned)time(NULL));
- //{{AFX_DATA_INIT(CMy2Dlg)
- // 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 CMy2Dlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMy2Dlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMy2Dlg, CDialog)
- //{{AFX_MSG_MAP(CMy2Dlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_DESTROY()
- ON_WM_TIMER()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_KEYDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMy2Dlg message handlers
- BOOL CMy2Dlg::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
- SetWindowPos(&wndTopMost,0,0,
- ::GetSystemMetrics(SM_CXSCREEN),
- ::GetSystemMetrics(SM_CYSCREEN),
- SWP_SHOWWINDOW);
- SetTimer(1,250,NULL);
-
- 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 CMy2Dlg::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 CMy2Dlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CMy2Dlg::OnDestroy()
- {
- CDialog::OnDestroy();
-
- // TODO: Add your message handler code here
- KillTimer(1);
- }
- void CMy2Dlg::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- CClientDC dc(this);
- CRect rect;
- GetClientRect(&rect);
- CPen mypen;
- mypen.CreatePen(PS_SOLID,1,RGB(rand()%255,rand()%255,rand()%255));
- CBrush mybrush;
- mybrush.CreateSolidBrush(RGB(rand()%255,rand()%255,rand()%255));
- dc.SelectObject(&mypen);
- dc.SelectObject(&mybrush);
- dc.MoveTo(rect.right/2,0);
- for(int a=0;a<100;a++){
- dc.LineTo(rect.right-a,rect.bottom/2);
- dc.LineTo(rect.right/2,rect.bottom-a);
- dc.LineTo(a,rect.bottom/2);
- dc.LineTo(rect.right/2-a,0);}
- // CBrush mybrush;
- // mybrush.CreateSolidBrush(RGB(rand()%255,rand()%255,rand()%255));
- dc.Rectangle(rand()%rect.right,rand()%rect.right,rand()%rect.bottom,rand()%rect.bottom);
- dc.Ellipse(rand()%rect.right,rand()%rect.right,rand()%rect.bottom,rand()%rect.bottom);
-
- dc.SelectStockObject(BLACK_PEN);
- CDialog::OnTimer(nIDEvent);
- }
- void CMy2Dlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDialog::EndDialog(IDOK);
- CDialog::OnLButtonDown(nFlags, point);
- }
- void CMy2Dlg::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDialog::EndDialog(IDOK);
- CDialog::OnLButtonDblClk(nFlags, point);
- }
- void CMy2Dlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- CDialog::EndDialog(IDOK);
- CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
- }