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

📄 windowanima.cpp

📁 一个简单的demo
💻 CPP
📖 第 1 页 / 共 5 页
字号:

		// repaint original screen to avoid animation trail
		m_pdcScreen->BitBlt(wx+xs1-a,wy+ys1-b,czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs1-a,wy+ys1-b,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs2,wy+ys2-b, czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs2,wy+ys2-b,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs3+a,wy+ys3-b, czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs3+a,wy+ys3-b,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs4-a,wy+ys4+b, czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs4-a,wy+ys4+b,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs5,wy+ys5+b, czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs5,wy+ys5+b,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs6+a,wy+ys6+b, czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs6+a,wy+ys6+b,SRCCOPY);

		a+=nMove;
		b+=nMove;
	}
}

/************************************************************************************
	Six separate parts of a window fly from different directions to a central point
	where they join to make a full window.
************************************************************************************/
void CWindowAnima::ReAssemble6(int nDistance, int nMoveFactor, int nSleeptime)
{
	// Do any pre-animation initialisations
	Initialise();

	int nSteps=nDistance;
	int nMove=nMoveFactor;
	int a=nMove*nSteps;
	int b=a;
	int wx=m_rectWnd.left, wy=m_rectWnd.top;
	CPoint cptWindowCenter=m_rectWnd.CenterPoint();
	CSize czDiv(m_czWnd.cx/3, m_czWnd.cy/2);
	int xs1,ys1,xs2,ys2,xs3,ys3,xs4,ys4,xs5,ys5,xs6,ys6;
	xs1=0;
	ys1=0;
	xs2=czDiv.cx;
	ys2=0;
	xs3=czDiv.cx*2;
	ys3=0;
	xs4=0;
	ys4=czDiv.cy;
	xs5=czDiv.cx;
	ys5=czDiv.cy;
	xs6=czDiv.cx*2;
	ys6=czDiv.cy;

	for(int i=0;i<nSteps;i++){
		m_pdcScreen->BitBlt(wx+xs1-a,wy+ys1-b,czDiv.cx,czDiv.cy,m_pdcMemWnd,
			xs1,ys1,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs2,wy+ys2-b, czDiv.cx,czDiv.cy,m_pdcMemWnd,
			xs2,ys2,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs3+a,wy+ys3-b, czDiv.cx,czDiv.cy,m_pdcMemWnd,
			xs3,ys3,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs4-a,wy+ys4+b, czDiv.cx,czDiv.cy,m_pdcMemWnd,
			xs4,ys4,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs5,wy+ys5+b, czDiv.cx,czDiv.cy,m_pdcMemWnd,
			xs5,ys5,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs6+a,wy+ys6+b, czDiv.cx,czDiv.cy,m_pdcMemWnd,
			xs6,ys6,SRCCOPY);

		Sleep(nSleeptime);

		// repaint original screen to avoid animation trail
		m_pdcScreen->BitBlt(wx+xs1-a,wy+ys1-b,czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs1-a,wy+ys1-b,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs2,wy+ys2-b, czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs2,wy+ys2-b,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs3+a,wy+ys3-b, czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs3+a,wy+ys3-b,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs4-a,wy+ys4+b, czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs4-a,wy+ys4+b,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs5,wy+ys5+b, czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs5,wy+ys5+b,SRCCOPY);
		m_pdcScreen->BitBlt(wx+xs6+a,wy+ys6+b, czDiv.cx,czDiv.cy,m_pdcMemScr,
			wx+xs6+a,wy+ys6+b,SRCCOPY);

		a-=nMove;
		b-=nMove;
	}
	RestoreWindow(FALSE);
}

/************************************************************************************
	Checks that the Window pointer is not null and then captures a copy of
	the entire users screen area.
************************************************************************************/
void CWindowAnima::Initialise()
{
	ASSERT(m_pWnd!=NULL);

	// if task bar clipping is on then set the clipping region to
	// exclude drawing over the task bar else if task bar clipping WAS on
	// and and the flag is no longer set then turn task bar clipping off
	if(FlagIsSet(WA_KEEP_TASKBAR_ONTOP)){
		ToggleTaskBarOnTop(WA_TASKBAR_ON);
		m_TaskBarClippingOn=TRUE;
	} else if(m_TaskBarClippingOn) {
		ToggleTaskBarOnTop(WA_TASKBAR_OFF);
		m_TaskBarClippingOn=FALSE;
	}

	// Capture a copy of the screen within the clipping region
	CaptureScreenImage(m_pWnd);
}

