heavenm 发表于 2014-5-12 04:53:35

后台截图,部分界面会卡住是什么原因

本帖最后由 heavenm 于 2014-5-12 04:54 编辑

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>

$CMB_HWND = WinGetHandle('');获取主窗口句柄

_Windows_Capture($CMB_HWND, -1, -1)
Func _Windows_Capture($hWnd, $iWidth = -1, $iHeight = -1)
        Local $hDestDC, $hBmp, $hSrcDC
        If $iWidth = -1 Then $iWidth = _WinAPI_GetWindowWidth($hWnd)
        If $iHeight = -1 Then $iHeight = _WinAPI_GetWindowHeight($hWnd)
        $hDC = _WinAPI_GetWindowDC($hWnd);创建一个DC句柄
        $hDestDC = _WinAPI_CreateCompatibleDC($hDC);从DC句柄创建一个宽高为调用值的位图句柄
        $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight);从DC句柄创建一个宽高为调用值的位图句柄
        $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap);将位图句柄复制到内存区域中去
        ;$hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
        _WinAPI_SelectObject($hSrcDC, $hBitmap)
        _WinAPI_PrintWindow($hWnd, $hDestDC)
        ;_WinAPI_BitBlt($hDestDC, 0, 0, $iWidth, $iHeight, $hSrcDC, 0, 0, $MERGECOPY)

        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
        $hClone = _GDIPlus_BitmapCloneArea($hImage, 100, 100, 100, 100,$GDIP_PXF24RGB)
        _GDIPlus_ImageSaveToFile($hClone, @DesktopDir & "\window2.bmp")

        _WinAPI_ReleaseDC($hWnd, $hDC)
        _WinAPI_DeleteDC($hDC)
        _WinAPI_DeleteDC($hDestDC)
        _WinAPI_DeleteObject($hBitmap)
        Return $hBitmap
EndFunc   ;==>_Windows_Capture
估计很多人没有招商的专业版比较难测试
也只有部分界面会卡住,要再次运行这个脚本才会显示新的内容,不理解为什么

heavenm 发表于 2014-5-12 04:58:14

_WinAPI_PrintWindow($CMB_HWND, '')
要执行这句才会显示最新的窗口,,,,,这是为什么??

heavenm 发表于 2014-5-12 05:36:51

http://www.fengyuan.com/article/wmprint.html
找到这篇文章,不过看不懂,有高手看看么

heavenm 发表于 2014-5-15 00:25:26

#include <APIConstants.au3>
#include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $STM_SETIMAGE = 0x0172
Global Const $STM_GETIMAGE = 0x0173

Global $hWnd, $hForm, $Pic, $hPic, $Size, $hObj, $hBmp, $hBitmap, $hDC, $hDestDC, $hDestSv, $hSrcDC, $hSrcSv


$hWnd = WinGetHandle('');获取主窗口句柄
If Not $hWnd Then
        Exit
EndIf

; 创建 GUI
$Size = WinGetPos($hWnd)
$hForm = GUICreate('MyGUI', $Size - 80, $Size - 80)
$Pic = GUICtrlCreatePic('', 40, 40, $Size, $Size)
$hPic = GUICtrlGetHandle($Pic)

; 创建位图
$hDC = _WinAPI_GetDC($hPic)
$hDestDC = _WinAPI_CreateCompatibleDC($hDC)
$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $Size, $Size)
$hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
$hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
$hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Size, $Size)
$hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp)
;_WinAPI_PrintWindow($hWnd, $hSrcDC)
_WinAPI_BitBlt($hDestDC, 0, 0, $Size, $Size, $hSrcDC, 0, 0, $MERGECOPY)


_WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0)
_WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_ERASE)
_WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
_WinAPI_RedrawWindow($hDC, 0, 0,$RDW_NOINTERNALPAINT)
_WinAPI_RedrawWindow($hDC, 0, 0, $RDW_ERASE)
_WinAPI_RedrawWindow($hDC, 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
_WinAPI_RedrawWindow($hDC, 0, $RDW_FRAME )

_SendMessage($hWnd, 'WM_PRINT', $hSrcDC, 'PRF_CLIENT|PRF_ERASEBKGND|PRF_NONCLIENT|PRF_CHILDREN')
_WinAPI_ReleaseDC($hPic, $hDC)
_WinAPI_SelectObject($hDestDC, $hDestSv)
_WinAPI_SelectObject($hSrcDC, $hSrcSv)
_WinAPI_DeleteDC($hDestDC)
_WinAPI_DeleteDC($hSrcDC)
_WinAPI_DeleteObject($hBmp)

_WinAPI_UpdateWindow($hSrcDC)
_WinAPI_UpdateWindow($hWnd)

; 设置位图到控件
_SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
$hObj = _SendMessage($hPic, $STM_GETIMAGE)
If $hObj <> $hBitmap Then
        _WinAPI_DeleteObject($hBitmap)
EndIf

GUISetState()

Do
Until GUIGetMsg() = -3
找了NN多资料还是没解决 有高人帮忙下么
页: [1]
查看完整版本: 后台截图,部分界面会卡住是什么原因