User Tools

Site Tools


capturing_20the_20contents_20of_20a_20window

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Last revision Both sides next revision
capturing_20the_20contents_20of_20a_20window [2018/03/31 13:19]
127.0.0.1 external edit
capturing_20the_20contents_20of_20a_20window [2018/04/13 14:53]
richardrussell Added syntax highlighting
Line 3: Line 3:
 //by Richard Russell, May 2007 (updated)//​\\ \\  You can //​capture//,​ as a bitmap file, the contents of your program'​s main output window using the ***SCREENSAVE** (or ***GSAVE**) command. But what if you want to save not your output window but the contents of a dialogue box, Direct3D window or other window? There is no equivalent built-in command to do that.\\ \\  The procedures listed below will capture to a file the contents of the window whose handle is specified. If one doesn'​t work the other probably will. The procedures as listed save the image as a BMP file; if you want to use a different file format change **PROCsaveasbmp(hbm%,​ file$)** to [[/​Saving%20a%20GIF%20image|PROCsavegif(hbm%,​ file$)]] or [[/​Saving%20a%20JPEG%20image|PROCsavejpg(hbm%,​ file$, quality%)]] etc. as appropriate.\\ \\  //by Richard Russell, May 2007 (updated)//​\\ \\  You can //​capture//,​ as a bitmap file, the contents of your program'​s main output window using the ***SCREENSAVE** (or ***GSAVE**) command. But what if you want to save not your output window but the contents of a dialogue box, Direct3D window or other window? There is no equivalent built-in command to do that.\\ \\  The procedures listed below will capture to a file the contents of the window whose handle is specified. If one doesn'​t work the other probably will. The procedures as listed save the image as a BMP file; if you want to use a different file format change **PROCsaveasbmp(hbm%,​ file$)** to [[/​Saving%20a%20GIF%20image|PROCsavegif(hbm%,​ file$)]] or [[/​Saving%20a%20JPEG%20image|PROCsavejpg(hbm%,​ file$, quality%)]] etc. as appropriate.\\ \\ 
 ===== Method one ===== ===== Method one =====
-\\  This method is most appropriate for dialogue boxes and other child windows. It will work even if the window is wholly or partially obscured, but won't work with Direct3D windows:\\ \\ +\\  This method is most appropriate for dialogue boxes and other child windows. It will work even if the window is wholly or partially obscured, but won't work with Direct3D windows: 
 + 
 +<code bb4w> ​
         DEF PROCcapturewindow1(hwnd%,​ file$)         DEF PROCcapturewindow1(hwnd%,​ file$)
         PRF_CHILDREN = 16         PRF_CHILDREN = 16
Line 23: Line 25:
         SYS "​DeleteDC",​ hdc%         SYS "​DeleteDC",​ hdc%
         ENDPROC         ENDPROC
-So if you wanted to capture the contents of a dialogue box you might do:\\ \\ +</​code>​ 
 + 
 +So if you wanted to capture the contents of a dialogue box you might do: 
 + 
 +<code bb4w>
         PROCcapturewindow1(!dlg%,​ @dir$+"​dialogue.bmp"​)         PROCcapturewindow1(!dlg%,​ @dir$+"​dialogue.bmp"​)
 +</​code>​
 +
 where **dlg%** is the value returned from **FN_newdialog**.\\ \\  The procedure calls the **PROCsaveasbmp** routine which is listed below. If you want to capture the window as a JPEG or GIF file change the **PROCsaveasbmp** to [[/​Saving%20a%20JPEG%20image|PROCsavejpeg]] or [[/​Saving%20a%20GIF%20image|PROCsavegif]] respectively.\\ \\  where **dlg%** is the value returned from **FN_newdialog**.\\ \\  The procedure calls the **PROCsaveasbmp** routine which is listed below. If you want to capture the window as a JPEG or GIF file change the **PROCsaveasbmp** to [[/​Saving%20a%20JPEG%20image|PROCsavejpeg]] or [[/​Saving%20a%20GIF%20image|PROCsavegif]] respectively.\\ \\ 
 ===== Method two ===== ===== Method two =====
