Jump to content

WinSubtractRect

From EDM2
Revision as of 03:18, 9 April 2025 by Martini (talk | contribs) (Related Functions)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function subtracts one rectangle from another.

Syntax

WinSubtractRect(hab, prclDest, prclSrc1, prclSrc2)

Parameters

hab (HAB) - Input
Anchor-block handle.
prclDest (PRECTL) - Output
Result.
The result of the subtraction of prclSrc2 from prclSrc1.
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.
prclSrc1 (PRECTL) - Input
First source rectangle.
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.
prclSrc2 (PRECTL) - Input
Second source rectangle.
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
Not-empty indicator.
TRUE
Rectangle is not empty
FALSE
Rectangle is empty or an error occurred.

Remarks

Subtracts prclSrc2 from prclSrc1.

prclSrc1, prclSrc2, and prclDest must be distinct RECTL structures. Subtracting one rectangle from another does not always result in a rectangular area. When this occurs, this function returns prclSrc1 in prclDest. For this reason, this function provides only an approximation of subtraction. However, the area described by prclDest is always greater than, or equal to, the true result of the subtraction.

GpiCombineRegion can be used to calculate the true result of the subtraction of two rectangular areas. The WinSubtractRect function is much faster.

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  prclDest;  /*  Result. */
PRECTL  prclSrc1;  /*  First source rectangle. */
PRECTL  prclSrc2;  /*  Second source rectangle. */
BOOL    rc;        /*  Not-empty indicator. */

rc = WinSubtractRect(hab, prclDest, prclSrc1, prclSrc2);

This example uses the WinSubtractRect call to subtract two rectangles.

#define INCL_WINRECTANGLES
#include <OS2.H>
HAB hab;
RECTL resultrcl;   /* result */
RECTL rclminuend={25,  /* x coordinate of left-hand edge of */
                       /* rectangle */
                  25,  /* y coordinate of bottom edge of    */
                       /* rectangle */
                  425, /* x coordinate of right-hand edge of */
                       /* rectangle */
                  425};/* y coordinate of top edge of rectangle */

RECTL rclsubtrahend={15,  /* x coordinate of left-hand edge of */
                          /* rectangle */
                  15,  /* y coordinate of bottom edge of    */
                       /* rectangle */
                  125, /* x coordinate of right-hand edge of */
                       /* rectangle */
                  125};/* y coordinate of top edge of rectangle */

WinSubtractRect(hab,
                &resultrcl,
                &rclminuend,
                &rclsubtrahend);

Related Functions