Ich will AutoIt Windows Screenshooter mit einer Web Screenshot Funktion erweitern,
bin eigentlich mit der IE Objektprogrammierung fast überhaupt nicht vertraut.
Es gibt zwar ein klasse Proggy (Web Screenshot), aber ich kenne mich überhaupt nicht
mit AutoItObject aus.
Also habe ich versucht, was eigenes auf die Beine zu stellen:
Spoiler anzeigen
#include <Clipboard.au3>
#include <IE.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;Coded by UEZ 2011 - beta version
If @OSBuild < 6000 Then Exit MsgBox(16, "Error!", "Script is running properly only on Vista+ os!", 10)
[/autoit] [autoit][/autoit] [autoit]Global Const $hDwmApiDll = DllOpen("dwmapi.dll")
Global $sChkAero = DllStructCreate("int;")
DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero))
Global $aero = DllStructGetData($sChkAero, 1)
If Not $aero Then Exit MsgBox(16, "Error", "Aero must be enabled to grab web sites properly!", 20)
$sChkAero = 0
Global $URL, $btn, $msg, $hWnd, $input, $i
$hWnd = GUICreate("Save Web Page as an image", 320, 120)
$input = GUICtrlCreateInput("http://www.stern.de", 10, 5, 300, 20)
$btn = GUICtrlCreateButton("Ok", 40, 35, 240, 70)
ControlFocus($hWnd, "", $btn)
GUISetState()
While $msg <> -3
$msg = GUIGetMsg()
Select
Case $msg = $btn
Start()
Case $msg = -3
GUIDelete($hWnd)
Exit
EndSelect
WEnd
Func Start()
$URL = GUICtrlRead($input)
SplashTextOn("Screenshooting Web Site", "Please wait while taking screenshot", 300, 40, -1, -1, 1 + 2 + 4 + 32, "")
AdlibRegister("Wait", 300)
Web_Screenshot($URL)
AdlibUnRegister("Wait")
SplashOff()
MsgBox(0, "Information", "Web Site Image copied to clipboard!", 10)
EndFunc
Func Web_Screenshot($url, $IEwidth = 1045)
Local $oIE, $GUIActiveX, $oDocument, $oBody, $BodyWidth, $BodyHeight, $oHtml
Local $hGUI_WebGrab, $hWin, $aWin, $aMP
Local Const $BrowserNavConstant = 2 + 256 + 2048 ;BrowserNavConstant -> http://msdn.microsoft.com/en-us/library/…8(v=vs.85).aspx
$oIE = ObjCreate("Shell.Explorer.2") ;http://msdn.microsoft.com/en-us/library/…4(v=vs.85).aspx
$hWin = WinGetHandle("Program Manager")
$aWin = WinGetPos($hWin)
#region render web site to get height
$hGUI_WebGrab = GUICreate("", 0, 0, $aWin[0] - $BodyWidth + 1, $aWin[1] - $BodyHeight + 1, BitOR($WS_CLIPSIBLINGS, $WS_CLIPCHILDREN, $WS_POPUP),Default, WinGetHandle(AutoItWinGetTitle()))
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, $IEwidth, 256)
GUISetState(@SW_MINIMIZE, $hGUI_WebGrab)
Local $timeout = 30 * 1000
Local $timer = TimerInit()
With $oIE
.Silent = True
.FullScreen = True
.Resizable = False
.Visible = False
.StatusBar = False
.AddressBar = False
.Navigate($URL, $BrowserNavConstant, "_top")
Do
If TimerDiff($timer) > $timeout Then ExitLoop
Sleep(100)
Until $oIE.ReadyState = 4
.Stop
Sleep(2000)
EndWith
$oDocument = $oIE.document
$oBody = $oDocument.body
$oBody.scroll = "no"
$oBody.style.borderStyle = "none"
$BodyWidth = $oBody.scrollWidth
$BodyHeight = $oBody.scrollHeight
GUIDelete($hGUI_WebGrab)
$GUIActiveX = 0
#endregion
$hGUI_WebGrab = GUICreate("", $BodyWidth, $BodyHeight, $aWin[0] - $BodyWidth + 1, $aWin[1] - $BodyHeight + 1, BitOR($WS_CLIPSIBLINGS, $WS_CLIPCHILDREN, $WS_POPUP), Default, WinGetHandle(AutoItWinGetTitle()))
;~ $hGUI_WebGrab = GUICreate("", $BodyWidth, $BodyHeight, -1, -1, BitOR($WS_CLIPSIBLINGS, $WS_CLIPCHILDREN, $WS_POPUP), Default, WinGetHandle(AutoItWinGetTitle()))
$GUIActiveX = GUICtrlCreateObj ($oIE, 0, 0, $BodyWidth, Min($BodyHeight, 8192))
;~ GUISetState(@SW_SHOWNA, $hGUI_WebGrab) ;Show GUI for some milli seconds to make a screenshot
$timer = TimerInit()
With $oIE
.Silent = True
.FullScreen = True
.Resizable = False
.Visible = False
.StatusBar = False
.AddressBar = False
.Navigate($URL, $BrowserNavConstant, "_top")
Do
If TimerDiff($timer) > $timeout Then ExitLoop
Sleep(100)
Until $oIE.ReadyState = 4
.Stop
Sleep(1000)
EndWith
$oDocument = $oIE.document
$oBody =$oDocument.body
$oHtml = $oDocument.documentElement
$oBody.scroll = "no"
$oBody.style.borderStyle = "none"
$oBody.style.border = "0px"
$oHtml.style.overflow = 'hidden'
GUISetState(@SW_SHOWNA, $hGUI_WebGrab) ;Show GUI
[/autoit] [autoit][/autoit] [autoit]Local $hDC = _WinAPI_GetWindowDC($hGUI_WebGrab)
Local $hDC_Dummy = _WinAPI_GetWindowDC(0)
Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Dummy)
Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Dummy, $BodyWidth, $BodyHeight)
_WinAPI_SelectObject($hMemDC, $hBitmap)
_WinAPI_BitBlt($hMemDC, 0, 0, $BodyWidth, $BodyHeight, $hDC, 0, 0, $SRCCOPY)
_WinAPI_DeleteDC($hMemDC)
_WinAPI_ReleaseDC($hGUI_WebGrab, $hDC)
_WinAPI_ReleaseDC(0, $hDC_Dummy)
_WinAPI_ReleaseDC(0, $hDC)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_ClipBoard_SetDataEx($hBitmap, $CF_BITMAP)
_ClipBoard_Close()
_WinAPI_DeleteObject ($hBitmap)
$GUIActiveX = 0
$oIE = 0
GUIDelete($hGUI_WebGrab)
_ReduceMemory()
EndFunc
Func Min($a, $b)
If $a < $b Then Return $a
Return $b
EndFunc
Func Wait()
Switch Mod($i, 4)
Case 0
ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot")
Case 1
ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot .")
Case 2
ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot ..")
Case 3
ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot ...")
EndSwitch
$i += 1
EndFunc
Func _ReduceMemory($ProcID = 0)
If $ProcID = 0 or ProcessExists($ProcID) = 0 Then ; No process id specified or process doesn't exist - use current process instead.
Local $ai_GetCurrentProcess = DllCall('kernel32.dll', 'ptr', 'GetCurrentProcess')
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'ptr', $ai_GetCurrentProcess[0])
Return $ai_Return[0]
EndIf
Local $ai_Handle = DllCall("kernel32.dll", 'ptr', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $ProcID)
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'ptr', $ai_Handle[0])
DllCall('kernel32.dll', 'int', 'CloseHandle', 'ptr', $ai_Handle[0])
Return $ai_Return[0]
EndFunc
Ich habe zwei Probleme hier:Wie kann ich eine IE Seite rendern und diese abspeichern, ohne eine GUI anzuzeigen?Wie bekomme ich den vertikalen Balken auf der rechten Seite weg (einfach den Screenshot vom Clipboard in irgendein Tool einfügen)?
Ideen?
Der Code ist noch im Alpha Status und kann oder hat sehr wahrscheinlich schwachsinnigen Code! Jetzt im ßeta Stadium.
Gruß,
UEZ
Edit: scheint mit WinXP nicht zu laufen, da es kein Aero gibt, welches nötig ist, von Fenstern einen Screenshot zu erstellen, das sich außerhalb des sichtbaren Desktops befindet.!