#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinApi.au3>
#Include <GDIPlusEx.au3>
#Include <ScreenCapture.au3>
#Region ### START Koda GUI section ### Form=
HotKeySet("{F1}","pic")
$Form1 = GUICreate("Form1", 500, 470, 500, 500)
$Pic1 = GUICtrlCreatePic("", 0, 0, 498, 448)
$Button1 = GUICtrlCreateButton("Button1", 205, 450, 75, 20)
$Button2 = GUICtrlCreateButton("Button2", 290, 450, 75, 20)
$Button2 = GUICtrlCreateButton("Button2", 290, 450, 75, 20)
$Button3 = GUICtrlCreateButton("", 200, 450, 15, 15)
_GDIPlus_Startup ()
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$hd=_WinAPI_GetDesktopWindow()
If IsHWnd($hd) Then
$win_xy=WinGetPos($hd)
$m_xy=MouseGetPos()
If $m_xy[0]>=$win_xy[0]+8 And $m_xy[1]>$win_xy[1]+192 And $m_xy[0]<$win_xy[0]+$win_xy[2]+8 And $m_xy[1]<$win_xy[1]+$win_xy[3]+192 Then
GUICtrlSetPos ( $Button3, $m_xy[0]-$win_xy[0]-8, $m_xy[1]-$win_xy[1]-192 )
EndIf
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_GDIPlus_Shutdown ()
Exit
EndSwitch
WEnd
Func pic()
$hd=_WinAPI_GetDesktopWindow()
If IsHWnd($hd) Then
_Capture2($hd, 8, 192, 517,192,498,448)
EndIf
EndFunc
Func _Capture2($hWnd, $iLeft_1,$iTop_1,$iLeft_2, $iTop_2,$iWidth, $iheight)
$h1=_Capture3($hWnd, $iLeft_1,$iTop_1,$iWidth, $iheight)
$h2=_Capture3($hWnd, $iLeft_2,$iTop_2,$iWidth, $iheight)
DllCall("user32.dll", "lparam", "SendMessage", "hwnd", GUICtrlGetHandle($Pic1), "int", 0x0172, "wparam", 0, "lparam",ImageColorToTransparent($h1,$h2))
EndFunc
Func _Capture3($hWnd, $iLeft_1,$iTop_1,$iWidth, $iheight)
Local $_SRCCOPY = 0x00CC0020
Local $_SRCINVERT = 0x00660046
Local $hDDC = _WinAPI_GetDC($hWnd)
Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iheight)
_WinAPI_SelectObject($hCDC, $hBMP)
_WinAPI_BitBlt($hCDC, 0, 0, $iWidth, $iheight, $hDDC, $iLeft_1, $iTop_1, $_SRCCOPY)
_WinAPI_ReleaseDC($hWnd, $hDDC)
_WinAPI_DeleteDC($hCDC)
Return $hBMP
EndFunc
Func ImageColorToTransparent($hImage1,$hImage2, $iStartPosX = 0, $iStartPosY = 0, $GuiSizeX = Default, $GuiSizeY = Default)
Local $hBitmap1, $Reslt, $width, $height, $stride, $format, $Scan0, $v_Buffer, $v_Value, $iIW, $iIH
$b1=_GDIPlus_BitmapCreateFromHBITMAP($hImage1)
$b2=_GDIPlus_BitmapCreateFromHBITMAP($hImage2)
$iIW = _GDIPlus_ImageGetWidth($b1)
$iIH = _GDIPlus_ImageGetHeight($b2)
MsgBox(0,$iIW,$iIH)
If $GuiSizeX = Default Or $GuiSizeX > $iIW - $iStartPosX Then $GuiSizeX = $iIW - $iStartPosX
If $GuiSizeY = Default Or $GuiSizeY > $iIH - $iStartPosY Then $GuiSizeY = $iIH - $iStartPosY
$Reslt1 = _GDIPlus_BitmapLockBits($b1, 0, 0, $GuiSizeX, $GuiSizeY, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
$Reslt2 = _GDIPlus_BitmapLockBits($b2, 0, 0, $GuiSizeX, $GuiSizeY, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
$width1 = DllStructGetData($Reslt1, "width")
$height1 = DllStructGetData($Reslt1, "height")
$stride1 = DllStructGetData($Reslt1, "stride")
$format1 = DllStructGetData($Reslt1, "format")
$Scan01 = DllStructGetData($Reslt1, "Scan0")
$width2 = DllStructGetData($Reslt2, "width")
$height2 = DllStructGetData($Reslt2, "height")
$stride2 = DllStructGetData($Reslt2, "stride")
$format2 = DllStructGetData($Reslt2, "format")
$Scan02 = DllStructGetData($Reslt2, "Scan0")
For $i = 0 To $GuiSizeX - 1
For $j = 0 To $GuiSizeY - 1
$v_Buffer1 = DllStructCreate("dword", $Scan01 + ($j * $stride1) + ($i * 4))
$v_Value1 = DllStructGetData($v_Buffer1, 1)
$v_Buffer2 = DllStructCreate("dword", $Scan02 + ($j * $stride2) + ($i * 4))
$v_Value2 = DllStructGetData($v_Buffer2, 1)
If Hex($v_Value2, 6) = Hex($v_Value1, 6) Then
DllStructSetData($v_Buffer1, 1, 0xff0000); Sets Transparency here. Alpha Channel = 00, not written to.
EndIf
Next
Next
_GDIPlus_BitmapUnlockBits($b1, $Reslt1)
_GDIPlus_BitmapUnlockBits($b2, $Reslt2)
Return $b1
EndFunc
自己试试写了一个。
但是还是没有反应!
无奈 |