Jump to content
Sign in to follow this  

_WinAPI_GetDC error?

Recommended Posts

Hello, hope someone can help. This is the situation on windows7 64bit:

I have a gui:

$wsoIE = ObjCreate("Shell.Explorer.2")
$wshGUI = GUICreate("",  $Width,  $Height)
$wsGUIActiveX = GUICtrlCreateObj ($wsoIE, 0, 0, $Width,  $Height + 50)

now i navigate to a url, and move the complete gui outside of the desktop-coordinates.

with active aero-style i can now perform "_WinAPI_GetDC" and save it as a picturefile.

when aero is disabled and windows-basic style active, then i get only a black image.

is there a way to fix this?

thank you.

@ UEZ: Vielleicht findet ja hier jemand eine lösung :)

transl.: mabye someone here has a solution.

Share this post

Link to post
Share on other sites

Here some more background information: the idea was to make screenshots from web site using a GUI with embedded IE engine whereas the GUI shouldn't be visible.

First step is to render the web site and get the height of the created window.

Second step is to create a GUI with fixed width and rendered height from step 1 whereas the GUI is only visible by 1 pixel otherwise _WinAPI_GetWindowDC($hGUI) will create only a black screen.

When Aero is enabled you can get the content of the GUI and take a screenshot. When Aero is disabled you see only a black screen.

Here the code:

#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)

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.autoitscript.com/forum/", 10, 5, 300, 20)
$btn = GUICtrlCreateButton("Ok", 40, 35, 240, 70)
ControlFocus($hWnd, "", $btn)
While $msg <> -3
    $msg = GUIGetMsg()
        Case $msg = $btn
        Case $msg = -3

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)
    MsgBox(0, "Information", "Web Site Image copied to clipboard!", 10)

Func Web_Screenshot($url)
    Local $oIE, $GUIActiveX, $oDocument,  $oBody, $BodyWidth, $BodyHeight
    Local $hGUI, $hWin, $aWin
    $oIE = ObjCreate("Shell.Explorer.2")

    #region render web site to get height
    $hGUI = GUICreate("",  1, 1, -1, -1, $WS_POPUP)
    $GUIActiveX = GUICtrlCreateObj ($oIE, 0, 0, 1024, 256)
    With $oIE
        .Silent = True
        .TheaterMode = False
        .FullScreen = True
        .Resizable = False
        While .ReadyState <> 4

    $oDocument = $oIE.document
    $oBody = $odocument.body
    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $BodyWidth = $oBody.scrollWidth
    $BodyHeight = $oBody.scrollHeight


    $GUIActiveX = 0
    $hGUI = GUICreate("",  $BodyWidth,  $BodyHeight, -1, 0, BitOR($WS_CLIPCHILDREN, $WS_POPUP), Default, WinGetHandle(AutoItWinGetTitle()))
    $GUIActiveX = GUICtrlCreateObj ($oIE, 0, 0, $BodyWidth,  $BodyHeight + 50)

    With $oIE
         .Silent = True
        .TheaterMode = False
        .FullScreen = True
        .Resizable = False
        While .ReadyState <> 4

    $oDocument = $oIE.document
    $oBody =$odocument.body
    $oHtml = $odocument.documentElement
    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $oHtml.style.overflow = 'hidden'

    $hWin = WinGetHandle("Program Manager")
    $aWin = WinGetPos($hWin)
    WinMove($hGUI, "", $aWin[0] - $BodyWidth + 1, $aWin[1] - $BodyHeight + 1) ;hide window
    GUISetState(@SW_SHOWNA)       ;Show GUI

    Local $hDC = _WinAPI_GetWindowDC($hGUI)
    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_ReleaseDC($hGUI, $hDC)
    _WinAPI_ReleaseDC(0, $hDC_Dummy)
    _WinAPI_ReleaseDC(0, $hDC)

    _ClipBoard_SetDataEx($hBitmap, $CF_BITMAP)
    _WinAPI_DeleteObject ($hBitmap)
    $GUIActiveX = 0
    $oIE = 0

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 ...")
    $i += 1

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]
    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]



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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...