# User32Addition

{% hint style="info" %}
Module

**Windows only! Some features are available for macOS too in** [**AppKitAddition**](https://xojo.gitbook.io/add-ons/cstruecolors/documentation/appkitaddition)**.**
{% endhint %}

## Overview

### Methods

| Overview                                                                                   |                                                                                                                                                                                                            |
| ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [BringToFront](#bringtofront-expands-w-as-window)                                          | [IdealHeight](#idealheight-expands-p-as-pushbutton-as-integer)                                                                                                                                             |
| [IdealWidth](#idealwidth-expands-p-as-pushbutton-as-integer)                               | [Image](#image-extends-s-as-pushbutton-radiobutton-scaling-as-nsimagescaling-nsimagescaling-none-position-as-nscellimageposition-nscellimageposition-imageleft-assigns-pic-as-picture-mac-win)             |
| [Images](#images-extends-parent-as-menuitem-s-as-menuitem-assigns-pics-as-picture-mac-win) | [MakeComposited](#makecomposited-extends-w-as-window-rectcontrol)                                                                                                                                          |
| [MakeLayered](#makelayered-extends-w-as-window-rectcontrol-redraw-as-boolean-true)         | [MakeTransparent](#maketransparent-extends-w-as-rectcontrol-window-transparencycolor-as-color-and-cffffffff-alpha-as-byte-0)                                                                               |
| [SizeToFit](#sizetofit-extends-p-as-pushbutton-radiobutton)                                | [Template](#template-extends-s-as-pushbutton-scaling-as-nsimagescaling-nsimagescaling-proportionallyupordown-position-as-nscellimageposition-nscellimageposition-imageleft-assigns-pic-as-picture-mac-win) |

## Documentation

### Methods

#### BringToFront (expands w As Window) `[mac + win]`

Brings the window to the front of the z oder.&#x20;

#### IdealHeight(expands p As PushButton) As Integer

Returns the ideal height of a pushbutton, or -1 if it cannot be calculated.

#### IdealWidth(expands p As PushButton) As Integer

Returns the ideal width of a pushbutton, or -1 if it cannot be calculated.

#### Image(extends s As PushButton / RadioButton, scaling As NSImageScaling = NSImageScaling.None, position As NSCellImageposition = NSCellImageposition.imageleft, assigns pic As Picture) `[mac + win]`

Sets the image that appears on the button when it’s in an off state, or nil if there is no such image.

{% hint style="danger" %}
This currently crashes the project under Windows silently when an image or template is assigned second time to a button – because of getting its handle, not because of the declare.
{% endhint %}

{% hint style="info" %}
Scaling and Position are ignored on Windows.
{% endhint %}

#### Images(extends parent As Menuitem, s As Menuitem, assigns pics() As Picture) `[mac + win]`

Sets the offstate and onstate images for a menuitem. \
Example: If you have a menuitem mi with a child miChild and want to set off- and onstateimage for miChild:\
`mi.Images(miChild) = Array(onStateImage, offStateImage)`

#### MakeComposited(extends w as Window / RectControl)

Makes the window or control a composited (buffered) window to avoid flicker in a non-transparent environment.

{% hint style="warning" %}
You should make a window either compositied or layered, not both.
{% endhint %}

#### MakeLayered(extends w as Window / RectControl, Redraw As Boolean = True)

Makes a window a layered window, redrawing it optionally. Use Layered Windows to avoid flicker in situations where transparencies are rendered.

#### MakeTransparent(extends w As RectControl / Window, TransparencyColor as Color = \&cffffffff, Alpha As Byte = 0)

Makes a rectcontrol or a window transparent by turning every appearance of transparencyColor into transparency with an alpha value between 0 (fully) and 255 (opaque). Sets the window to PopupStyle to allow a fully transparent window without title bar. Makes the Window or control layered too.

{% hint style="info" %}
Works for windows on macOS too. Use [Alpha](https://xojo.gitbook.io/add-ons/cstruecolors/appkitaddition#alpha-extends-w-as-window-rectcontrol-assigns-value-as-integer-as-integer) for controls under macOS.
{% endhint %}

#### SizeToFit(extends p as Pushbutton / RadioButton)

Resizes a button to the optimum space to show all content if possible.

#### Template(extends s As PushButton, scaling As NSImageScaling = NSImageScaling.ProportionallyUpOrDown, position As NSCellImageposition = NSCellImageposition.imageleft, assigns pic As Picture) `[mac + win]`

Identical to [*Image*](https://xojo.gitbook.io/add-ons/cstruecolors/appkitaddition#image-extends-s-as-segmentedcontrol-index-as-integer-scaling-as-nsimagescaling-nsimagescaling-proportionallyupordown-assigns-pic-as-picture), only that here the template representation of the image is being used.

{% hint style="danger" %}
This currently crashes the project under Windows silently when an image or template is assigned second time to a button – because of getting its handle, not because of the declare.
{% endhint %}
