MYWND.CPP
上传用户:trhysrzt
上传日期:2022-03-19
资源大小:9454k
文件大小:17k
- // MyWnd.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ScreenSafe.h"
- #include "MyWnd.h"
- #include "Mmsystem.h"
- #include "math.h"
- // CMyWnd
- IMPLEMENT_DYNAMIC(CMyWnd, CWnd)
- CMyWnd::CMyWnd()
- {
- m_prePoint=CPoint(0,0);
- }
- LPCSTR CMyWnd::lpszClassName=NULL;
- CMyWnd::~CMyWnd()
- {
- }
- BEGIN_MESSAGE_MAP(CMyWnd, CWnd)
- ON_WM_CREATE()
- ON_WM_TIMER()
- ON_WM_PAINT()
- ON_WM_KEYDOWN()
- ON_WM_SYSCOMMAND()
- ON_WM_DESTROY()
- ON_WM_LBUTTONDOWN()
- ON_WM_MOVE()
- END_MESSAGE_MAP()
- // CMyWnd message handlers
- bool CMyWnd::Create()
- {
-
- // TODO: Add your specialized creation code here
- if(lpszClassName==NULL)
- {
- //注册类,IDC_NOCURSOR为新建的光标ID,这个光标没有任何图案
- lpszClassName=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,::LoadCursor(AfxGetResourceHandle(),
- MAKEINTRESOURCE(IDC_NOCURSOR)));
- }
- CRect rect(0,0,::GetSystemMetrics(SM_CXSCREEN),
- ::GetSystemMetrics(SM_CYSCREEN));
- //创建一个全屏的窗口
- CreateEx(WS_EX_TOPMOST,lpszClassName,_T(""),WS_VISIBLE|WS_POPUP,
- rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,
- GetSafeHwnd(),NULL,NULL);
- SetTimer(0,5000,NULL);//计时器
- return true;
-
- }
- void CMyWnd::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- CClientDC dc(this);
- static nIndexBit=0;
- if(nIndexBit>=3)
- nIndexBit=0;
- DrawBitmap(dc,nIndexBit++);
- CWnd::OnTimer(nIDEvent);
- }
- void CMyWnd::DrawBitmap(CDC& dc, int nIndexBit)
- {
- CRect rect;
- GetClientRect(rect);
- //绘制图形
- CBitmap m_Bitmap;
- m_Bitmap.LoadBitmap(IDB_BITMAP1+nIndexBit);
- int rnd=rand();
- int i=rnd%7;
- switch(i)
- {
- case 0:
- MasicWindow(&dc,&m_Bitmap,rect.left,rect.top,rect.Width(),rect.Height());
- break;
- case 1:
- MoveDown(&dc,&m_Bitmap,rect.left,rect.top,rect.Width(),rect.Height());
- break;
- case 2:
- MoveUp(&dc,&m_Bitmap,rect.left,rect.top,rect.Width(),rect.Height());
- break;
- case 3:
- BlindWindow(&dc,&m_Bitmap,rect.left,rect.top,rect.Width(),rect.Height());
- break;
- case 4:
- ScanRight(&dc,&m_Bitmap,rect.left,rect.top,rect.Width(),rect.Height());
- break;
- case 5:
- ScanDown(&dc,&m_Bitmap,rect.left,rect.top,rect.Width(),rect.Height());
- break;
- case 6:
- StripWindow(&dc,&m_Bitmap,rect.left,rect.top,rect.Width(),rect.Height());
- break;
- }
- }
- void CMyWnd::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- // TODO: Add your message handler code here
- CBrush brush(RGB(0,0,0));
- CRect rect1;
- GetClientRect(rect1);
- dc.FillRect(&rect1,&brush);
- OnTimer(0);
- }
- void CMyWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- PostMessage(WM_CLOSE);
- CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CMyWnd::OnSysCommand(UINT nID, LPARAM lParam)
- {
- // TODO: Add your message handler code here and/or call default
- CWnd::OnSysCommand(nID, lParam);
- }
- BOOL CMyWnd::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Add your specialized code here and/or call the base class
- return CWnd::PreCreateWindow(cs);
- }
- void CMyWnd::OnDestroy()
- {
- CWnd::OnDestroy();
- // TODO: Add your message handler code here
- }
- ///////////////////////////////////////////////
- //特效,向下逐行显示
- //nLeft, nTop //显示区域的左上角坐标
- //nWidth, nHeight //显示区域的宽、高
- //bmph,bmpw //位图的高、宽
- //nStart //显示区域上所处理块开始位置
- //nEnd //显示区域上所处理块结束位置
- //nBlock //所处理块的大小
- ///////////////////////////////////////////////
- void CMyWnd::ScanDown(CDC* pDC, CBitmap* pBmp, int nLeft, int nTop, int nWidth, int nHeight)
- {
- CBrush brush(RGB(0,0,0));
- CBrush* oldBrush=pDC->SelectObject(&brush);
- CPen pen(PS_SOLID,1,RGB(0,0,0));
- CPen* oldPen=pDC->SelectObject(&pen);
- pDC->Rectangle(0,0,nWidth,nHeight);
- //起始行的上下高度
- int nStart=0;
- int nEnd=25;
- BITMAP bmpinfo;
- CDC MemDC;
- CBitmap *oldBmp;
- MemDC.CreateCompatibleDC(pDC);
- oldBmp=MemDC.SelectObject(pBmp);
- pBmp->GetBitmap(&bmpinfo);
- int bmpw=bmpinfo.bmWidth;//位图的高、宽
- int bmph=bmpinfo.bmHeight;
- int nBlock=25; //所处理块的大小
- int ddbEnd,ddbBlock,ddbStart;
- //下移
- for(nEnd=nBlock;nEnd<nHeight+nBlock;nEnd=nEnd+nBlock)
- {
- ddbEnd=int(nEnd*bmph/nHeight); //位图上所处理块结束位置
- ddbBlock=int(nBlock*bmph/nHeight);//位图上所处理块的大小
- ddbStart=int(nStart*bmph/nHeight);//位图上所处理块开始位置
-
- pDC->StretchBlt(nLeft,nStart,
- nWidth,nBlock,
- &MemDC,
- 0,ddbStart,
- bmpw,ddbBlock,
- SRCCOPY);
- nStart=nEnd;
- WaitTime(100);
- }
- WaitTime(3000);
- oldBrush=pDC->SelectObject(&brush);
- oldPen=pDC->SelectObject(&pen);
- pDC->SelectObject(oldBrush);
- pDC->SelectObject(oldPen);
- }
- ///////////////////////////////////////////////
- //特效,向右逐行显示
- //nLeft, nTop //显示区域的左上角坐标
- //nWidth, nHeight //显示区域的宽、高
- //bmph,bmpw //位图的高、宽
- //nStart //显示区域上所处理块开始位置
- //nEnd //显示区域上所处理块结束位置
- //nBlock //所处理块的大小
- ///////////////////////////////////////////////
- void CMyWnd::ScanRight(CDC* pDC, CBitmap* pBmp, int nLeft, int nTop, int nWidth, int nHeight)
- {
- CBrush brush(RGB(0,0,0));
- CBrush* oldBrush=pDC->SelectObject(&brush);
- CPen pen(PS_SOLID,1,RGB(0,0,0));
- CPen* oldPen=pDC->SelectObject(&pen);
- pDC->Rectangle(0,0,nWidth,nHeight);
- //起始行的上下高度
- int nStart=0;
- int nEnd=25;
- BITMAP bmpinfo;
- CDC MemDC;
- CBitmap *oldBmp;
- MemDC.CreateCompatibleDC(pDC);
- oldBmp=MemDC.SelectObject(pBmp);
- pBmp->GetBitmap(&bmpinfo);
- int bmpw=bmpinfo.bmWidth;//位图的高、宽
- int bmph=bmpinfo.bmHeight;
- int nBlock=25; //所处理块的大小
- int ddbEnd,ddbBlock,ddbStart;
- //下移
- for(nEnd=nBlock;nEnd<nWidth+nBlock;nEnd=nEnd+nBlock)
- {
- ddbEnd=int(nEnd*bmpw/nWidth);//位图上所处理块结束位置
- ddbBlock=int(nBlock*bmpw/nWidth);//位图上所处理块的大小
- ddbStart=int(nStart*bmpw/nWidth);//位图上所处理块开始位置
- pDC->StretchBlt(nStart,nTop,
- nBlock,nHeight,
- &MemDC,
- ddbStart,0,
- ddbBlock,bmph,
- SRCCOPY);
- nStart=nEnd;
- WaitTime(100);
- }
- WaitTime(1000);
- oldBrush=pDC->SelectObject(&brush);
- oldPen=pDC->SelectObject(&pen);
- pDC->SelectObject(oldBrush);
- pDC->SelectObject(oldPen);
- }
- ///////////////////////////////////////////////
- //MoveDown 特效,向下移动显示
- //nLeft, nTop //显示区域的左上角坐标
- //nWidth, nHeight //显示区域的宽、高
- //bmph,bmpw //位图的高、宽
- //nStart //显示区域上所处理块开始位置
- //nEnd //显示区域上所处理块结束位置
- //nBlock //所处理块的大小
- ///////////////////////////////////////////////
- void CMyWnd::MoveDown(CDC* pDC, CBitmap* pBmp, int nLeft, int nTop, int nWidth, int nHeight)
- {
- CBrush brush(RGB(0,0,0));
- CBrush* oldBrush=pDC->SelectObject(&brush);
- CPen pen(PS_SOLID,1,RGB(0,0,0));
- CPen* oldPen=pDC->SelectObject(&pen);
- pDC->Rectangle(0,0,nWidth,nHeight);
- //起始行的上下高度
- int nStart=0;
- int nEnd=25;
- BITMAP bmpinfo;
- CDC MemDC;
- CBitmap *oldBmp;
- MemDC.CreateCompatibleDC(pDC);
- oldBmp=MemDC.SelectObject(pBmp);
- pBmp->GetBitmap(&bmpinfo);
- int bmpw=bmpinfo.bmWidth;//位图的高、宽
- int bmph=bmpinfo.bmHeight;
- int nBlock=25; //所处理块的大小
- //下移
- for(int i=0;i<nHeight+nBlock;i=i+nBlock)
- {
- int ddbi=int(i*bmph/nHeight);
- pDC->StretchBlt(nLeft,nTop,
- nWidth,i,
- &MemDC,
- 0,bmph-ddbi,
- bmpw,ddbi,
- SRCCOPY);
- WaitTime(100);
- }
- WaitTime(1000);
- //清除
- for(int j=0;j<=nHeight;j++)
- {
- pDC->Rectangle(0,j,nWidth,0);
- }
- pDC->SelectObject(oldBrush);
- pDC->SelectObject(oldPen);
- }
- ///////////////////////////////////////////////
- //MoveUp 特效,向上移动显示
- //nLeft, nTop //显示区域的左上角坐标
- //nWidth, nHeight //显示区域的宽、高
- //bmph,bmpw //位图的高、宽
- //nStart //显示区域上所处理块开始位置
- //nEnd //显示区域上所处理块结束位置
- //nBlock //所处理块的大小
- ///////////////////////////////////////////////
- void CMyWnd::MoveUp(CDC* pDC, CBitmap* pBmp, int nLeft, int nTop, int nWidth, int nHeight)
- {
- CBrush brush(RGB(0,0,0));
- CBrush* oldBrush=pDC->SelectObject(&brush);
- CPen pen(PS_SOLID,1,RGB(0,0,0));
- CPen* oldPen=pDC->SelectObject(&pen);
- pDC->Rectangle(0,0,nWidth,nHeight);
- //起始行的上下高度
- int nStart=0;
- int nEnd=25;
- BITMAP bmpinfo;
- CDC MemDC;
- CBitmap *oldBmp;
- MemDC.CreateCompatibleDC(pDC);
- oldBmp=MemDC.SelectObject(pBmp);
- pBmp->GetBitmap(&bmpinfo);
- int bmpw=bmpinfo.bmWidth;//位图的高、宽
- int bmph=bmpinfo.bmHeight;
- int nBlock=25; //所处理块的大小
- for(int i=0;i<nHeight+nBlock;i=i+nBlock)
- {
- int ddbi=int(i*bmph/nHeight);
- pDC->StretchBlt(nLeft,nHeight-i,
- nWidth,i,
- &MemDC,
- 0,0,
- bmpw,ddbi,
- SRCCOPY);
- WaitTime(100);
- }
- WaitTime(1000);
- //清除
- for(int j=0;j<=nHeight;j++)
- {
- pDC->Rectangle(0,nHeight-j,nWidth,nHeight);
- }
- pDC->SelectObject(oldBrush);
- pDC->SelectObject(oldPen);
- }
- ///////////////////////////////////////////////
- //BlindWindow 特效,百叶窗显示
- //nLeft, nTop //显示区域的左上角坐标
- //nWidth, nHeight //显示区域的宽、高
- //bmph,bmpw //位图的高、宽
- //nStart //显示区域上所处理块开始位置
- //nEnd //显示区域上所处理块结束位置
- //nBlock //所处理块的大小
- //nScanLine //条纹数
- ///////////////////////////////////////////////
- void CMyWnd::BlindWindow(CDC* pDC, CBitmap* pBmp, int nLeft, int nTop, int nWidth, int nHeight)
- {
- CBrush brush(RGB(0,0,0));
- CBrush* oldBrush=pDC->SelectObject(&brush);
- CPen pen(PS_SOLID,1,RGB(0,0,0));
- CPen* oldPen=pDC->SelectObject(&pen);
- pDC->Rectangle(0,0,nWidth,nHeight);
- //起始行的上下高度
- int nStart=0;
- int nEnd=25;
- BITMAP bmpinfo;
- CDC MemDC;
- CBitmap *oldBmp;
- MemDC.CreateCompatibleDC(pDC);
- oldBmp=MemDC.SelectObject(pBmp);
- pBmp->GetBitmap(&bmpinfo);
- int bmpw=bmpinfo.bmWidth;//位图的高、宽
- int bmph=bmpinfo.bmHeight;
- int nBlock=25; //所处理块的大小
- int nScanLine=20;
- int temp,temp1;
- if(bmpw>nWidth)
- {
- if(fmod(bmpw,nWidth)!=0)
- temp=int(bmpw/nWidth)+1;
- else
- temp=int(bmpw/nWidth);
- temp1=1;
- }
- else
- {
- if(fmod(nWidth,bmpw)!=0)
- temp1=int(nWidth/bmpw)+1;
- else
- temp1=int(nWidth/bmpw);
- temp=1;
- }
- for(int i=0;i<nScanLine;++i)
- {
- for(int j=i;j<nWidth;j=j+nScanLine)
- {
- pDC->StretchBlt(j,0,
- temp1,nHeight,
- &MemDC,
- j*bmpw/nWidth,0,
- temp,bmph,
- SRCCOPY);
- }
- WaitTime(100);
- }
- WaitTime(1000);
- for(int i=0;i<nScanLine;++i)
- {
- for(int j=i;j<nWidth;j=j+nScanLine)
- {
- pDC->Rectangle(j,0,j+1,nHeight);
- }
- WaitTime(100);
- }
- pDC->SelectObject(oldBrush);
- pDC->SelectObject(oldPen);
- }
- ///////////////////////////////////////////////
- //StripWindow 特效,栅条显示
- //nLeft, nTop //显示区域的左上角坐标
- //nWidth, nHeight //显示区域的宽、高
- //bmph,bmpw //位图的高、宽
- //nStart //显示区域上所处理块开始位置
- //nEnd //显示区域上所处理块结束位置
- //nBlock //所处理块的大小
- //nScanLine //条纹数
- ///////////////////////////////////////////////
- void CMyWnd::StripWindow(CDC* pDC, CBitmap* pBmp, int nLeft, int nTop, int nWidth, int nHeight)
- {
- CBrush brush(RGB(0,0,0));
- CBrush* oldBrush=pDC->SelectObject(&brush);
- CPen pen(PS_SOLID,1,RGB(0,0,0));
- CPen* oldPen=pDC->SelectObject(&pen);
- pDC->Rectangle(0,0,nWidth,nHeight);
- //起始行的上下高度
- int nStart=0;
- int nEnd=25;
- BITMAP bmpinfo;
- CDC MemDC;
- CBitmap *oldBmp;
- MemDC.CreateCompatibleDC(pDC);
- oldBmp=MemDC.SelectObject(pBmp);
- pBmp->GetBitmap(&bmpinfo);
- int bmpw=bmpinfo.bmWidth;//位图的高、宽
- int bmph=bmpinfo.bmHeight;
- int nBlock=25; //所处理块的大小
- int nScanLine=20;
- double wScale=(double)bmpw/(double)nWidth;
- double hScale=(double)bmph/(double)nHeight;
- for(int i=0;i<nHeight+1;i=i+10)
- {
- for(int j=0;j<nWidth;j=j+2*nScanLine)
- {
- pDC->StretchBlt(j,0,
- nScanLine,i+1,
- &MemDC,
- (int)(j*wScale),0,
- (int)(nScanLine*wScale),(int)(hScale*(i+1)),
- SRCCOPY);
- int k=j+nScanLine;
- pDC->StretchBlt(k,nHeight-i,
- nScanLine,i,
- &MemDC,
- (int)(k*wScale),(int)((nHeight-i)*hScale),
- (int)(nScanLine*wScale),(int)(i*hScale),
- SRCCOPY);
- }
- }
- WaitTime(1000);
- for(int i=0;i<nHeight+1;i=i+10)
- {
- for(int j=0;j<nWidth;j=j+2*nScanLine)
- {
- pDC->StretchBlt(j,i,
- nScanLine,nHeight-i,
- &MemDC,
- (int)(j*wScale),(int)(i*hScale),
- (int)(nScanLine*wScale),(int)(hScale*(nHeight-i)),
- SRCCOPY);
- pDC->Rectangle(j,i-1,j+nScanLine,i-11);
- int k=j+nScanLine;
- pDC->StretchBlt(k,0,nScanLine,nHeight-i,
- &MemDC,
- (int)(k*wScale),0,
- (int)(nScanLine*wScale),
- (int)((nHeight-i)*hScale),
- SRCCOPY);
- pDC->Rectangle(k,nHeight-i,k+nScanLine,nHeight-i+10);
-
- }
- }
- pDC->SelectObject(oldBrush);
- pDC->SelectObject(oldPen);
- }
- ///////////////////////////////////////////////
- //MasicWindow 特效,马赛克显示
- //nLeft, nTop //显示区域的左上角坐标
- //nWidth, nHeight //显示区域的宽、高
- //bmph,bmpw //位图的高、宽
- //nStart //显示区域上所处理块开始位置
- //nEnd //显示区域上所处理块结束位置
- //nBlock //所处理块的大小
- //nScanLine //条纹数
- ///////////////////////////////////////////////
- void CMyWnd::MasicWindow(CDC* pDC, CBitmap* pBmp, int nLeft, int nTop, int nWidth, int nHeight)
- {
- CBrush brush(RGB(0,0,0));
- CBrush* oldBrush=pDC->SelectObject(&brush);
- CPen pen(PS_SOLID,1,RGB(0,0,0));
- CPen* oldPen=pDC->SelectObject(&pen);
- pDC->Rectangle(0,0,nWidth,nHeight);
- //起始行的上下高度
- int nStart=0;
- int nEnd=25;
- BITMAP bmpinfo;
- CDC MemDC;
- CBitmap *oldBmp;
- MemDC.CreateCompatibleDC(pDC);
- oldBmp=MemDC.SelectObject(pBmp);
- pBmp->GetBitmap(&bmpinfo);
- int bmpw=bmpinfo.bmWidth;//位图的高、宽
- int bmph=bmpinfo.bmHeight; //源位图的尺寸
- int nBlock=25; //所处理块的大小
- int nScanLine=20;
- int nDividedSize=75;
- int nWidthAppend=0;
- int nHeightAppend=0;
- //如果不能整除,横纵方块的数量要加1
- if((nWidth%nDividedSize)!=0)
- nWidthAppend=1;
- if((nHeight%nDividedSize)!=0)
- nHeightAppend=1;
- //划分的方块数量
- long lDividedNum=(nWidth/nDividedSize+nWidthAppend)*(nHeight/nDividedSize+nHeightAppend);
- //申请数组,存储方块的坐标
- POINT *point=new POINT[lDividedNum];
- //为数组赋值的临时变量
- long mx=0;
- long my=0;
- double wScale=(double)bmpw/(double)nWidth;//
- double hScale=(double)bmph/(double)nHeight;//
- //为数组赋值
- for(long mi=0;mi<lDividedNum;mi++)
- {
- point[mi].x=mx;
- point[mi].y=my;
- mx=mx+nDividedSize;
- if(mx>nWidth)
- {
- mx=0;
- my=my+nDividedSize;
- }
- }
- //RAND_MAX是系统定义的最大随机数,是0x7fff,即32767
- double fmax=RAND_MAX;
- for(mi=lDividedNum-1;mi>=0;mi--)
- {
- //产生随机数
- int randNum=rand();
- //计算要随机显示的方块
- int n=(int)((double)randNum*(double)lDividedNum/fmax);
- //得到此方块的位置
- mx=point[n].x;
- my=point[n].y;
- //随机显示方块
- pDC->StretchBlt(mx, my,
- nDividedSize, nDividedSize,
- &MemDC,
- (int)(mx*wScale),
- (int)((my+nDividedSize)*hScale),
- (int)(nDividedSize*wScale),
- (int)(nDividedSize*hScale),
- SRCCOPY);
- WaitTime(100);
- //将显示过的方块设置标志,以补充绘制
- point[n].x=-1;
- point[n].y=-1;
- }
- //补充绘制上面没有绘制到的方块
- for(mi=lDividedNum-1;mi>=0;mi--)
- {
- if(point[mi].x!=-1&&point[mi].y!=-1)
- {
- mx=point[mi].x;
- my=point[mi].y;
- pDC->StretchBlt(mx, my,
- nDividedSize, nDividedSize,
- &MemDC,
- (int)(mx*wScale),
- (int)((my+nDividedSize)*hScale),
- (int)(nDividedSize*wScale),
- (int)(nDividedSize*hScale),
- SRCCOPY);
- }
- }
- delete []point;
- WaitTime(1000);
- //清除
- POINT *erasePoint=new POINT[lDividedNum];
- mx=0;
- my=0;
- for(mi=0;mi<lDividedNum;mi++)
- {
- erasePoint[mi].x=mx;
- erasePoint[mi].y=my;
- mx=mx+nDividedSize;
- if(mx>nWidth)
- {
- mx=0;
- my=my+nDividedSize;
- }
- }
- //利用随机数清除
- for(mi=lDividedNum-1;mi>=0;mi--)
- {
- int randNum=rand();
- int n=(int)((double)randNum*(double)lDividedNum/fmax);
- mx=erasePoint[n].x;
- my=erasePoint[n].y;
- pDC->Rectangle(mx,my,mx+nDividedSize,my+nDividedSize);
- WaitTime(1);
- erasePoint[n].x=-1;//设置标志
- erasePoint[n].y=-1;
- }
- for(mi=lDividedNum-1;mi>=0;mi--)//补充绘制
- {
- if(erasePoint[mi].x!=-1&&erasePoint[mi].y!=-1)
- {
- mx=erasePoint[mi].x;
- my=erasePoint[mi].y;
- pDC->Rectangle(mx,my,mx+nDividedSize,my+nDividedSize);
- }
- }
- delete []erasePoint;
- }
- void CMyWnd::WaitTime(int nDelay)
- {//延时一定的时间
- int nBegin,nEnd;
- nBegin=timeGetTime();
- do
- {
- nEnd=timeGetTime();
- }while(nEnd-nBegin<nDelay);
- }
- void CMyWnd::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- PostMessage(WM_CLOSE);
- CWnd::OnLButtonDown(nFlags, point);
- }
- void CMyWnd::OnMove(int x, int y)
- {
- CWnd::OnMove(x, y);
- PostMessage(WM_CLOSE);
- // TODO: Add your message handler code here
- }