Contains winapi like functions for Delphi compatibility.

This unit was created for Delphi compatibility. It contains selected functions from the Delphi Windows unit, which finally are implemented in the widgetsets.

For LCL users:
The functions can be used to make porting of Delphi applications easier, and are not 100% emulating winapi functions, not even under windows. They were implemented and tested with some common Delphi libraries. The LCL contains many extra functions that the Delphi VCL does not have.

Some functions are not exactly Delphi or WinAPI compatible.

For example:
Instead of using the common windows functions SaveDC and RestoreDC use the Canvas.SaveHandleState and Canvas.RestoreHandleState.

Draws an elliptical curve.

Use Arc to draw an elliptically curved line with the current Pen.

The angles Angle16Deg and Angle16DegLength are measure in 1/16th of a degree. For example, a full circle equals 5760 (16*360). Positive values of Angle16Deg and Angle16DegLength mean counter-clockwise rotation while negative values mean a clockwise direction, from the point of view of who looks at the screen.

Zero degrees is at the 3'o clock position (right).

The starting angle in 1/16 degrees, starting right and continuing counter-clockwise.
The length of the arc. A positive value indicates that it goes counter-clockwise from the start angle and a negative value that it goes clockwise
Draws a filled Chord described by two angles.

AngleChord is a Lazarus addition, similar to the Windows API Chord, but uses angles to control the location of the chord inside the ellipse instead of two points like the Windows API Chord.

A Chord is a section of an ellipse between two angles (angle1 and angle2), closed by a straight line (secant). It's equivalent to a Pie without the triangle between the arc and the center of the ellipse.

The curve part of the chord is defined by the ellipse which fits in the bounding rectangle specified by the coordinates x1, y1, x2 and y2.

The Chord is outlined by the current Pen and filled with the current Brush.

LCLIntf.Pie Graphics.TCanvas.Chord Graphics.TCanvas.Pie
False on failure.
The starting angle in 1/16 degrees, starting right and continuing counter-clockwise.
The ending angle in 1/16 degrees, starting right and continuing counter-clockwise.
Start painting in a window.

This function is for use in WM_PAINT handlers only. Not all platforms allow for painting outside WM_PAINT messages.

BeginPaint prepares the specified window for painting and fills a PAINTSTRUCT structure with information about the painting.

?

A Device Context for the window, Nil on failure.
The window Handle.
Will receive painting information.
Copies a section of a Canvas to another one, performing a raster operation (ROP).

This routine implements the equivalent Windows GDI API of the same name in all platforms supported by Lazarus. It copies a section of a Canvas to another one, without any stretching. It allows to select the kind of operation which should be performed to draw the pixels into the destination in the parameter ROP. Allowed operations go from simply copying the pixels without change to inverting them and also to executing logical operations involving the source pixels and the previously existing pixels in the destination Canvas.

For normal usage one should only use SRCOPY in the ROP parameter, other operations may not be supported by all widgetsets.

There exist 16 raster operations, according to the possible combinations of two (boolean) values. Excluding the NOP case, that doesn't modify the target area, the possible values for ROP are:

- BLACKNESS - Fills the destination rectangle with black
- DSTINVERT - Inverts the colors of the destination area
- MERGECOPY - Fills the destination area with (Src and Pattern)
- MERGEPAINT - Fills the destination area with (Dst or not Src)
- NOTSRCCOPY - Fills the destination area with (not Src)
- NOTSRCERASE - Fills the destination area with (not (Dst or Src))
- PATCOPY - Fills the destination area with (Pattern)
- PATINVERT - Fills the destination area with (Dst xor Pattern)
- PATPAINT - Fills the destination area with (Dst or (not Src) or Pattern)
- SRCAND - Fills the destination area with (Dst and Src)
- SRCCOPY - Fills the destination area with Src
- SRCERASE - Fills the destination area with ((not Dst) and Src)
- SRCINVERT - Fills the destination area with (Dst xor Src)
- SRCPAINT - Combines the colors of the source and the destination using the operator OR on each pixel
- WHITENESS - Fills the destination rectangle with white

These flags can be added to above ROPs:

- CAPTUREBLT - Includes windows which are on top of the specified Canvas. This option is not recommended and is very hard to implement in all supported platforms.
- NOMIRRORBITMAP - Prevents the bitmap from being mirrored. (The coordinates are sorted before painting?)

