abdulrahmanok

Screen Capture sometimes get blank webpage

16 posts in this topic

#1 ·  Posted (edited)

hi brothers, 

I'm trying to take screenshot from webpage and if found code that could take screenshot even when window is minimized but sometimes i get image like Image Attached I'm trying for 4 hours ago to know where is the problem ...

Notice: for some reason I'm need to run site minimized :)

 

ScreenShot CaptureTest.jpg

The Code:
 

;coded by UEZ 2012
#include <Array.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <IE.au3>
Opt("WinTitleMatchMode", 2)
    Local $oIE = _IECreate("https://mybanner.qu.edu.qa/PROD/twbkwbis.P_WWWLogin")
         opt('winwaitdelay', 0)  ;to make it run a little bit faster    
            WinWait("User Login")
                $handle = WinMove("User Login - Internet Explorer","",0,0,877, 516)
            WinSetState("User Login","",@SW_SHOWMINIMIZED)
        _IELoadWait($oIE)
        Sleep(2000)

WinSetState("User Login","",@SW_SHOWDEFAULT)

$aWinlist = GetAllWindow()
$handle = WinMove("Student Employment Time Attendance","",0,0,877, 516)
$MyWindow=WinGetHandle("[Class:IEFrame]")
ConsoleWrite($MyWindow)
For $i = 0 To UBound($aWinlist) - 1
    $hWnd = $aWinlist[$i][1]

    If Not WinActive($hWnd) Then ExitLoop
Next
If $i = UBound($aWinlist) Then Exit MsgBox(0, "Info", "No inactive window found", 10)

_GDIPlus_Startup()
$hBitmap = Capture_Window($MyWindow, 877, 516)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "Test.jpg")
_GDIPlus_BitmapDispose($hBitmap)
ShellExecute(@ScriptDir & "Test.jpg")
_GDIPlus_Shutdown()
Exit

Func Capture_Window($hWnd, $w, $h)
    Local $hDC_Capture = _WinAPI_GetWindowDC($hWnd)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
    Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $w, $h)
    Local $hObject = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    DllCall("user32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0)
    _WinAPI_DeleteDC($hMemDC)
;    Local $hObject = _WinAPI_SelectObject($hMemDC, $hObject)
    _WinAPI_ReleaseDC($hWnd, $hDC_Capture)
    Local $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
    _WinAPI_DeleteObject($hHBitmap)
    Return $hBmp
EndFunc   ;==>Capture_Window

Func GetAllWindow() ;code by Authenticity - modified by UEZ
    Local $aWin = WinList(), $aWindows[1][4]
    Local $iStyle, $iEx_Style, $iCounter = 0
    Local $i, $hWnd_state, $aWinPos

    For $i = 1 To $aWin[0][0]
        $iEx_Style = BitAND(_WinAPI_GetWindowLong($aWin[$i][1], $GWL_EXSTYLE), $WS_EX_TOOLWINDOW)
        $iStyle = BitAND(WinGetState($aWin[$i][1]), 2)
        If $iEx_Style <> -1 And Not $iEx_Style And $iStyle Then
            $aWinPos = WinGetPos($aWin[$i][1])
            If $aWinPos[2] > 1 And $aWinPos[3] > 1 Then
                $aWindows[$iCounter][0] = $aWin[$i][0]
                $aWindows[$iCounter][1] = $aWin[$i][1]
                $aWindows[$iCounter][2] = $aWinPos[2]
                $aWindows[$iCounter][3] = $aWinPos[3]
                $iCounter += 1
            EndIf
            ReDim $aWindows[$iCounter + 1][4]
        EndIf
    Next
    ReDim $aWindows[$iCounter][4]
    Return $aWindows
EndFunc   ;==>GetAllWindow

 

Edited by abdulrahmanok
Forgot to add code..

Share this post


Link to post
Share on other sites



#2 ·  Posted

any Idea?

Share this post


Link to post
Share on other sites

#3 ·  Posted

@abdulrahmanok you have been around long enough to know better than, and have in fact been warned about, bumping your posts without waiting 24 hours. This may be the most important thing in the world to you, but you need to show some patience.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#4 ·  Posted

What if you just tried using the built-in window capture UDF instead of an external function?

#include <ScreenCapture.au3>

_GDIPlus_Startup()
;$hBitmap = Capture_Window($MyWindow, 877, 516)
$hBitmap = _ScreenCapture_CaptureWnd(@ScriptDir & "\Test.jpg", $myWindow) ;<=======ADDED this line
;_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "Test.jpg")
_GDIPlus_BitmapDispose($hBitmap)
ShellExecute(@ScriptDir & "Test.jpg")
_GDIPlus_Shutdown()

