Jump to content

Possible to not screencapture title bar of window...?


Burgs
 Share

Recommended Posts

Greetings,

  I have a simple code example of my issue below.  I create a GUI with a 'Title bar' (the '$WS_CAPTION, $WS_SYSMENU' enabled).  I then later use the '_ScreenCapture_CaptureWnd' to capture the contents of that GUI window into an image file. 

  My question is if it is possible to NOT include the 'Title bar' within the screen-captured image...?  Is there some setting that might accomplish that?  The way I have it coded here the GUI 'Title bar' is being included within my captured image and I do not wish it to be so...thanks in advance for any advice.

;****CREATE THE GUI...

   $_CTRL_GUI = GUICreate("Positioning", 512, 512, -1, -1, BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU, $WS_EX_TOPMOST))
   GUISetBkColor(0xFFFFFF)  ;set GUI background to 'White'...

   GUISetState(@SW_SHOW, $_CTRL_GUI)

   ;****
   
   $_CONTROL_HWD = WinGetHandle($_CTRL_GUI)  ;save the handle to the Window...

...

    if WinExists($_CONTROL_HWD) Then

    $_WinPOS = WinGetPos($_CONTROL_HWD)

     if (IsArray($_WinPOS) == 1) AND (@error <> 1) Then
     _ScreenCapture_CaptureWnd(@ScriptDir & "\Copy_Image.jpg", $_CTRL_GUI, 0, 1, Number($_WinPOS[2] - 1), Number($_WinPOS[3] - 1), False)
     EndIf  ;'$_WinPOS' IS an array...AND '@error' NOT "1"...
    EndIf  ;WinExists ($_CONTROL_HWD)...

 

 

Link to comment
Share on other sites

Wouldn't you be able to just use this function?

_WinAPI_GetClientRect

Rather than WinGetPos.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Hi again,

  I tried the '_WinAPI_GetClientRect' however it still seems to include the title bar in the saved screencapture image...evidently it is considered part of the 'client area' of the window.

  I am a bit confused about usage of the ' _WinAPI_GetSystemMetrics($SM_CYCAPTION) '...how do I dictate which GUI window I want to return the 'Title bar' measurement into the command...?  There is no parameter to accept the window I want to use...?

 

Link to comment
Share on other sites

#include <WindowsConstants.au3>
#include <ScreenCapture.au3>

$_CONTROL_HWD = GUICreate("Positioning", 512, 512, -1, -1, BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU, $WS_EX_TOPMOST))
GUISetState(@SW_SHOW, $_CONTROL_HWD)

Sleep(2000)

$_WinPOS = WinGetPos($_CONTROL_HWD)
$iTitleHeight = _WinAPI_GetSystemMetrics(31) + 1
_ScreenCapture_CaptureWnd(@ScriptDir & "\Copy_Image.jpg",  $_CONTROL_HWD, 0, $iTitleHeight, Number($_WinPOS[2] - 1), Number($_WinPOS[3] - 1), False)

 

Read help on _WinAPI_GetSystemMetrics, click link to GetSystemMetrics, search for "title" and get SM_CYSIZE (31). HTH

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

@Burgs You can use temporary control for recalculate left-top corner of client area to screen coordinates 

#include <WindowsConstants.au3>
#include <ScreenCapture.au3>

Global $iW = 512, $iH = 512
$HWD = GUICreate("Positioning", $iW, $iH, -1, -1, BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU, $WS_EX_TOPMOST))
GUISetBkColor(0xFFFFFF)

$tPoint = DllStructCreate($tagPoint)
$TempCtrl = GUICtrlCreateLabel("", 0, 0, 1, 1)
_WinAPI_ClientToScreen(GUICtrlGetHandle($TempCtrl), $tPoint)
GUICtrlDelete($TempCtrl)

GUISetState()
WinWaitActive($HWD, "", 2)
_ScreenCapture_Capture(@ScriptDir & "\Copy_Image.jpg", $tPoint.X, $tPoint.Y, $tPoint.X + $iW - 1, $tPoint.Y + $iH - 1, False)

Or simply copy full client area

#include <WindowsConstants.au3>
#include <ScreenCapture.au3>

Global $iW = 512, $iH = 512
$hWnd = GUICreate("Positioning", $iW, $iH, -1, -1, BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU, $WS_EX_TOPMOST))
GUISetBkColor(0xFFFFFF)
GUISetState()
WinWaitActive($hWnd, "", 2)

$hDDC = _WinAPI_GetDC($hWnd)
$hCDC = _WinAPI_CreateCompatibleDC($hDDC)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH)
_WinAPI_SelectObject($hCDC, $hBMP)
_WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, 0, 0, $__SCREENCAPTURECONSTANT_SRCCOPY)
_WinAPI_ReleaseDC($hWnd, $hDDC)
_WinAPI_DeleteDC($hCDC)