False on failure.
The destination Device Context.
The origin in the destination DC.
The origin in the destination DC.
The image size.
The image size.
The source Device Context.
The origin in the source DC.
The origin in the source DC.
The raster operation.
Calls the next procedure in the hook chain.
Depends on the Hook type.
Handle of the current hook.
The Hook code (message ID).
Message parameter.
Message parameter.
Calls another Window procedure, to handle a message.
Converts (relative) Client coordinates into absolute Screen coordinates.
False on failure.
The window with the client area.
The point to convert.
Combines two regions.

    The following parameters are present in this function:
    Dest - The Handle of a region which will receive the result of the operation
    Src1 - One of the two regions to combine
    Src2 - The other region to combinee
    fnCombineMode - The method to use to combine the regions.
    As for the parameter fnCombineMode, the following constants from the unit LCLType can be used:
    RGN_AND	- The result is the intersection of the two combined regions.
    RGN_COPY - The result is a copy of the region Src1
    RGN_DIFF - Combines the parts of Src1 that are not part of Src2.
    RGN_OR - The result is the union of the two regions.
    RGN_XOR - The result is the union of two combined regions except for any overlapping areas.

The Handle of the destination region. This region must already exist!
The handle of a region to combine.
The handle of a region to combine.
How the regions are combined.
Creates a bitmap object.
The bitmap Handle, zero on failure.
The number of color planes.
The number of color bits per pixel and plane.
The bitmap pixels. Scanlines must be word-aligned.
Creates a brush object (bitmap).
A brush is used to fill image areas (background...). It has a color and a pattern, e.g. BS_SOLID.
The brush Handle, zero on failure.
Description of the brush.
Creates a Caret (text cursor).
This description is taken from the WinAPI, no guarantee for other platforms.
False on failure.
The window that owns the caret.
Bitmap Handle, or zero for a solid (black) caret, 1 for a grey caret.
The width of the caret, in logical units.
The height of the caret, in logical units.
Creates a bitmap that is compatible with the given DC.
The bitmap handle, zero on failure.
The Device Context for the bitmap.
The bitmap width in pixels.
The bitmap height in pixels.
Creates an memory Device Context, compatible with the device of the given DC.
The memory DC, zero on failure.
The device DC.
Creates a Device Dependent Bitmap (DDB) from a Device Independent Bitmap (DIB).
The bitmap handle, zero on failure.
The context for the DDB.
The bitmap info header.
An array containing the bitmap pixels.
CBM_INIT when InitBits contains valid data, else zero.
Creates a bitmap into which the application can write.
The bitmap Handle, zero on failure.
The DC for the bitmap.
Contains all information about the bitmap, except the pixels.
The type of the bitmap colors, e.g. DIB_RGB_COLORS.
Pointer to the bitmap pixels.
Zero or the Handle of a file-mapping object, from which the bitmap is initialized (needs CreateFileMapping).
The offset to the bitmap bits in the file-mapping object.
Creates an elliptic region.
The region Handle, zero on failure.
Creates an logical font, selectable into any DC.
The font handle, zero on failure.
The font description.
Creates an logical font, selectable into any DC. Allows for an long fontname.
The font handle, zero on failure.
The font description.
The font name, can be longer than 32 characters.
Creates an icon or cursor.
The Handle, zero on failure.
Creates a logical palette, selectable into any DC.
The palette Handle, zero on failure.
Creates a logical brush, selectable into any DC.

The bitmap pattern is repeated for areas of larger width or height, it should allow for smooth transitions.

Monochrome bitmaps obtain the actual text (0) or background (1) color of the DC.

