AnimateDialog

BlackDice 0 Tallied Votes 154 Views Share

this is a wrapper around the AnimateWindow API. this allows random animations in a dialog. I just call it in the dialog's OnInitDialog() handler. The 'fade' effect has not been implemented because I didn't like the idea of having to call RedrawWindow or something like that because sometimes the borders aren't drawn right for controls when you use that flag.

void AnimateDialog(HWND hWnd)
{
	DWORD		dwTemp2,dwTemp,dwAnimate = AW_ACTIVATE;
	int			nFirst,nSecond;
	
	//seed randomNumber Generator
	srand( (unsigned)time( NULL ) );
	nFirst = rand() % 3 + 1;
		
	switch(nFirst)
	{
	case 1:
		dwTemp = AW_SLIDE;
		break;
	case 2:
		//removed because it was AW_BLEND which doesn't seem to repaint controls correctly
	case 3:
		dwTemp = AW_CENTER;
		break;
	}
	
	dwAnimate |= dwTemp;

	//these next values will only work with AW_SLIDE
	if(nFirst == 1)
	{
		srand( (unsigned)time( NULL ) );
		nSecond = rand() % 4 + 1;
		
		switch(nSecond)
		{
			case 1:
				dwTemp2 = AW_HOR_POSITIVE ;
				break;
			case 2:
				dwTemp2 = AW_HOR_NEGATIVE;
				break;
			case 3:
				dwTemp2 = AW_VER_POSITIVE;
				break;
			default:
				dwTemp2 = AW_VER_NEGATIVE;
		}
		dwAnimate |= dwTemp2;

		srand( (unsigned)time( NULL ) );
		nSecond = rand() % 2;
		
		if(dwTemp2 == AW_VER_POSITIVE || dwTemp2 == AW_VER_NEGATIVE)
		{
			dwTemp2 = 0;
			switch(nSecond)
			{
				case 1: dwTemp2 = AW_HOR_POSITIVE; break;
				case 2: dwTemp2 = AW_HOR_NEGATIVE; break;
			}
			dwAnimate |= dwTemp2;
		}//if(dwTemp2 == AW_VER_POSITIVE || dwTemp2 == AW_VER_NEGATIVE)
		else
		{
			dwTemp2 = 0;
			switch(nSecond)
			{
				case 1: dwTemp2 = AW_VER_POSITIVE; break;
				case 2: dwTemp2 = AW_VER_NEGATIVE; break;
			}
			dwAnimate |= dwTemp2;
		}

			
			
	}//if(nFirst == 1)

	::AnimateWindow(hWnd,200,dwAnimate);
}
Satil 0 Newbie Poster

preety good

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.