NewScrdefDlg.cpp
资源名称:NewScrdef.rar [点击查看]
上传用户:sunbbj
上传日期:2013-03-21
资源大小:111k
文件大小:9k
源码类别:
屏幕保护
开发平台:
Visual C++
- // NewScrdefDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "NewScrdef.h"
- #include "NewScrdefDlg.h"
- #include "PassDlg.h"
- #include <math.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CNewScrdefDlg dialog
- CNewScrdefDlg::CNewScrdefDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CNewScrdefDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CNewScrdefDlg)
- // 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);
- m_pMemDC = NULL;
- m_pMemBitmap = NULL;
- m_pPen = NULL;
- m_nGirlPosX = 0;
- m_bAgument = TRUE;
- m_pFont = NULL;
- }
- void CNewScrdefDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CNewScrdefDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CNewScrdefDlg, CDialog)
- //{{AFX_MSG_MAP(CNewScrdefDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_TIMER()
- ON_WM_DESTROY()
- ON_WM_LBUTTONDOWN()
- ON_WM_KEYDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CNewScrdefDlg message handlers
- BOOL CNewScrdefDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // 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
- Init();
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CNewScrdefDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 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 CNewScrdefDlg::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 CNewScrdefDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CNewScrdefDlg::Init()
- {
- m_pDC = GetDC();
- m_pMemDC = new CDC();
- m_pMemDCLittleGirl = new CDC();
- m_pMemBitmap = new CBitmap();
- m_pMemDC->CreateCompatibleDC(m_pDC);
- m_pMemBitmap->CreateCompatibleBitmap(m_pDC, 1024, 768);
- m_pMemDC->SelectObject(m_pMemBitmap);
- m_pMemDC->SelectObject(&CBrush(RGB(128,0,128)));
- m_pMemDCLittleGirl->CreateCompatibleDC(m_pDC);
- m_bitmapLittleGirl.LoadBitmap(IDB_BITMAP_LITTLEGIRL);
- m_pMemDCLittleGirl->SelectObject(&m_bitmapLittleGirl);
- BITMAP bt;
- m_bitmapLittleGirl.GetBitmap(&bt);
- m_szBitmapLittleGirl.cx = bt.bmWidth;
- m_szBitmapLittleGirl.cy = bt.bmHeight;
- // m_pPen = new CPen(PS_SOLID, 3, RGB(255, 84 , 219));
- // m_pMemDC->SelectObject(m_pPen);
- this->SetTimer(1, 10, NULL);
- ShowWindow(3);
- ::ShowCursor(SW_HIDE);
- CString strMyPath;
- strMyPath = "D:\Scrdef\my.txt";
- if (m_stFile.Open(strMyPath, CFile::modeRead))
- {
- m_bStFileCanRead = TRUE;
- CreateFont();
- m_pMemDC->SelectObject(m_pFont);
- m_pMemDC->SetTextColor(RGB(255,0,255));
- m_pMemDC->SetBkMode(TRANSPARENT);
- }
- else
- {
- m_bStFileCanRead = FALSE;
- }
- }
- void CNewScrdefDlg::OnTimer(UINT nIDEvent)
- {
- Render();
- }
- void CNewScrdefDlg::OnDestroy()
- {
- if (m_pMemBitmap != NULL)
- {
- delete m_pMemBitmap;
- }
- if (m_pMemDC != NULL)
- {
- delete m_pMemDC;
- }
- if (m_pPen != NULL)
- {
- delete m_pPen;
- }
- if (m_pMemDCLittleGirl != NULL)
- {
- delete m_pMemDCLittleGirl;
- }
- if (m_pFont != NULL)
- {
- delete m_pFont;
- }
- ::DeleteObject(m_bitmapLittleGirl);
- ReleaseDC(m_pDC);
- CDialog::OnDestroy();
- }
- void CNewScrdefDlg::Render()
- {
- // m_pMemDC->SelectObject(&CBrush(RGB(0,0,0)));
- m_pMemDC->Rectangle(0,0,1024,768);
- DrawWant();
- m_pDC->StretchBlt(0,0,
- 1024,768,
- m_pMemDC,
- 0,0,1024,768,SRCCOPY);
- }
- void CNewScrdefDlg::DrawWant()
- {
- m_pMemDC->Rectangle(0,0,1024,768);
- m_pMemDC->SelectStockObject(BLACK_BRUSH);
- //公共变量
- static int af = 0;
- float r;
- static int ct;
- float a;
- int x,y;
- int x0,y0;
- static POINT ptLast;
- ptLast.x = 512;
- ptLast.y = 384;
- a = 0.5;
- x0 = 512;
- y0 = 384;
- //
- //正炫
- #if 0
- // int y;
- // int x0 = 512;
- // int y0 = 384;
- // static int ct = 0;
- for (int i=0; i<1024; i++)
- {
- y = y0 + 40*sin(cos((i + 0 )*PI/180));
- x = i + x0;
- m_pMemDC->SetPixel(x,y, RGB(i,i+y,y));
- }
- #endif
- #if 1 //圆渐开线
- for (ct=0; ct<1080; ct++)
- {
- r = ct * a;
- x = x0 + int(r * cos((ct+af) * PI / 180.0));
- y = y0 + int(r * sin((ct+af) * PI / 180.0));
- m_pMemDC->SetPixel(x,y,RGB(x,y,x+y));
- }
- for (ct=0; ct<360; ct++)
- {
- r = 100*cos((3*ct) * PI / 180.0);
- m_ptArray[ct].x = x0 + int(r * cos((ct+af) * PI / 180.0));
- m_ptArray[ct].y = y0 + int(r * sin((ct+af) * PI / 180.0));
- }
- CRgn rgnRose;
- rgnRose.CreatePolygonRgn(m_ptArray, 360, WINDING);
- m_pMemDC->FillRgn(&rgnRose, &CBrush(RGB(255,0,255)));
- #endif
- af += 5;
- #if 0
- //球
- int z = 0;
- int R = 100;
- for (ct=0; ct<360; ct++)
- {
- for (z=0; z<5; z++)
- {
- x = x0 + R * cos(ct * PI /180.0) - z* sin(45 * PI / 180.0);
- y = y0 + R * sin(ct * PI /180.0) + z* sin(45 * PI / 180.0);
- m_pMemDC->SetPixel(x,y, RGB(255,0,255));
- }
- }
- //球
- #endif
- if (m_bAgument)
- {
- m_nGirlPosX += 2;
- if (m_nGirlPosX >= 1024 - m_szBitmapLittleGirl.cx)
- {
- m_bAgument = FALSE;
- }
- }
- else
- {
- m_nGirlPosX -= 2;
- if (m_nGirlPosX <= 0)
- {
- m_bAgument = TRUE;
- }
- }
- ::TransparentBlt(m_pMemDC->m_hDC,
- m_nGirlPosX,
- 0,
- m_szBitmapLittleGirl.cx,
- m_szBitmapLittleGirl.cy,
- m_pMemDCLittleGirl->m_hDC,
- 0,
- 0,
- m_szBitmapLittleGirl.cx,
- m_szBitmapLittleGirl.cy,
- RGB(0,255,255));
- #if 0
- TRACE("Info(%d,%d,%d,%d n",m_ptArray[ct-1].x,
- m_ptArray[ct-1].y,
- m_szBitmapLittleGirl.cx,
- m_szBitmapLittleGirl.cy);
- #endif
- if (m_bStFileCanRead)
- {
- if (af % 500 == 0)
- {
- if (!m_stFile.ReadString(m_strRead))
- {
- m_stFile.SeekToBegin();
- }
- }
- //if (m_stFile.E
- m_pMemDC->TextOut(100,600,m_strRead);
- }
- }
- void CNewScrdefDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- #if 0
- return;
- CPassDlg dlgPass;
- int n = dlgPass.DoModal();
- if (dlgPass.DoModal() == IDOK)
- {
- if (dlgPass.m_strPassword == "Hello")
- {
- CDialog::OnOK();
- }
- else
- {
- ((CStatic*)(dlgPass.GetDlgItem(IDC_STATIC_PASSWORD)))->SetWindowText(_T("密码错误,请再重新输入"));
- return;
- }
- }
- #endif
- CDialog::OnOK();
- }
- void CNewScrdefDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- CDialog::OnOK();
- }
- void CNewScrdefDlg::CreateFont()
- {
- LOGFONT logfont;
- logfont.lfCharSet = 134;
- logfont.lfClipPrecision = 0;
- logfont.lfEscapement = 0;
- //logfont.lfFaceName = "";
- logfont.lfHeight = -56;
- logfont.lfItalic = 0;
- logfont.lfOrientation = 0;
- logfont.lfOutPrecision = 0;
- logfont.lfPitchAndFamily = 0;
- logfont.lfQuality = 0;
- logfont.lfStrikeOut = 0;
- logfont.lfUnderline = 0;
- logfont.lfWeight = 700;
- logfont.lfWidth = 0;
- m_pFont = new CFont();
- m_pFont->CreateFontIndirect(&logfont);
- }