WinOffsetRect
Appearance
This function offsets a rectangle.
Syntax
WinOffsetRect(hab, prcl, cx, cy)
Parameters
- hab (HAB) - Input
- Anchor-block handle.
- prcl (PRECTL) - In/Out
- Rectangle to be offset.
- Note
- The value of each field in this structure must be in the range -32 768 through 32 767. The data type WRECT may also be used, if supported by the language.
Returns
- rc (BOOL) - returns
- Success indicator.
- TRUE
- Successful completion
- FALSE
- Error occurred.
Remarks
This function offsets the coordinates of prcl by adding the value of the cx parameter to both the left and right coordinates, and the value of the cy to both the top and bottom coordinates.
Errors
Possible returns from WinGetLastError: (No specific errors were listed in the provided text.)
Example Code
#define INCL_WINRECTANGLES /* Or use INCL_WIN, INCL_PM, */ #include <os2.h> HAB hab; /* Anchor-block handle. */ PRECTL prcl; /* Rectangle to be offset. */ LONG cx; /* x-value of offset. */ LONG cy; /* y-value of offset. */ BOOL rc; /* Success indicator. */ rc = WinOffsetRect(hab, prcl, cx, cy);
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);