找回密码
 加入
搜索
查看: 4034|回复: 3

[AU3基础] 后台截图,部分界面会卡住是什么原因

[复制链接]
发表于 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('[TITLE:个人银行专业版;CLASS:TMainFrm]');获取主窗口句柄

_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
估计很多人没有招商的专业版比较难测试
也只有部分界面会卡住,要再次运行这个脚本才会显示新的内容,不理解为什么
 楼主| 发表于 2014-5-12 04:58:14 | 显示全部楼层
_WinAPI_PrintWindow($CMB_HWND, '')
要执行这句才会显示最新的窗口,,,,,这是为什么??
 楼主| 发表于 2014-5-12 05:36:51 | 显示全部楼层
http://www.fengyuan.com/article/wmprint.html
找到这篇文章,不过看不懂,有高手看看么
 楼主| 发表于 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('[TITLE:个人银行专业版;CLASS:TMainFrm]');获取主窗口句柄
If Not $hWnd Then
        Exit
EndIf

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

; 创建位图
$hDC = _WinAPI_GetDC($hPic)
$hDestDC = _WinAPI_CreateCompatibleDC($hDC)
$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $Size[2], $Size[3])
$hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
$hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
$hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Size[2], $Size[3])
$hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp)
;_WinAPI_PrintWindow($hWnd, $hSrcDC)
_WinAPI_BitBlt($hDestDC, 0, 0, $Size[2], $Size[3], $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多资料还是没解决 有高人帮忙下么
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-23 21:03 , Processed in 0.114213 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表