The brush handle, zero on failure.
The bitmap to use for the brush.
Creates an logical Pen, selectable into any DC.
The pen Handle, zero on failure.
Creates a polygonial region.
The last point is connected to the first point, to close the region.
The region Handle, zero on failure.
The array of points.
The number of points in Points.
Can be ALTERNATE or WINDING.
Creates a rectangular region.
The region handle, zero on failure.
Creates a rectangular region with rounded corners. All parameters in logical units.
The region Handle, zero on failure.
The extent of the ellipse, used for the rounded corners.
The extent of the ellipse, used for the rounded corners.
Deletes an unowned crititcal section.
Results are unpredictable when the section is owned, i.e. has been entered but not yet left.
Deletes an Device Context, created by CreateDC.
False on failure.
Frees an GDI object.
The bitmap of a pattern brush is not destroyed with the brush.
The function fails when the Handle is selected into an DC.
False on failure.
Destroys the caret but doesn't free the bitmap.
False on failure.
Handle of the window with the caret.
Destroys an mouse cursor.
False on failure.
The cursor Handle.
Destroys an icon.
False on failure.
Converts an array of Device Points (coordinates) into Logical Points.
False on failure.
The device context, containing the coordinate mapping information.
An array of points.
The number of points to convert.
Draws a window frame control, of the specified type and style.
False on failure.
Shows or hides a floating rectangle.
Draws one or more edges of a rectangle.
Draws formatted text within a rectangle.
Enables or disables the arrows of a scrollbar control, or of the scrollbars of a window.
Enables or disables mouse and keyboard input to the specified window or control.
Ends painting a window, started with BeginPaint.
Enters a critical section.
Invokes a callback function for every available display monitor.
Invokes a callback function for every font available on a specified device.
Invokes a callback function for every available font that matches certain criteria.
Draws a filled circle or ellipse, bounded by a rectangle.
Excludes a rectangle from the clipping region, i.e. allows to paint within the rectangle.
Creates an logical pen, selectable into any DC.
Draws an string without formatting (single line).
Combines the passed Region with the current clipping region.
Fills a rectangle by using the specified brush.
Fills a region using the specified brush.
Fills an area of the display surface with the current brush.
Draws a border around a rectangle.
Returns the Handle of the active window of the calling thread.
Fills an buffer with the bitmap bits.
Returns the background color of an device context.
Returns the window that captures mouse messages.
Returns the caret position, in client coordinates.
Returns the client rectangle of a control. Left and Top are always 0.

The client rectangle is the size of the inner area of a control, where the child controls are visible.

A child control with Align=alClient will completely fill the clientrect.

Returns the smallest rectangle which includes the entire clipping region of an device context.
Returns the clipping region of an device context.
Returns an currently selected object in an device context.
Returns the ABC widths of an range of character codes.
Returns the handle of an Device Context (DC) for the client area of a window.
Returns various device specific informations.

Returns informations about any DC, which might be the screen DC representing the monitor, a control canvas or a offscreen bitmap canvas. The following constants can be utilized in the index argument:

- HORZSIZE
- VERTSIZE
- HORZRES
- BITSPIXEL
- PLANES
- SIZEPALETTE
- LOGPIXELSX - the DPI in the X axis
- LOGPIXELSY - the DPI in the Y axis
- VERTRES
- NUMRESERVED

    An example showing how to obtain the screen DPI for the X axis using GetDeviceCaps, which is the method utilized by TScreen.PixelsPerInch:

    var
      DC: HDC;
    begin
      DC := GetDC(0);
      FDPI := GetDeviceCaps(DC,LOGPIXELSX); // DPI in pixels per inch
      ReleaseDC(0, DC);
    end;

Returns the double-click time, in milliseconds.
Fills an buffer with the bitmap bits.
The (device dependent) bitmap handle.
Pointer to the output buffer, or Nil to get the required dimensions.
Returns the handle of the window that has the focus in the current thread.
Returns language information about the currently selected font.
Returns the window that the user is currently working with, session wide.
Returns information about an Icon or Cursor.
The status of a virtual key.
Returns the mapping mode of an device context.
Returns information about an display monitor.
Returns information about a graphics object.
Retrieves an range of color entries from a logical palette.
Returns the parent window of a window.
Retrieves an property value for a window.
Returns the bounding rectangle of a region, containing the entire region.
The current Foreground Mixing Mode in an device context.
Returns all or selected information about a ScrollBar.
False on failure.
The ScrollBar or window handle.
The ScrollBar kind.
Receives the values indicated in fMask.
Retrieves a handle to one of the predefined graphic objects.
Retrieves the system color for standard display elements.
Retrieves a system brush for standard display elements.
Retrieves an range of color entries from the system palette for a device.
Retrieves various system metrics.
The current text color in an device context.
Calculates the number of characters, that fit into some horizontal space.
Computes the display width and height of an string.
Computes the display width and height of an string.
Retrieves the metrics for the currently selected font.
Returns the size of the viewport of an device context.
Returns the origin of the viewport of an device context.
Returns the extent of a window, in logical units.
Returns attributes of a window.
Retrieves the bounding rectangle of a window, including the window decoration in screen coordinates.
Retrieves the bounding rectangle of a window, including the window decoration. The coordinates are given relative to the upper-left corner of the screen in screen.
Returns the Width and Height of a window, including the window decoration.