/************************************************************************************
	Captures a copy of the users entire screen area and saves the data into the
	member variable m_pdcMemScr.  Also sets the dimensions of the screen in
	m_czScr.  Finally it hides the window from view, and copies the portion of the
	screen that was behind the window into the memory buffer.
************************************************************************************/
void CWindowAnima::CaptureScreenImage(CWnd *pWnd)
{
	if(m_nFlags & WA_SCR_SKIPCAPTURE)
		return;

	CBitmap bmWindow;

	ASSERT(m_pWnd!=NULL);

	// capture a copy of the screen area within our clipping region
	m_pdcMemScr->BitBlt(m_rectScr.left,m_rectScr.top,m_czScr.cx,m_czScr.cy,
		m_pdcScreen,m_rectScr.left,m_rectScr.top,SRCCOPY);

	// hide the window and capture the part of the screen that was
	// hidden behind it.  This reduces flicker if the window needs to be
	// visible again immediately after screen capture
	HideWindow();
	m_pdcMemScr->BitBlt(m_rectWnd.left,m_rectWnd.top,m_rectWnd.Width(),
		m_rectWnd.Height(),m_pdcScreen,m_rectWnd.left,m_rectWnd.top,SRCCOPY);
}

/************************************************************************************
	Captures a copy of the window image pointed to by pWnd unless the
	WA_WND_SKIPCAPTURE flag is set.  The window must be visible when 
	CaptureWindowImage() is called or the program will ASSERT in debug mode.
	When a window image is capture the size and position of the window are also
	recorded.
************************************************************************************/
void CWindowAnima::CaptureWindowImage(CWnd *pWnd)
{
	if(m_nFlags & WA_WND_SKIPCAPTURE)
		return;

	// make sure the window is visible
	ASSERT(pWnd->IsWindowVisible());

	// create a WindowDC object
	CWindowDC dcWindow(pWnd);

	// get window position & size data;
	pWnd->GetWindowRect(&m_rectWnd);

	CBitmap bmWindow;

	// copy size data to member variables
	m_czWnd.cx=m_rectWnd.Width();
	m_czWnd.cy=m_rectWnd.Height();

	// if there is already a window stored in our CWindowAnima object
	// the delete it.
	if(m_pdcMemWnd!=NULL){
		m_pdcMemWnd->SelectObject(m_pOldBitmapWnd);
		delete m_pdcMemWnd;
	}

	// create a new CDC memory object to store the image of the window
	m_pdcMemWnd=new CDC;

	// create a compbatible bitmap area to draw to
	bmWindow.CreateCompatibleBitmap(&dcWindow,m_czWnd.cx,m_czWnd.cy);

	m_pdcMemWnd->CreateCompatibleDC(&dcWindow);
	m_pOldBitmapWnd=m_pdcMemWnd->SelectObject(&bmWindow);

	// copy the image of the window into our dc memory buffer
	m_pdcMemWnd->BitBlt(0,0,m_czWnd.cx,m_czWnd.cy,&dcWindow,0,0,SRCCOPY);
}

/************************************************************************************
	Choose the direction in which to Melt a window.
************************************************************************************/
void CWindowAnima::Melt(int nDirection, int nSegments, 
						int nStagger, int nSleeptime)
{
	// Do any pre-animation initialisations
	Initialise();

	switch(nDirection){
	case WA_AUTO:
		nDirection=GetClosestSide();
		break;
	case WA_RAND:
		nDirection=GetRandomDirection(4);
		break;
	}

	switch(nDirection){
	case WA_LEFT:
		MeltLeft(nSegments, nStagger, nSleeptime);
		break;
	case WA_RIGHT:
		MeltRight(nSegments, nStagger, nSleeptime);
		break;
	case WA_UP:
		MeltUp(nSegments, nStagger, nSleeptime);
		break;
	case WA_DOWN:
		MeltDown(nSegments, nStagger, nSleeptime);
		break;
	}
}

/************************************************************************************
	Paints an image of the window onto the screen at the window's existing postion.
	When a window is processing an intensive loop, the interface sometimes remains
	blank, by printing a copy of the window to the screen instead of showing the
	actual window we avoid this.
************************************************************************************/
void CWindowAnima::PrintWindow()
{
	m_pdcScreen->BitBlt(m_rectWnd.left, m_rectWnd.top, 
		m_czWnd.cx, m_czWnd.cy, m_pdcMemWnd,0,0,SRCCOPY);
}

/************************************************************************************
	Restores the window and the proper background of the window to its existing
	location.  Internally RestoreWindow() is called with its parameter set to
	FALSE so that m_nFlags will be checked for the WA_KEEP_WINDOW_HIDDEN flag.
	Calling RestoreWindow() externally with no parameters causes the function
	to use the default value TRUE as its parameter and therefore ignore the value
	of the flags.  It is assumed that the only reason a user would call this function
	explicitly is to actually restore a window irrespective of what the flags are
	set to.
************************************************************************************/
void CWindowAnima::RestoreWindow(BOOL bIgnoreFlags)
{
	if(bIgnoreFlags || !(m_nFlags & WA_WND_SKIPRESTORE)){
		if(bIgnoreFlags || !(m_nFlags & WA_KEEP_BKGRND_HIDDEN))
			PrintImageBehindWindow();
		if(bIgnoreFlags || !(m_nFlags & WA_KEEP_WINDOW_HIDDEN))
			ShowWindow();
	}
}

