This example moves a rectangle in response to the movement of the mouse (WM_MOUSEMOVE); the rectangle is moved (offset) based on the distance moved by the mouse since its previous position.

#define INCL_WINRECTANGLES      /* Window Rectangle Functions   */
#include <os2.h>

int main(void)
{
BOOL  fSuccess;         /* success indicator                    */
HAB     hab;            /* anchor-block handle                  */
RECTL prclRect1 = {0,0,100,100}; /* rectangle                   */
LONG   lcx;             /* Horizontal expansion                 */
LONG   lcy;             /* Vertical expansion                   */
POINTL ptlPrev;         /* previous mouse position              */
POINTL ptlCurr;         /* current mouse position               */
MPARAM mp1;             /* Parameter 1  (x,y) point value       */

case WM_MOUSEMOVE:
     ptlCurr.x = (LONG) SHORT1FROMMP(mp1);
     ptlCurr.y = (LONG) SHORT2FROMMP(mp1);

     /* calculate distance from previous mouse position */
     lcx =   (LONG)(ptlPrev.x - ptlCurr.x);
     lcy =   (LONG)(ptlPrev.y - ptlCurr.y);

     fSuccess = WinOffsetRect(hab, &prclRect1, lcx, lcy);


[Back] [Next]