This function is a Lazarus addition and does not exist in the Windows API. It returns the Width and Height of a window, including the window decoration. To get the size of a form without the window decoration just use TCustomForm.Width and TCustomForm.Height or TCustomForm.ClientWidth and TCustomForm.ClientHeight.

Retrieves the window origin of an device context, in logical units.
Fills rectangle or triangle areas with gradient colors.
Removes the caret from the screen.
Shrinks the clipping region of an Device Context to a rectangular boundary, e.g. a text area.
The result can be one of the following constants:
Error NullRegion SimpleRegion ComplexRegion Region_Error
The region type, zero on failure.
Marks a display area for repaint.
Marks a display area for repaint.
True when the window is minimized.
Checks whether a handle refers to a window.
Determines whether a window can receive mouse and keyboard input.
The definite Visible state of a window.
True when the window is maximized.
Initializes a Critical Section object.
Releases a critical section, for use by other threads.
Draws a line from the current position up to, but not including, the specified point.
Converts logical coordinates into device coordinates.
Copies part of an source DC into an destination DC, using the specified foreground and background raster operations.

MaskBlt behaves like BitBlt when no mask bitmap is specified. It does a SRCOPY operation when also no Rop is specified. See BitBlt for general information about raster operations.

Rop contains both a foreground and a background raster operation (see MakeROP4). When a (monochrome) mask bitmap is present, its bits select either the foreground (1) or background (0) raster operation.

The MessageBox function displays an modal dialog, with the given text, caption, icon and buttons.
Finds an monitor from screen coordinates.
Finds the monitor covering most of a window.
Moves the current position to the specified point.
Moves a region relative.
Draws a filled pie-shaped wedge, from an ellipse and two radials.
Draws Bézier curves
Use Polybezier to draw cubic Bézier curves. The first curve is drawn from the first point to the fourth point with the second and third points being the control points. If the Continuous flag is TRUE then each subsequent curve requires three more points, using the end-point of the previous Curve as its starting point, the first and second points being used as its control points, and the third point its end-point. If the continous flag is set to FALSE, then each subsequent Curve requires 4 additional points, which are used exactly as in the first curve. Any additonal points which do not add up to a full bezier(4 for Continuous, 3 otherwise) are ignored. There must be at least 4 points for an drawing to occur. If the Filled Flag is set to TRUE then the resulting Poly-Bézier will be drawn as a Polygon.
Draws a Polygon
Use Polygon to draw a closed, many-sided shape on the canvas, using the value of Pen. After drawing the complete shape, Polygon fills the shape using the value of Brush. The Points parameter is an array of points that give the vertices of the polygon. Winding determines how the polygon is filled. When Winding is True, Polygon fills the shape using the Winding fill algorithm. When Winding is False, Polygon uses the even-odd (alternative) fill algorithm. StartIndex gives the index of the first point in the array to use. All points before this are ignored. NumPts indicates the number of points to use, starting at StartIndex. If NumPts is -1 (the default), Polygon uses all points from StartIndex to the end of the array. The first point is always connected to the last point. To draw a polygon on the canvas, without filling it, use the Polyline method, specifying the first point a second time at the end.
Draws a sequence of lines
Use Polyline to connect a set of points on the canvas. If you specify only two points, Polyline draws a single line. The Points parameter is an array of points to be connected. StartIndex identifies the first point in the array to use. NumPts indicates the number of points to use. If NumPts is -1 (the default), PolyLine uses all the points from StartIndex to the end of the array. Calling the MoveTo function with the value of the first point, and then repeatedly calling LineTo with all subsequent points will draw the same image on the canvas. However, unlike LineTo, Polyline does not change the value of PenPos.
Sends a message to a window.

