本帖最后由 gto250 于 2011-3-30 22:20 编辑
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
Opt("GUIOnEventMode", 1)
_GDIPlus_Startup()
Dim $p_x = 5
Dim $p_y = 5
Dim $p_w = 180
Dim $p_h = 220
Dim $c_w = 80
Dim $c_h = 100
Dim $k = 0
$hGUI = GUICreate("Form1", 600, 400, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\dd.jpg", $p_x, $p_y, $p_w, $p_h, BitOR($SS_NOTIFY, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUISetState()
$hChild = GUICreate("Form2", 80, 100, ($p_w - $c_w) / 2 + 5, ($p_h - $c_h) / 2 + 5, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUICtrlCreateLabel("", 0, 0, 100, 100, -1, $GUI_WS_EX_PARENTDRAG)
GUISetBkColor(0x0054E3)
GUIRegisterMsg(0x0203, "_SaveCapture")
GUIRegisterMsg(0x0003, "MY_WM_MOVEING")
WinSetTrans($hChild, "", 100)
GUISetState()
While 1
Sleep(1000)
WEnd
Func _SaveCapture($hWnd, $iMsg, $iwParam, $ilParam)
If $hWnd = WinGetHandle($hChild) Then
_ScreenCapture_CaptureWnd(@ScriptDir & "\020202.jpg", $hChild)
EndIf
EndFunc ;==>_SaveCapture
Func MY_WM_MOVEING($hWnd, $Msg, $wParam, $lParam)
If $hWnd = WinGetHandle($hChild) Then
$GUI_xy = WinGetPos($hGUI)
$Child_xy = WinGetPos($hChild)
$GUI_m_xy = GUIGetCursorInfo($hGUI)
$Child_m_xy = GUIGetCursorInfo($hChild)
$iLeft = $GUI_xy[0] + $p_x + 5
$iTop = $GUI_xy[1] + $p_y + 32
$iRight = $GUI_xy[0] + $p_w + $p_x + 1
$iBottom = $GUI_xy[1] + $p_h + $p_y + 26
If $Child_xy[0] < $iLeft Then
_WinAPI_Mouse_Event(0x0004)
WinMove($hWnd, "", $iLeft + 1, Default, Default, Default, 1)
;_WinAPI_Mouse_Event(0x0002)
EndIf
If $Child_xy[1] < $iTop Then
_WinAPI_Mouse_Event(0x0004)
WinMove($hWnd, "", Default, $iTop + 1, Default, Default, 1)
;_WinAPI_Mouse_Event(0x0002)
EndIf
If $Child_xy[0] + $c_w > $iRight Then
_WinAPI_Mouse_Event(0x0004)
WinMove($hWnd, "", $iRight - $c_w - 1, Default, Default, Default, 1)
; _WinAPI_Mouse_Event(0x0002)
EndIf
If $Child_xy[1] + $c_h > $iBottom Then
_WinAPI_Mouse_Event(0x0004)
WinMove($hWnd, "", Default, $iBottom - $c_h - 1, Default, Default, 1)
; _WinAPI_Mouse_Event(0x0002)
EndIf
EndIf
EndFunc ;==>MY_WM_MOVEING
Func close()
Exit
EndFunc ;==>close
上面的代码我要实现的功能是,左键双击淡蓝色的框,就在当前目录下生成一张截图,但是不知道什么原因,这个代码不成功!
帮忙看下。我自己检查的结果就是Func _SaveCapture($hWnd, $iMsg, $iwParam, $ilParam)根本就获取不到$hWnd=$hChild
图片的话,大家可以选择任意的图片。只要改名为dd.jpg放在脚本目录下即可
|