-\\  This method is appropriate for Direct3D windows and other windows which don't give the required results with the previous method. However if the window is wholly or partially obscured, the captured image will include the obscuring object:\\ \\ +\\  This method is appropriate for Direct3D windows and other windows which don't give the required results with the previous method. However if the window is wholly or partially obscured, the captured image will include the obscuring object: 
 + 
 +<code bb4w>
         DEF PROCcapturewindow2(hwnd%,​ file$)         DEF PROCcapturewindow2(hwnd%,​ file$)
         LOCAL rc{}, hdc%, hbm%, ddc%, oldbm%         LOCAL rc{}, hdc%, hbm%, ddc%, oldbm%
Line 43: Line 53:
         SYS "​DeleteDC",​ ddc%         SYS "​DeleteDC",​ ddc%
         ENDPROC         ENDPROC
-So if you wanted to capture your Direct3D output you might do:\\ \\ +</​code>​ 
 + 
 +So if you wanted to capture your Direct3D output you might do: 
 + 
 +<code bb4w>
         PROCcapturewindow2(@hwnd%,​ @dir$+"​direct3d.bmp"​)         PROCcapturewindow2(@hwnd%,​ @dir$+"​direct3d.bmp"​)
 +</​code>​
 +
 The procedure calls the **PROCsaveasbmp** routine which is listed below. If you want to capture the window as a JPEG or GIF file change the **PROCsaveasbmp** to [[/​Saving%20a%20JPEG%20image|PROCsavejpeg]] or [[/​Saving%20a%20GIF%20image|PROCsavegif]] respectively.\\ \\  The procedure calls the **PROCsaveasbmp** routine which is listed below. If you want to capture the window as a JPEG or GIF file change the **PROCsaveasbmp** to [[/​Saving%20a%20JPEG%20image|PROCsavejpeg]] or [[/​Saving%20a%20GIF%20image|PROCsavegif]] respectively.\\ \\ 
 ===== Method three ===== ===== Method three =====
-\\  This is similar to **Method two**, but simulates capturing the mouse pointer in addition to the window contents:\\ \\ +\\  This is similar to **Method two**, but simulates capturing the mouse pointer in addition to the window contents: 
 + 
 +<code bb4w>
         DEF PROCCaptureWindowWithMousePointer(hwnd%,​ file$)         DEF PROCCaptureWindowWithMousePointer(hwnd%,​ file$)
         LOCAL ddc%, hdc%, hbm%, oldbm%, hicon%         LOCAL ddc%, hdc%, hbm%, oldbm%, hicon%
Line 81: Line 99:
         SYS "​DeleteDC",​ ddc%         SYS "​DeleteDC",​ ddc%
         ENDPROC         ENDPROC
-\\ // by Michael Hutton, November 2010//\\ \\  Capturing the whole desktop can be done with:\\ +</​code>​ 
 + 
 +// by Michael Hutton, November 2010//\\ \\  Capturing the whole desktop can be done with: 
 + 
 +<code bb4w>
         DEF PROC_CaptureScreenWithMousePointer(_file$)         DEF PROC_CaptureScreenWithMousePointer(_file$)
         LOCAL ddc%, hdc%, hbm%, oldbm%, xscreen%, yscreen% , hicon% , X%, Y%         LOCAL ddc%, hdc%, hbm%, oldbm%, xscreen%, yscreen% , hicon% , X%, Y%
Line 110: Line 132:
         SYS "​DeleteObject",​ ii.hbmColor%         SYS "​DeleteObject",​ ii.hbmColor%
         ENDPROC         ENDPROC
-\\ \\ +</​code>​ 
 ===== Saving a bitmap to a file ===== ===== Saving a bitmap to a file =====
-\\  This routine can be used whenever you want to save to file a bitmap whose handle you know:\\ \\ +\\  This routine can be used whenever you want to save to file a bitmap whose handle you know: 
 + 
 +<code bb4w>
         DEF PROCsaveasbmp(hbm%,​file$)         DEF PROCsaveasbmp(hbm%,​file$)
         LOCAL bmp%, width%, height%, size%, data%, res%         LOCAL bmp%, width%, height%, size%, data%, res%
Line 149: Line 174:
         SYS "​GlobalFree",​ data%         SYS "​GlobalFree",​ data%
         ENDPROC         ENDPROC
 +</​code>​
capturing_20the_20contents_20of_20a_20window.txt · Last modified: 2018/04/16 14:41 by richardrussell