This method is a thread-safe solution to send messages to windows. Those messages will be handled in the message loop of the application and therefore can be sent from any thread. They are not immediate, but they will awake the main thread if it is waiting for messages. These messages can be handled by procedures with the keyword message in the class of a form for example. One would then use the handle of this form as the Handle parameter of this routine. Custom messages should always have an identification number (represented by the parameter Msg) larger then the constant LM_USER. The two parameters WParam and LParam will be passed along to the window together with the Msg identification number.

The difference between SendMessage and PostMessage is the way that they return control to the calling thread. With SendMessage control is not returned until the window that the message was sent to has completed processing the sent message, however with PostMessage control is returned immediately.

LCLIntf.SendMessage
Redraws (part of) a window.
Restores normal mouse input processing, after .
Releases an Device Context obtained by GetDC.
Zero on failure.
The window associated with the DC.
Removes a named property from a window.
Restores an Device Context (DC) to an previously saved state.
Saves the state of an Device Context in the context stack.
Converts absolute Screen coordinates into Client relative coordinates.
False on failure.
The window with the client area.
The point to convert.
Sends a message directed to a window to the message pool of the application

This method is a thread-safe solution to send messages to windows. Those messages will be handled in the message loop of the application and therefore can be sent from any thread. They are not immediate, but they will awake the main thread if it is waiting for messages. These messages can be handled by procedures with the keyword message in the class of a form for example. One would then use the handle of this form as the HandleWnd parameter of this routine. Custom messages should always have an identification number (represented by the parameter Msg) larger then the constant LM_USER. The two parameters WParam and LParam will be passed along to the window together with the Msg identification number.

The difference between SendMessage and PostMessage is the way that they return control to the calling thread. With SendMessage control is not returned until the window that the message was sent to has completed processing the sent message, however with PostMessage control is returned immediately.

LCLIntf.PostMessage
The handle of the window to receive the message.
Sets focus to the specified window, if the application is on top.
Sets the current background color of an decice context.
Sets the background mix mode (transparency) of an device context.
Sets the mouse capture to the specified window.
Moves the Caret to the specified coordinates.
Moves the Caret into a window.
Changes the shape of the mouse cursor.
Changes the position of the mouse cursor.
Sets the mapping mode of an device context.
Assigns a menu to a window.
Changes the parent of a window.
Adds a property to a window.
Sets the Foreground Mixing Mode in an device context.
Sets the ClipRegion of an DeviceContext.
Selects an object into an device context.
Sets the keyboard input focus to the specified window.
Moves a window in front of all other windows, and activates it.
Sets the StrechBlt mode for an device context.
Sets the colors for one or more display elements of window borders and desktop.
Sets extra intercharacter spacing in text output.
Sets the text color in an device context.
Sets the extent of the viewport for a device context.
Sets the device origin corresponding to the window origin (0,0) in an device context.
Sets the extent of the window for an device context.
Sets an attribute of a window.
Specifies which window point maps to the viewport origin (0,0).
Changes the size, position, and Z order of a window.
Defines the visible region of a window or control
This function sets the visible region of a window or control. It's parameters are: hWnd - The handle of the window or control hRgn - The handle to the region which contains the visible section of the window or control bRedraw - True if the control or window should be repainted following the call of this function, false otherwise See also the wiki documentation: http://wiki.lazarus.freepascal.org/LCL_Tips#Creating_a_non-rectangular_window_or_control
TWinControl.SetShape LCLIntf.CreateRectRgn
Shows the Caret (text cursor).
Shows or hides a ScrollBar.
Shows a window in an specific state.
Copies a rectangular region into an device context, shrinking or stretching it as required.
Copies a rectangular region from a DIB into an device context, shrinking or stretching it as required.
Retrieves or sets one of the system-wide parameters.
Draws an string without formatting (single line).
Forces an immediate repaint of a window, if required.
Finds the window containing the specified point.
Returns True when the rectangles are identical.
Returns the scollbar position.
If the scrollbar is not visible, then the return value is 0.
The position, zero if the scrollbar is not visible.
Returns the minimum and maximum Position values of a ScrollBar.
Extracts the red color value from a COLORREF.
Extracts the green color value from a COLORREF.
Extracts the blue color value from a COLORREF.
Extracts the red, green and blue color values from a COLORREF.
Extracts the red, green and blue color values from a COLORREF.
Converts an imagelist index into an overlay index.
Ready for combination with another imagelist index.
The imagelist index of the overlay.
Inflates the rectangle in all directions.

