Skip to content

Consider Changing CombineRgn Return Type to Enum #1024

Closed

Description

@lonitra

Is your feature request related to a problem? Please describe.
The current return type of CombineRgn is an int, which affects code readability since getting a 0 as a return may not immediately signify to the reader that there was an error, and no region was created. To work around this, users could create their own enum type, but even then they would still need to cast their enum type everywhere they want to check the return of CombineRgn.

Describe the solution you'd like
Have CombineRgn return an enum type for readability and cleanliness. Perhaps something like:

internal enum RegionType : int
    {
        ERROR = 0,
        NULLREGION = 1,
        SIMPLEREGION = 2,
        COMPLEXREGION = 3,
    }

This enum type could also be used for the return type of other methods such as GetClipBox, GetRgnBox, IntersectClipRect etc.

Activity

  1. added
    enhancement
    on Aug 2, 2022
  2. AArnott commented on Aug 3, 2022

    @AArnott
    Member

    Your enum looks good. The 3 non-zero values are already defined as constants in the metadata and could be relocated to the enum. The value for ERROR should be defined natively in the enum rather than relocating it (if it's in the metadata) since it obviously isn't named specifically for the region APIs and probably is used elsewhere.

  3. added
    missing enum
    and removed
    enhancement
    on Aug 3, 2022
  4. mikebattista commented on Aug 3, 2022

    @mikebattista
    Contributor

    Windows.Win32.Graphics.Gdi.GDI_REGION_TYPE not found in 1st winmd
    Windows.Win32.Graphics.Gdi.Apis.ERROR...System.UInt32 => System.Int32
    Windows.Win32.Graphics.Gdi.Apis.NULLREGION not found in 2nd winmd
    Windows.Win32.Graphics.Gdi.Apis.SIMPLEREGION not found in 2nd winmd
    Windows.Win32.Graphics.Gdi.Apis.COMPLEXREGION not found in 2nd winmd
    Windows.Win32.Graphics.Gdi.Apis.RGN_ERROR not found in 2nd winmd
    Windows.Win32.Graphics.Gdi.Apis.CombineRgn : return...Int32 => GDI_REGION_TYPE
    Windows.Win32.Graphics.Gdi.Apis.ExcludeClipRect : return...Int32 => GDI_REGION_TYPE
    Windows.Win32.Graphics.Gdi.Apis.GetClipBox : return...Int32 => GDI_REGION_TYPE
    Windows.Win32.Graphics.Gdi.Apis.GetRgnBox : return...Int32 => GDI_REGION_TYPE
    Windows.Win32.Graphics.Gdi.Apis.IntersectClipRect : return...Int32 => GDI_REGION_TYPE
    Windows.Win32.Graphics.Gdi.Apis.OffsetClipRgn : return...Int32 => GDI_REGION_TYPE
    Windows.Win32.Graphics.Gdi.Apis.OffsetRgn : return...Int32 => GDI_REGION_TYPE
    Windows.Win32.Graphics.Gdi.Apis.SelectClipRgn : return...Int32 => GDI_REGION_TYPE
    Windows.Win32.Graphics.Gdi.Apis.ExtSelectClipRgn : return...Int32 => GDI_REGION_TYPE
    Windows.Win32.Graphics.Gdi.Apis.SetMetaRgn : return...Int32 => GDI_REGION_TYPE

  5. mikebattista commented on Aug 3, 2022

    @mikebattista
    Contributor

    I left ERROR separate for now and added RGN_ERROR to the enum which was an existing alias for ERROR.

  6. mikebattista commented on Aug 3, 2022

    @mikebattista
    Contributor

    I'm planning to ship a metadata update later this week so if there are other issues affecting WinForms, let me know.

  7. added a commit that references this issue on Mar 28, 2026
    081709d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementmissing enum

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions