Moving window along a cosine path
-
Hi all, Upon the start of my windows application I would like the splash screen window to move along the path of a cosine curve. More precisely I would like it to work like this: My splash window is positioned at the lower right corner of the screen. Now image a cosine graph under the interval of 0 <= degrees <= 180. I want the upper left corner of the splash screen to initially correspond to the coordinate of [180, cosine(180)]. Then, at some intervals I want the window to move to the "left" along the cosine curve all the way up to the top left corner of the screen, making a horizontally flipped S-shaped path (almost a flash-logo-like path). Since screens vary in sizes I need to know how to transpose a cosine curve to "fit" all screens. Any help would be greatly appreciated!!!!! /Tommy
-
Hi all, Upon the start of my windows application I would like the splash screen window to move along the path of a cosine curve. More precisely I would like it to work like this: My splash window is positioned at the lower right corner of the screen. Now image a cosine graph under the interval of 0 <= degrees <= 180. I want the upper left corner of the splash screen to initially correspond to the coordinate of [180, cosine(180)]. Then, at some intervals I want the window to move to the "left" along the cosine curve all the way up to the top left corner of the screen, making a horizontally flipped S-shaped path (almost a flash-logo-like path). Since screens vary in sizes I need to know how to transpose a cosine curve to "fit" all screens. Any help would be greatly appreciated!!!!! /Tommy
I don't know what language you're using, but I've always used ::GetSystemMetrics(SM_CXSCREEN) to get the screen width and similar calls to get other screen dimensions. For your problem, since cos(180)=-1 and cos(0)=1, you will want to find the center of the screen to pivot from, but to do this you will need to subtract off the height of the splash screen and any borders. The following worked in a dialog based app:
void CTestSplashDlg::SetPosition(double dDegrees) { const double pi = 3.1415926535; double dRadians = (2 * dDegrees * pi)/360; double dCos = cos(dRadians); CRect rect; GetClientRect(&rect); long nNewWidth = (long)(::GetSystemMetrics(SM_CXSCREEN) - rect.Width() - ::GetSystemMetrics(SM_CXDLGFRAME)) * (dDegrees/180); // Since cos(0) = 1 and cos(180) = -1, must have center of screen as cos(90) = 0 long nHeightCenter = (long)(::GetSystemMetrics(SM_CYSCREEN) - rect.Height() - ::GetSystemMetrics(SM_CYDLGFRAME) - ::GetSystemMetrics(SM_CYCAPTION))/2; long nNewHeight = (long)(nHeightCenter - (dCos * (nHeightCenter))); SetWindowPos(NULL, nNewWidth, nNewHeight, 0, 0, SWP_NOZORDER | SWP_NOSIZE); }
when called with:for (double i = 180; i >= 0; i--) { SetPosition(i); Sleep(10); }
Note that you would probably call this from a timer instead of a for loop and the starting position does not take into account the taskbar that may be at the bottom of the screen.