0

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);
}
2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by Satil
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.