Sign in to follow this  
Followers 0
qwert

_ScreenCapture_CaptureWnd adds border to maximized window

9 posts in this topic

I've encountered a problem that only affects maximized windows.  When they're captured with _ScreenCapture_CaptureWnd, it adds what looks to be a 6-pixel black border.  When the same window is sized large, but not maximized, _CaptureWnd works just fine.

For reference, _ScreenCapture_Capture has no problem capturing the entire screen when occupied by that same window.

I can't spot any setting for this sort of thing.

Is it a feature?  A bug?  And is there a setting or something easily changeable in the UDF to eliminate it?

Thanks in advance for any help.

post-29172-0-11201100-1426108087_thumb.p

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I don't know why, when GUI is maximized, the x/y pos is shifted each by -8 pixels.

Can you test this function please and when possible with enabled / disabled aero?

 

Func _ScreenCapture_CaptureWnd_($sFileName, $hWnd, $bCursor = True)
    If Not IsHWnd($hWnd) Then $hWnd = WinGetHandle($hWnd)
    Switch BitAND(WinGetState($hWnd), BitXOR(16, BitOR(2, 32)))
        Case 34 ;Window is maximized and visible
            Local $aSize = WinGetClientSize($hWnd)
            Local $tPointC2S = DllStructCreate("int X;int Y"), $tPointS2C = DllStructCreate("int X;int Y")
            _WinAPI_ClientToScreen($hWnd, $tPointC2S)
            _WinAPI_ScreenToClient($hWnd, $tPointS2C)
            Local $iX = $tPointC2S.X + $tPointS2C.X, $iY = $tPointC2S.Y + $tPointS2C.Y
            Return _ScreenCapture_Capture($sFileName, $iX, $iY, $iX + $aSize[0] + $tPointC2S.X - 1, $iY + $aSize[1] + $tPointC2S.Y - 1, $bCursor)
        Case 2 ;Window is visible and not minimized
            Local $aPos = WinGetPos($hWnd)
            Return _ScreenCapture_Capture($sFileName, $aPos[0], $aPos[1], $aPos[0] + $aPos[2] - 1, $aPos[1] + $aPos[3] - 1, $bCursor)
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
EndFunc   ;==>_ScreenCapture_CaptureWnd_
Thanks. Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

UEZ, thanks for your response.

It seems to work properly for both maximized windows and normal (less-than-full-size) windows.  If I follow what you've done, it's a simplification by having _ScreenCapture_Capture do the work and controlling it with parameters.

I'm not in position to test with Aero at the moment.

 

I do have a somewhat related question: upon obtaining the bitmap from the capture, I need to display it for a couple of seconds

... and then change it to 50% transparency.  The sequence I'm use to display the capture is:

$hBitmap = _ScreenCapture_CaptureWnd()

$hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($GUI)

_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, $xPos, $yPos)

Sleep(2000)

Do you have a suggestion for what statement(s) can I add after the sleep to change the transparency?  (not of the GUI, itself ... just the captured image)

Edited by qwert

Share this post


Link to post
Share on other sites

I've tested the function in my office using 3 monitors and the conclusion is that it doesn't work properly. Also the same return values of 8 pixels.

Best is to add 8 pixels for x/y and substract 8 pixels for w/h.

Regarding transparency of the image. You have to use

_GDIPlus_ImageAttributesCreate()
_GDIPlus_ColorMatrixCreateTranslate()
_GDIPlus_ImageAttributesSetColorMatrix()
_GDIPlus_GraphicsDrawImageRectRect()

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Checking stackoverflow.com and other sites, it does seem like window borders are a problem in cases like this.

However, UEZ, I'm confused by your conclusion.  Which _ScreenCapture are you talking about?  And are you only talking about Aero?

I've double checked my results and the function in your OP gives me good results under Win 7 Pro non-Aero Mode.  I get a full-screen image with no border.  Saved as a PNG, it is exactly the dimensions of the screen.

Can you clarify this?  Did your OP method fail in your test?  Or was the failure with the 3.3.12.0 UDF?

 

(And thanks for the method on transparency.  I'm beginning to see how some of these GDI+ operations work together.)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Checking stackoverflow.com and other sites, it does seem like window borders are a problem in cases like this.

However, UEZ, I'm confused by your conclusion.  Which _ScreenCapture are you talking about?  And are you only talking about Aero?

I've double checked my results and the function in your OP gives me good results under Win 7 Pro non-Aero Mode.  I get a full-screen image with no border.  Saved as a PNG, it is exactly the dimensions of the screen.

Can you clarify this?  Did your OP method fail in your test?  Or was the failure with the 3.3.12.0 UDF?

 

(And thanks for the method on transparency.  I'm beginning to see how some of these GDI+ operations work together.)

 

I'm talking about the code I posted in post #2. If you have connected multiple monitors then the screen resolution will be the sum of all monitors (max. values).

E.g. my monitor config.

 

_____1680_____ ____1680______

|                           |                           | ____1600_____

| 1050       2         |1050       3          |                          |

|                           |                           |              1          |900

__________________________________________

Monitor 2 and 3 have the same dimension (1680x1050) and the primary has (1600x900). The overall screen resolution is 4960x1050.

E.g. when the GUI is on monitor 2 or 3 then the code from post #2 doesn't work.When checking the returned values from _WinAPI_ClientToScreen and _WinAPI_ScreenToClient show the difference of 158 instead of 150. 1050 - 900 = 150. On one monitor the difference is 0 and thus works properly.

I hope I could explain the problem a little bit.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

... when the GUI is on monitor 2 or 3 then the code from post #2 doesn't work ...

... on one monitor the difference is 0 and thus works properly.

UEZ, that helps a lot.  (and, yes, I meant post #2, not my OP)  Your last statement explains what I'm seeing.

I haven't had to address problems with multiple monitors ... not yet.  In fact, I haven't considered what "full screen" will mean to my application in a configuration like yours.  But looking ahead, is there a simple test for total screen width?  Does @DesktopWidth return 4960 for you?

Thanks for all the help.

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@DesktopWidth returns the value from the primary monitor only -> 1600 for me.

 

 

I'm using WinGetPos() and WinGetHandle() to get the full screen size:

Global $aFullScreenSize = WinGetPos(WinGetHandle("[TITLE:Program Manager;CLASS:Progman]"))
ConsoleWrite("Width: " & $aFullScreenSize[2] & ", height: " & $aFullScreenSize[3] & @CRLF)
Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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
Sign in to follow this  
Followers 0