【发布时间】:2009-06-01 07:13:37
【问题描述】:
我正在阅读此topic 并决定试一试。令我惊讶的是,它似乎真的比我想的要容易。我对“DesiredPos”变量有些困惑。至少在我的实现中。我试图不断移动一个窗口,让它在碰到显示器边缘时像球一样反应。就像乒乓球比赛中的球一样。我已经制作了这样的程序来移动鼠标,但我似乎无法理解这个。
这是我目前所拥有的,对于 Windows API 中的许多功能,我的经验有限。请记住,这是一个核心草稿。
编辑 我还没有实现任何碰撞检测,但我只是想让移动部分工作。
#include <windows.h>
#include <math.h>
int newX(int oldx);
int newY(int oldy);
double SmoothMoveELX(double x);
int main()
{
int lengthInMs = 10*1000;
HWND notepad = FindWindow("Notepad",NULL);
RECT window;
SetTimer(
notepad,
NULL,
30,
(TIMERPROC)NULL
);
int startTime = GetTickCount();
int pos = elap / lengthInMs;
while(1)
{
RECT window;
GetWindowRect(notepad,&window);
int elap = (GetTickCount() - startTime);
if(elap >= lengthInMs)
{
int NEWX = NewX(window.x);
int NEWY = NewY(window.y);
MoveWindow(
notepad,
NEWX,
NEWY,
100,
100,
TRUE
);
}
}
}
int NewX(int oldx)
{
int newx = oldx*(1-SmoothMoveELX(pos))
+ 10 *SmoothMoveELX(pos));
return newx;
}
int newY(int oldy)
{
int newy = oldy*(1-SmoothMoveELX(pos))
+ 10 *SmoothMoveELX(pos));
return newy;
}
double SmoothMoveELX(double x)
{
double PI = Atan(1) * 4;
return ((cos(1 - x) * PI + 1) /2 )
}
【问题讨论】:
-
那么你的问题是什么?