The deltas are applied to every side, i.e. the width and height increase by the double amount.

Positive values inflate, negative values deflate.

The rectangle is clipped so that width and height never can become negative.

This method can be used to add or subtract a border around the rectangle.

Always True.
This rectangle is modified.
The horizontal increase, negative to decrease.
The vertical increase, negative to decrease.
Intersects SrcRect1 and SrcRect2 into DestRect.

Intersecting means that DestRect will be the overlapping area of SrcRect1 and SrcRect2.

If SrcRect1 and SrcRect2 do not overlap the Result is false, else true.

False when the rectangles don't overlap.
Receives the intersection.
Checks for ASCII letter or digit characters.
True when the character is a letter or digit.
Returns True if the rectangle is empty.
IsEmptyRect returns true if the area of the rectangle is empty, i.e. has a zero or negative width or height.
True if the rectangle is empty.
Removes an timer.
Zero on failure!
The window handle associated with the timer, can be zero.
The timer ID.
Copies two words into a double word.
The combined doubleword.
The low word.
The high word.
Copies two bytes into a word.
The low byte.
The high byte.
Copies two words into a double word, usable as a message wParam.
The result has the size of an pointer.
The low word.
The high word.
Copies two words into a double word, usable as a message lParam.
The low word.
The high word.
Copies two words into a double word, usable as a message Result.
The low word.
The high word.
Move Left/Right by dx, Top/Bottom by dy. Return Top and Left are >= 0.
False if resulting Top or Left are negative.
Checks whether a Point is within a Rect.

Top and Left side are part of the rectangle, but Bottom and Right side are outside.

True when Point is within Rect.
Combines Red, Green and Blue values into an TColorRef value.

The bytes are shifted into place, following the format $00bbggrr, which is the format of the Windows API type COLORREF. Their actual physical order depends on the endianness of the machine.

The combined COLORREF created with the given color channels.
The value of the red channel. zero indicates no contribution, 255 indicates a full red channel.
The value of the green channel
The value of the blue channel
Scrolls the content of a window, by a number of pixels.
Horizontal distance (positive to scroll right)
Vertical distance (positive to scroll down)
The part of the window, that is to be scrolled.
Pixels falling outside this rectangle are lost.
Copies coordinates into a rectangle.
Always True.
Clears the rectangle to all zero coordinates.
Always True.
Changes the Position of an ScrollBar slider.
The SetScrollPos function sets the position of the scroll box (thumb) in the specified scroll bar and, if requested, redraws the scroll bar to reflect the new position of the scroll box.
The previous Position, zero if invisible.
The ScrollBar or Window Handle.
SB_CTL means a ScrollBar control.
The new Position.
True forces a repaint.
Sets the minimum and maximum position values of an ScrollBar.
Always True.
Creates or resets an timer for the given time interval.

Every timer has a unique ID, which is reported in the timer message and can be used to reset or kill the timer.

When the time has elapsed, the callback procedure is invoked. If no procedure is given, a WM_TIMER message is sent to the window. If also no window is given, the function fails.

When the timer already exists, it is reset to the new interval.

The timer ID, or zero on failure.
The window associated with the timer.
The ID of the timer, ignored when Wnd is zero.
The time interval to wait.
The callback procedure, can be Nil.
Converts an TSmallPoint into an TPoint.
Computes the bounding box of the geometric difference of two rectangles.

When the rectangles do not overlap completely in either x or y direction, the result is the first rectangle (lprcSrc1).

Otherwise the overlapping area is excluded from the first rectangle.

The bounding box is the rectangle that covers the entire resulting area.

False when the resulting rectangle is empty.
The rectangle to subtract.
Computes the bounding box of the union of two rectangles.

The bounding box is the rectangle that covers the entire resulting area. Here the result covers both rectangles.

The rectangles can be disjoint.

Rectangles with a zero or negative width or height are treated as empty rectangles (ignored).

False when the resulting rectangle is empty, i.e. when both source rectangles are empty.
Open a given URL with the default browser
The function uses FindDefaultBrowser to find the default browser. If it can be found it starts it and returns true. The AURL is passed as parameter. AURL must be an URL like http://www.lazarus.freepascal.org or file:///tmp/test.txt or file://C:\test.txt.