If you want to tweak the bounds you can do so with extra parameters after the window handle.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#5 ·  Posted

4 hours ago, abdulrahmanok said:

_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "Test.jpg")

Looks like you are missing a slash (/) in that line.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted

Try this:

;coded by UEZ 2012
#include <Array.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <IE.au3>
Opt("WinTitleMatchMode", 2)
    Local $oIE = _IECreate("https://mybanner.qu.edu.qa/PROD/twbkwbis.P_WWWLogin")
         opt('winwaitdelay', 0)  ;to make it run a little bit faster
            WinWait("User Login")
                $handle = WinMove("User Login - Internet Explorer","",0,0,877, 516)
            WinSetState("User Login","",@SW_SHOWMINIMIZED)
        _IELoadWait($oIE)
        Sleep(2000)

WinSetState("User Login","",@SW_SHOWDEFAULT)

$aWinlist = GetAllWindow()
$handle = WinMove("Student Employment Time Attendance","",0,0,877, 516)
$MyWindow=WinGetHandle("[Class:IEFrame]")
ConsoleWrite($MyWindow)
For $i = 0 To UBound($aWinlist) - 1
    $hWnd = $aWinlist[$i][1]
    If Not WinActive($hWnd) Then ExitLoop
Next
If $i = UBound($aWinlist) Then Exit MsgBox(0, "Info", "No inactive window found", 10)
Sleep(1000)
_GDIPlus_Startup()
$hBitmap = Capture_Window($MyWindow, 877, 516)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Test.jpg")
_GDIPlus_BitmapDispose($hBitmap)
ShellExecute(@ScriptDir & "\Test.jpg")
_GDIPlus_Shutdown()
Exit