_ScreenCapture_SaveImage(@ScriptDir & "\Copy_Image.jpg", $hBMP, True)

 

Link to comment
Share on other sites

OK thanks again for those replies, I will give them a try out soon when I have the chance...and Slacker thanks for that link information for the documentation on that command...I was able to find it...should be useful.

Link to comment
Share on other sites

Greets again,

  I have tried both methods mentioned above...and they seem to work fine.  I am performing the 'screen-capture' within a loop, I add some text to an image and then capture it, and use that image as a source for the next.  The issue i'm having now is with the 'border' of the images...as can be seen in my screenshots, it is being successively included in each additional image that is captured...which I want to avoid.  However it seems I cannot change my GUI create parameters since a 'BORDER' is included within the 'CAPTION' option...

here is the 'first' method, using the "_WinAPI_GetSystemMetrics(31)" command:

;****CREATE THE GUI...

   $_CTRL_GUI = GUICreate("Positioning", 512, 512, -1, -1, BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU, $WS_EX_TOPMOST))
   GUISetBkColor(0xFFFFFF)  ;set GUI background to 'White'...

   GUISetState(@SW_SHOW, $_CTRL_GUI)

   ;****
   
   $_CONTROL_HWD = WinGetHandle($_CTRL_GUI)  ;save the handle to the Window...

...

    if WinExists($_CONTROL_HWD) Then

    $_WinPOS = WinGetPos($_CONTROL_HWD)

     if (IsArray($_WinPOS) == 1) AND (@error <> 1) Then
     
     $iTitleHeight = _WinAPI_GetSystemMetrics(31) + 1
     _ScreenCapture_CaptureWnd(@ScriptDir & "\Copy_Image.jpg", $_CTRL_GUI, 0, $iTitleHeight, Number($_WinPOS[2] - 1), Number($_WinPOS[3] - 1), False)
     
     EndIf  ;'$_WinPOS' IS an array...AND '@error' NOT "1"...
    EndIf  ;WinExists ($_CONTROL_HWD)...

Produces images like the first 3 images (where planet names 'Saturn' and 'Jupiter' appear)...where the border is inclusive of each successive image...

The second method, whereby the client area is captured is coded as such:

;****CREATE THE GUI...

   $_CTRL_GUI = GUICreate("Positioning", 512, 512, -1, -1, BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU, $WS_EX_TOPMOST))
   GUISetBkColor(0xFFFFFF)  ;set GUI background to 'White'...

   GUISetState(@SW_SHOW, $_CTRL_GUI)

   ;****
   
   $_CONTROL_HWD = WinGetHandle($_CTRL_GUI)  ;save the handle to the Window...

...

    if WinExists($_CONTROL_HWD) Then

    $_WinPOS = WinGetPos($_CONTROL_HWD)

     if (IsArray($_WinPOS) == 1) AND (@error <> 1) Then
     
     $iTitleHeight = _WinAPI_GetSystemMetrics(31) + 1
     $hDDC = _WinAPI_GetDC($_CTRL_GUI)
     $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
     $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, Number($_WinPOS[2] - 1), Number($_WinPOS[3] - 1) - $iTitleHeight)
     _WinAPI_SelectObject($hCDC, $hBMP)
     _WinAPI_BitBlt($hCDC, 0, 0, Number($_WinPOS[2] - 1), Number($_WinPOS[3] - 1) - $iTitleHeight, $hDDC, 0, 0,     $__SCREENCAPTURECONSTANT_SRCCOPY)
     _WinAPI_ReleaseDC($_CTRL_GUI, $hDDC)
     _WinAPI_DeleteDC($hCDC)

     _ScreenCapture_SaveImage(@ScriptDir & "\Copy_Image.jpg", $hBMP, True)

     EndIf  ;'$_WinPOS' IS an array...AND '@error' NOT "1"...
    EndIf  ;WinExists ($_CONTROL_HWD)...

Produces images like the 'second' 3 images (where 'Alabama' and 'Georgia' appear)...

Anybody have any ideas on how I can modify (either) of these code script snippets to eliminate the unwanted border in each...?  It seems using the 'first' method the entire border area is included in the successive image...while using the 'second' method the top left seems fine, and the problem occurs with the 'ending' bottom right area of the image...?   I thank you in advance.  Regards

 

 

 

Slot_Image0.jpg

Slot_Image0-1.jpg

Slot_Image0-1-2.jpg

Slot_Image0.jpg

Slot_Image0-1.jpg

Slot_Image0-1-2.jpg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...