Platforms to show: All Mac Windows Linux Cross-Platform

Back to CGDisplayMBS class.

CGDisplayMBS.AllDisplayModes(Options as Dictionary = nil) as CGDisplayModeMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Return an array of all modes for the specified display.
Example
dim d as CGDisplayMBS = CGDisplayMBS.MainDisplay

Dim options As New Dictionary
options.Value(CGDisplayMBS.kCGDisplayShowDuplicateLowResolutionModes) = false

dim modes(-1) as string
for each mode as CGDisplayModeMBS in d.AllDisplayModes(options)
modes.append str(mode.Width)+" x "+str(mode.Height)
next
MsgBox Join(modes,EndOfLine)

Returns an empty array on any error.
Requires Mac OS X 10.6

CGDisplayMBS.AvailableModes as Dictionary()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns an array filled with dictionaries (one for each mode).
Example
// Display all available graphic modes:

Listbox1.DeleteAllRows
Listbox1.ColumnCount = 4

dim d as CGDisplayMBS = CGDisplayMBS.MainDisplay

dim a(-1) as Dictionary = d.AvailableModes

for each di as Dictionary in a

Listbox1.AddRow di.Value(d.kCGDisplayMode).stringValue
Listbox1.cell(Listbox1.LastIndex,1) = di.Value(d.kCGDisplayWidth)+" x "+di.Value(d.kCGDisplayHeight)
Listbox1.cell(Listbox1.LastIndex,2) = di.Value(d.kCGDisplayRefreshRate)
Listbox1.cell(Listbox1.LastIndex,3) = di.Value(d.kCGDisplayBitsPerPixel)

next

Returns empty error on any error.

Some examples using this method:

CGDisplayMBS.BestModeForParameters(BitsPerPixel as Integer, Width as Integer, Height as Integer, byref ExactMatch as boolean) as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns a Dictionary with the best mode found for the given parameters.

Returns nil on any error.

Try to find a display mode of specified depth with dimensions equal or greater than specified.
If no depth match is found, try for the next larger depth with dimensions equal or greater than specified. If no luck, then just return the current mode.

exactmatch is set to 'true' if an exact match in width, height, and depth is found, and 'false' otherwise.
Returns nil if display is invalid.

CGDisplayMBS.BestModeForParametersAndRefreshRate(BitsPerPixel as Integer, Width as Integer, Height as Integer, RefreshRate as Integer, byref ExactMatch as boolean) as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns a Dictionary with the best mode found for the given parameters.

Returns nil on any error.

Try to find a display mode of specified depth with dimensions equal or greater than specified.
If no depth match is found, try for the next larger depth with dimensions equal or greater than specified. If no luck, then just return the current mode.

exactmatch is set to 'true' if an exact match in width, height, and depth is found, and 'false' otherwise.
Returns nil if display is invalid.

CGDisplayMBS.BestModeForParametersAndRefreshRateWithProperty(BitsPerPixel as Integer, Width as Integer, Height as Integer, RefreshRate as Integer, propertyName as string, byref ExactMatch as boolean) as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns a Dictionary with the best mode found for the given parameters.

Returns nil on any error.

Try to find a display mode of specified depth with dimensions equal or greater than specified.
If no depth match is found, try for the next larger depth with dimensions equal or greater than specified. If no luck, then just return the current mode.

exactmatch is set to 'true' if an exact match in width, height, and depth is found, and 'false' otherwise.
Returns nil if display is invalid.

CGDisplayMBS.Capture as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Captures this display for your use.
Example
dim d as CGDisplayMBS = CGDisplayMBS.MainDisplay

if d.Capture = 0 then

dim c as CGContextMBS = d.DrawingContext

// watch it drawing red
c.SetRGBFillColor 1.0, 0.0, 0.0, 1.0
c.FillRect CGMakeRectMBS(0,0,d.PixelsWide,d.PixelsHigh)

DelayMBS 3.0

call d.Release
else
MsgBox "Failed to capture displays."
end if

Don't forget to Release the display later.
Returns an error code.

CGDisplayMBS.CaptureWithOptions(options as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Captures this display for your use.
Example
dim d as CGDisplayMBS = CGDisplayMBS.MainDisplay

if d.CaptureWithOptions(d.kCGCaptureNoOptions) = 0 then

dim c as CGContextMBS = d.DrawingContext

// watch it drawing red
c.SetRGBFillColor 1.0, 0.0, 0.0, 1.0
c.FillRect CGMakeRectMBS(0,0,d.PixelsWide,d.PixelsHigh)

DelayMBS 3.0

call d.Release
else
MsgBox "Failed to capture displays."
end if

Don't forget to Release the display later.
Returns an error code.
Use kCGCaptureNoOptions and kCGCaptureNoFill for options parameter.

CGDisplayMBS.CreateImage as CGImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Return an image containing the contents of the display.
Example
dim d as CGDisplayMBS = CGDisplayMBS.MainDisplay
dim img as CGImageMBS = d.CreateImage

Backdrop = img.Picture

Requires Mac OS X 10.6.

CGDisplayMBS.CreateImageAsync(receiverDelegate as CreateImageAsyncDelegateMBS, jpegQuality as Double = 0.9, tag as Variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 15.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Asynchronously creates an image with screenshot.

If jpeg is >= 0, we use it as quality for the jpeg compression and provide the JPEG data as memoryblock in the delegate.
Tag is passed through as is.

Delegate declaration:
CreateImageAsyncDelegateMBS(img as CGImageMBS, JPEGData as MemoryBlock, Tag as Variant)

Some examples using this method:

CGDisplayMBS.CreateImageForRect(rect as CGRectMBS) as CGImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Return an image containing the contents of the rectangle rect, specified in display space, of the display identified by self.
Example
dim r as CGRectMBS = CGMakeRectMBS(100,100,500,500)
dim d as CGDisplayMBS = CGDisplayMBS.MainDisplay
dim img as CGImageMBS = d.CreateImageForRect(r)

Backdrop = img.Picture

The actual rectangle used is the rectangle returned from CGRectIntegral(rect).
Requires Mac OS X 10.6.

Some examples using this method:

CGDisplayMBS.DrawingContext as CGContextMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Return a CGContext suitable for drawing to the captured display, or nil if display has not been captured.
Example
dim d as CGDisplayMBS = CGDisplayMBS.MainDisplay

if d.Capture = 0 then

dim c as CGContextMBS = d.DrawingContext

// watch it drawing red
c.SetRGBFillColor 1.0, 0.0, 0.0, 1.0
c.FillRect CGMakeRectMBS(0,0,d.PixelsWide,d.PixelsHigh)

DelayMBS 3.0

call d.Release
else
MsgBox "Failed to capture displays."
end if

The context is owned by the device and should not be released by the caller.

The context remains valid while the display is captured and while the display configuration is unchanged. Releasing the captured display or reconfiguring the display invalidates the drawing context.

The determine when the display configuration is changing, use
CGDisplayReconfigurationEventMBS class.

Some examples using this method:

CGDisplayMBS.GetDisplayTransferByTable(capacity as Integer, red as memoryblock, green as memoryblock, blue as memoryblock, byref samplecount as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Get transfer tables.

Capacity should contain the number of samples each array can hold, and sampleCount is filled in with the number of samples actually copied in.

You must pass in Memoryblocks with the given size (capacity*4 Bytes).
Returns an error code.

CGDisplayMBS.GetDisplayTransferFormula(byref formula as CGDisplayTransferFormulaMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Queries the display for the current gamma formula.

Returns an error code.

Some examples using this method:

CGDisplayMBS.HideCursor as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Hides the mouse cursor.

Returns an error code.
Decrements hide cursor count.

CGDisplayMBS.Info as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.6 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns the information CFDictionary about the display.
Example
dim c as CGDisplayMBS = CGDisplayMBS.MainDisplay
dim d as Dictionary = c.Info

MsgBox d.Value("DisplaySerialNumber")

On any error the return value is nil.
This function leaks around 4 to 16 KB of memory on Mac OS X 10.4. Not in the versions 10.3 or 10.5.

CGDisplayMBS.InfoAsCFDictionary as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 14.4 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns the information CFDictionary about the display.

On any error the return value is nil.
Returns a CFDictionaryMBS object. Returned as Variant to reduce plugin dependencies.

CGDisplayMBS.IsCaptured as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns true if you captured this display.
Example
dim d as new CGDisplayMBS // pick main display

MsgBox str(d.IsCaptured)

CGDisplayMBS.MoveCursorToPoint(x as Double, y as Double) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Move the cursor to the specified point relative to the display origin (the upper left corner of the display).
Example
Function KeyDown(Key As String) As Boolean
// in a window keydown event:

if asc(key)=32 then
dim c as new CGDisplayMBS
dim error as Integer = c.MoveCursorToPoint(200,200)

Title=str(error) // zero on success

end if

End Function

Returns CGDisplayNoErr (0) on success.
No events are generated as a result of this move.
Points that would lie outside the desktop are clipped to the desktop.

CGDisplayMBS.OpenGLDisplayMask as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Return the OpenGL display mask for display, or 0 is display is an invalid display.

CGDisplayMBS.Release as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Releases the display.
Example
dim d as CGDisplayMBS = CGDisplayMBS.MainDisplay

if d.Capture = 0 then

dim c as CGContextMBS = d.DrawingContext

// watch it drawing red
c.SetRGBFillColor 1.0, 0.0, 0.0, 1.0
c.FillRect CGMakeRectMBS(0,0,d.PixelsWide,d.PixelsHigh)

DelayMBS 3.0

call d.Release
else
MsgBox "Failed to capture displays."
end if

Returns an error code.

CGDisplayMBS.SetDisplayMode(mode as CGDisplayModeMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Switch the display mode to mode.

The selected display mode persists for the life of the program, and automatically reverts to the permanent setting when the program terminates.

When changing display modes of displays in a mirroring set, other displays in the mirroring set will be set to a display mode capable of mirroring the bounds of the largest display being explicitly set.

Note that after switching, display parameters and addresses may change.

CGDisplayMBS.SetDisplayTransferByByteTable(count as Integer, red as memoryblock, green as memoryblock, blue as memoryblock) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Set a display gamma/transfer function using tables of data for each channel.

As a convenience, allow setting of the gamma table by byte values.
Returns an error code.

CGDisplayMBS.SetDisplayTransferByTable(count as Integer, red as memoryblock, green as memoryblock, blue as memoryblock) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Set a display gamma/transfer function.

Set a display gamma/transfer function using tables of data for each channel.
Values within each table should have values in the range of 0.0 through 1.0.
The same table may be passed in for red, green, and blue channels. 'count' indicates the number of entries in each table.
The tables are interpolated as needed to generate the number of samples needed by hardware.

Returns an error code.

CGDisplayMBS.SetDisplayTransferFormula(formula as CGDisplayTransferFormulaMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Set a display gamma/transfer function.

Set a display gamma/transfer function from a formula specifying min and max values and a gamma for each channel.
Gamma values must be greater than 0.0.
To get an antigamma of 1.6, one would specify a value of (1.0 / 1.6)
Min values must be greater than or equal to 0.0 and less than 1.0.
Max values must be greater than 0.0 and less than or equal to 1.0.
Out of range values, or Max greater than or equal to Min result in a kCGSRangeCheck error.

Values are computed by sampling a function for a range of indices from 0 through 1: value = Min + ((Max - Min) * pow(index, Gamma))
The resulting values are converted to a machine specific format and loaded into hardware.

Returns an error code.

Some examples using this method:

CGDisplayMBS.SetRotation(angle as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 13.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Rescans the bus of displays and changes the rotation of the display.
Example
dim d as CGDisplayMBS = CGDisplayMBS.MainDisplay
dim e as Integer = d.SetRotation(90)

if e<>0 then
MsgBox "Error: "+str(e)
end if

Returns IOKit error code. Zero means success.

Lasterror is set.

CGDisplayMBS.SetStereoOperation(stereo as boolean, forceBlueLine as boolean, option as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Immediately enable or disable stereo operation for a display.

Note that the system normally detects the presence of a stereo window, and will automatically switch a display containing a stereo window to stereo operation. This function provides a mechanism to force a display to stereo operation, and to set options (such as blue line sync signal) when in stereo operation.

When in stereo operation, a display may need to generate a special stereo sync signal as part of the video output. The sync signal consists of a blue line which occupies the first 25% of the last scanline for the left eye view, and the first 75% of the last scanline for the right eye view. The remainder of the scanline is black. To force the display to generate this sync signal, pass true for forceBlueLine; otherwise, pass false.

Lasterror is set to kCGErrorSuccess on success, or kCGErrorRangeCheck if the display does not support the stereo operation settings requested.

On success, the display resolution, mirroring mode, and available display modes may change due to hardware-specific capabilities and limitations. You should check these settings to verify that they are appropriate for your application.

Lasterror is set.

CGDisplayMBS.ShieldingWindowID as UInt32

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns window ID of the shield window for the captured display, or 0 if the display is not not shielded.

CGDisplayMBS.ShowCursor as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Shows the mouse cursor.

Returns an error code.
Increments hide cursor count.

Some examples using this method:

CGDisplayMBS.SwitchToMode(Mode as Dictionary) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Switch display mode.

Note that after switching, display parameters and addresses may change.
The selected display mode persists for the life of the program, and automatically reverts to the permanent setting made by Preferences when the program terminates.
The mode dictionary passed in must be a dictionary vended by other CGDirectDisplay APIs such as BestModeForParameters() and AvailableModes().
Returns an error code.

Some examples using this method:

CGDisplayMBS.WaitForBeamPositionOutsideLines(upperScanLine as UInt32, lowerScanLine as UInt32) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Wait until the beam position is outside the range specified.

Wait until the beam position is outside the range specified by upperScanLine and lowerScanLine.
Note that if upperScanLine and lowerScanLine encompass the entire display height, the function returns an error.
lowerScanLine must be greater than or equal to upperScanLine.

Some display systems may not conventional video vertical and horizontal sweep in painting.
These displays report a kCGDisplayRefreshRate of 0 in the CFDictionaryRef returned by CurrentMode(). On such displays, this function returns at once.

Some drivers may not implement support for this mechanism.
On such displays, this function returns at once.

Returns CGDisplayNoErr on success, and an error if display or upperScanLine and lowerScanLine are invalid.

The app should set the values of upperScanLine and lowerScanLine to allow enough lead time for the drawing operation to complete. A common strategy is to wait for the beam to pass the bottom of the drawing area, allowing almost a full vertical sweep period to perform drawing.

To do this, set upperScanLine to 0, and set lowerScanLine to the bottom of the bounding box:
lowerScanLine = (CGBeamPosition)(cgrect.origin.y + cgrect.size.height);

IOKit may implement this as a spin-loop on the beam position call used for BeamPosition().
On such system the function is CPU bound, and subject to all the usual scheduling pre-emption.
In particular, attempting to wait for the beam to hit a specific scanline may be an exercise in frustration.

These functions are advisary in nature, and depend on IOKit and hardware specific drivers to implement support. If you need extremely precise timing, or access to vertical blanking interrupts, you should consider writing a device driver to tie into hardware-specific capabilities.

Returns an error code.

The items on this page are in the following plugins: MBS MacCG Plugin.


The biggest plugin in space...