Func Capture_Window($hWnd, $w, $h)
    Local $hDC_Capture = _WinAPI_GetWindowDC($hWnd)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
    Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $w, $h)
    Local $hObject = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    DllCall("user32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0)
    _WinAPI_DeleteDC($hMemDC)
;    Local $hObject = _WinAPI_SelectObject($hMemDC, $hObject)
    _WinAPI_ReleaseDC($hWnd, $hDC_Capture)
    Local $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
    _WinAPI_DeleteObject($hHBitmap)
    Return $hBmp
EndFunc   ;==>Capture_Window

Func GetAllWindow() ;code by Authenticity - modified by UEZ
    Local $aWin = WinList(), $aWindows[1][4]
    Local $iStyle, $iEx_Style, $iCounter = 0
    Local $i, $hWnd_state, $aWinPos

    For $i = 1 To $aWin[0][0]
        $iEx_Style = BitAND(_WinAPI_GetWindowLong($aWin[$i][1], $GWL_EXSTYLE), $WS_EX_TOOLWINDOW)
        $iStyle = BitAND(WinGetState($aWin[$i][1]), 2)
        If $iEx_Style <> -1 And Not $iEx_Style And $iStyle Then
            $aWinPos = WinGetPos($aWin[$i][1])
            If $aWinPos[2] > 1 And $aWinPos[3] > 1 Then
                $aWindows[$iCounter][0] = $aWin[$i][0]
                $aWindows[$iCounter][1] = $aWin[$i][1]
                $aWindows[$iCounter][2] = $aWinPos[2]
                $aWindows[$iCounter][3] = $aWinPos[3]
                $iCounter += 1
            EndIf
            ReDim $aWindows[$iCounter + 1][4]
        EndIf
    Next
    ReDim $aWindows[$iCounter][4]
    Return $aWindows
EndFunc   ;==>GetAllWindow

 


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

#7 ·  Posted

sorry I have tried all same Issue :(

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

1 hour ago, Jos said:

Looks like you are missing a slash (/) in that line.

Jos

slash should be (/) Or (\) ?

@UEZ

did you changed only slash which @Jos mentioned?

Edited by abdulrahmanok

Share this post


Link to post
Share on other sites

#9 ·  Posted

I added 2x "\" and additionally a Sleep(1000) line.

 

Does it work now for you?


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

#10 ·  Posted

unfortunately no , sometimes get the true screen and sometimes capture blank image

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

false assumption

Edited by abdulrahmanok

Share this post


Link to post
Share on other sites

#12 ·  Posted

Is there is any alternate way to screenshot selective window?

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I assume you can do a save as html/pdf with IE.AU3 library. So print to a file
https://msdn.microsoft.com/en-us/library/ms970457.aspx

$oIE.ExecWB did do this in the past not used it for a long time (google is your friend)

https://win32com.goermezer.de/microsoft/internet-explorer/printing-webpages-from-internet-explorer-with-python.html

  • dont make it minimized just make it 1 * 1 pixel or 10 * 10 and move it behind your startbar
Edited by junkew
dont make it minimized just make it 1 * 1 pixel or 10 * 10

Share this post


Link to post
Share on other sites

#14 ·  Posted

Try Ward's nice piece of code:

 


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

#15 ·  Posted

Thanks for your reply but I have no experiance with c++ codes and I couldn't find  $oIE.ExecWB Autoit code expamles  (after google it)
whatever I searched also about "autoit save page as pdf" but most of codes doesn't work or it doesn't do what is want.

Share this post


Link to post
Share on other sites

#16 ·  Posted

@UEZ Thank you for mention to this great way but unfortunately after many tries I known that this way can run by load ULR in separate GUI and then capture it  and in my case it will fails to get page when I use site need to login for example capture some pages after already login to my college page or take screen shot of Autoit account details page.

Result of current captured page:
 

Test1.png

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

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I would like to know if I can use the Excel UDF to manipulating a .csv file without having Office installed on the PC I'm going to work...
      I read somewhere that it could be done, but I'm here to ask and be sure of what I remember... 
      I'd like to post another question...
      How can I retrieve the handle of a windows from a PID of an .exe?
      I have my script that does a ShellExecute ( which returns the PID of the .exe ), and then, switching a parameter read from a .ini file, adapt the Window on the screen ( Maximize, Minimize, On Top )...
      I tried, but without having success with this:
       
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=prova.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <WinAPIEx.au3> #include <Array.au3> Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini" If(FileExists($sFileConfigurazione)) Then Local $aSezioniIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE") If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error) Else ; Lancio dell'applicativo indicato nel file di configurazione Local $iPID = ShellExecute($aSezioniIni[1][1]) Local $hWnd If($iPID <> 0) Then Local $aWinList = WinList() For $i = 1 To $aWinList[0][0] If(WinGetProcess($aWinList[$i][1] = $iPID)) Then $hWnd = $aWinList[$i][1] EndIf Next Switch($aSezioniIni[2][1]) Case $aSezioniIni[2][1] = "MIN" WinSetState($hWnd, "", @SW_MINIMIZE) Case $aSezioniIni[2][1] = "MAX" WinSetState($hWnd, "", @SW_MAXIMIZE) Case $aSezioniIni[2][1] = "TOP" WinSetOnTop($hWnd, "", $WINDOWS_ONTOP) EndSwitch EndIf EndIf EndIf It just set on top the .exe I'm launching...
      Thanks
    • computergroove
      By computergroove
      #include <IE.au3> _IECreate("www.google.com") Sleep(5000) WinSetState("Google - Internet Explorer","",@SW_MAXIMIZE) The browser window opens and it goes to google.com but it will not maximize. I have also tried:
      #include <IE.au3> Local $Browser = _IECreate("www.google.com") Sleep(5000) WinSetState($Browser,"",@SW_MAXIMIZE) Also doesn't work. I'm running windows 8.1 x64 and internet explorer 11.0.9600.16384. Help!
    • badapple89
      By badapple89
      Hi guys,
      I have a program that when minimised to task-bar an using WinGetState returns 37. Maximised, enabled and exists?
      Using WinSetState ("[CLASS:TfrmDesktop]", "", @SW_MAXIMIZE) returns 39. Maximised, enabled and exists and visible?
      But will not maximise the window.
      However 39 is what it normally is  when maximised and using the program
      Just using @SW_RESTORE = 7 but does not open window (obviously)
      and using @SW_RESTORE then  @SW_MAXIMIZE = 39 but then cant minimize.
      and using @SW_RESTORE then  @SW_MAXIMIZE then @SW_ENABLE = 39 but then cant minimize.
      Tried this and nothing WinMove("[CLASS:TfrmDesktop]",0,0,@Desktopwidth, @DesktopHeight)
      Really strange as not sure what else to try.
      Thanks guys
    • LarsBNygaard
      By LarsBNygaard
      I've written a little experimental program, using 2 shortcuts, to manage a relay.
      The shortcuts are:
      C:\USB-relæ\USBRelay\USBRelay.exe -c:8 -r:1#1 ( = 'ON')
      C:\USB-relæ\USBRelay\USBRelay.exe -c:8 -r:1#0 ( = 'OFF')

      The script (the compiled .exe) is doing what it is supposed to do, using the

      Run ("C:\USB-relæ\USBRelay\USBRelay.exe -c:8 -r:1#1") to turn the relay on - but I keep getting a window, which I cannot "get a grip on", almost all over my monitor, which I find absolutely annoying..!


      What can I do, in order to force this window to "disappear"..?

      Any help will be greatly appreciated!