/************************************************************************************
	Choose in which direction to Melt a window.
************************************************************************************/
void CWindowAnima::UnMelt(int nDirection, int nSegments,
						  int nStagger, int nSleeptime)
{
	// Do any pre-animation initialisations
	Initialise();

	switch(nDirection){
	case WA_AUTO:
		nDirection=GetClosestSide();
		break;
	case WA_RAND:
		nDirection=GetRandomDirection(4);
		break;
	}

	switch(nDirection){
	case WA_LEFT:
		UnMeltLeft(nSegments, nStagger, nSleeptime);
		break;
	case WA_RIGHT:
		UnMeltRight(nSegments, nStagger, nSleeptime);
		break;
	case WA_UP:
		UnMeltUp(nSegments, nStagger, nSleeptime);
		break;
	case WA_DOWN:
		UnMeltDown(nSegments, nStagger, nSleeptime);
		break;
	}

	RestoreWindow(FALSE);
}

/************************************************************************************
	Simply calls the CWnd function ShowWindow to hide the window from view.
************************************************************************************/
void CWindowAnima::HideWindow()
{
	// don't hide the window if the WA_SKIPHIDEONCAPTURE flag is set
	if(!(m_nFlags & WA_SKIPHIDEONCAPTURE)){
		m_pWnd->ShowWindow(SW_HIDE);

		// sleep for 10 milliseconds because we generally do a screen capture
		// after hiding the window.  Windows doesn't always hide the window as
		// quickly as we'd like so sometimes we get half the window remaining
		// splashed across the screen.  By sleeping we give Windows time to fully
		// hide the window and if you can't wait an extra 10 millisecs then window
		// animations are not for you anyway!!!!
		Sleep(10);
	}
}

/************************************************************************************
	Prints the correct background that a window should have when it has been
	restored subsequent to an animation.
************************************************************************************/
void CWindowAnima::PrintImageBehindWindow()
{
	m_pdcScreen->BitBlt(m_rectWnd.left, m_rectWnd.top, 
		m_czWnd.cx, m_czWnd.cy, m_pdcMemScr,m_rectWnd.left, m_rectWnd.top,
		SRCCOPY);
}

/************************************************************************************
	Creates a vertical blinds disappearing effect on the window
************************************************************************************/
void CWindowAnima::BlindVert(int nSegments, int nGapFactor, int nSleeptime)
{
	int wx=m_rectWnd.left, wy=m_rectWnd.top;
	int segWidth=m_czWnd.cx/nSegments;
	int istop=m_czWnd.cx;
	int stepcum=0;
	int nGapWidth=nGapFactor;

	PrintWindow();

	for(int gap=nGapWidth;stepcum<segWidth;gap+=nGapWidth){
		for(int i=0;i<=istop;i+=segWidth){
			m_pdcScreen->BitBlt(wx+i+stepcum,wy, gap,m_czWnd.cy,
				m_pdcMemScr, wx+i+stepcum, wy, SRCCOPY);
		}
		stepcum+=gap;
		Sleep(nSleeptime);
	}
}

/************************************************************************************
	Creates a vertical blinds appearing effect on the window
************************************************************************************/
void CWindowAnima::UnBlindVert(int nSegments, int nGapFactor, int nSleeptime)
{
	// Do any pre-animation initialisations
	Initialise();

	int wx=m_rectWnd.left, wy=m_rectWnd.top;
	int segWidth=m_czWnd.cx/nSegments;
	int istop=m_czWnd.cx;
	int stepcum=0;
	int nGapWidth=nGapFactor;

	for(int gap=nGapWidth;stepcum<segWidth;gap+=nGapWidth){
		for(int i=0;i<=istop;i+=segWidth){
			m_pdcScreen->BitBlt(wx+i+stepcum,wy, gap,m_czWnd.cy,
				m_pdcMemWnd, i+stepcum, 0, SRCCOPY);
		}
		stepcum+=gap;
		Sleep(nSleeptime);
	}
}

/************************************************************************************
	Melts the window segment by segment towards the left of the screen
************************************************************************************/
void CWindowAnima::MeltLeft(int nSegments, int nDrop, int nSleeptime)
{
	int wx=m_rectWnd.left, wy=m_rectWnd.top;
	int cumulator=0, cumulator2=0;
	int step=nDrop;

	// calculates how many iterations we'll need to get the whole window
	// off screen
	int nVisibleLimit=(m_rectWnd.right/step)+3;

	// calculate the width of each segment based on the number of segments given
	int segWidth=m_czWnd.cy/nSegments;

	if(m_czWnd.cy%nSegments!=0)
		nSegments++;

	// draw a copy of the window onto the screen
	PrintWindow();

	// while the window is still visible
	for(int a=0;a<nVisibleLimit;a++){
		// foreach segment
		for(int seg=0;seg<nSegments;seg++){
			if(a>0)
				seg=nSegments;
			int nSegOffset=0;
			int nStepHeight=0;

⌨️ 快捷键说明

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