Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/CGWindow capture
Function:
Required plugins for this example: MBS MacCG Plugin, MBS MacFrameworks Plugin, MBS Picture 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.rbp"
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

Feedback, Comments & Corrections

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




Links
MBS Xojo PDF Plugins