Note that there are some explanatory texts on larger screens.

plurals
  1. POSimulating movement of a window and have it react to collisions
    primarykey
    data
    text
    <p>I was reading this <a href="https://stackoverflow.com/questions/932706/how-to-programmatically-move-a-window-slowly-as-if-the-user-were-doing-it">topic</a> and I decided to give it a shot. To my astonishment it really seemed easier than what I am making it I guess. I have some confusion about the "DesiredPos" variable. Well at least in my implementation. I am trying to move a window around constantly and have it react like a ball when it hits the monitors edges. Like the ball in the game Pong. I have made programs like this that move the mouse, But I can't seem to get my head around this one. </p> <p>This is what I have so far, I have limited experience when it comes to a lot of functions in the Windows API. Keep in mind this is a hardcore rough draft.</p> <p>EDIT I haven't implemented any of the collision detection yet I just wanted to get the moving portion working.</p> <pre><code>#include &lt;windows.h&gt; #include &lt;math.h&gt; 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,&amp;window); int elap = (GetTickCount() - startTime); if(elap &gt;= 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 ) } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload