Example: /MacFrameworks/CGWindow capture

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/CGWindow capture


Required plugins for this example: MBS MacFrameworks Plugin, MBS MacCG Plugin, MBS Picture Plugin, MBS MacCF Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/CGWindow capture

This example is the version from Sun, 17th Mar 2012.

Project "CGWindow capture.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() dim windowID as integer = CGWindowMBS.GetWindowID(self) dim p as picture = CGWindowMBS.CreateWindowListImage(self.left+canvas1.left, self.top+canvas1.top, canvas1.Width, canvas1.Height, CGWindowMBS.kCGWindowListOptionOnScreenBelowWindow,windowID, CGWindowMBS.kCGWindowImageDefault) Title=str(p.Width)+" x "+str(p.Height) // scale down to match canvas size dim f as Double = min(canvas1.height/p.height,canvas1.width/p.width) dim w as integer = f * p.Width dim h as integer = f * p.Height Canvas1.Backdrop=p.ScaleMBS(w,h) End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() // take screenshot dim windowID as integer = CGWindowMBS.GetWindowID(self) dim p as Picture = CGWindowMBS.CreateWindowListImage(0, 0, 0, 0, CGWindowMBS.kCGWindowListOptionOnScreenBelowWindow, windowID, CGWindowMBS.kCGWindowImageDefault) Title=str(p.Width)+" x "+str(p.Height) // scale down to match canvas size dim f as Double = min(canvas1.height/p.height,canvas1.width/p.width) dim w as integer = f * p.Width dim h as integer = f * p.Height Canvas1.Backdrop=p.ScaleMBS(w,h) End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() dim windowID as integer = CGWindowMBS.GetWindowID(self) // you can grab CGImageMBS if you need dim img as CGImageMBS = CGWindowMBS.CreateWindowListCGImage(0,0,0,0,CGWindowMBS.kCGWindowListOptionOnScreenBelowWindow,windowID, CGWindowMBS.kCGWindowImageDefault) // and convert it later yourself to picture (if needed) dim p as Picture = img.Picture Title=str(p.Width)+" x "+str(p.Height) // scale down to match canvas size dim f as Double = min(canvas1.height/p.height,canvas1.width/p.width) dim w as integer = f*p.Width dim h as integer = f*p.Height Canvas1.Backdrop=p.ScaleMBS(w,h) End EventHandler
End Control
EventHandler Sub Open() if not TargetMachO then MsgBox "This project requires Mac OS X 10.5!" end if End EventHandler
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

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


💬 Ask a question or report a problem