Что нового

Создание экранной лупы на подобии Free Shooter.

Belfigor

Модератор
Локальный модератор
Сообщения
3,608
Репутация
941
Собственно вот тема: http://autoit-script.ru/index.php/topic,785.0.html
Пытался вникнуть в исходник программы но так и не смог вычленить оттуда ту часть, которая отвечает за создание самой лупы. Хочу у себя на экране иметь параллельно с основным потоком графики окошко, в котором будет увеличена небольшая область экрана. Кто может подсказать как этого добиться?
 

Yashied

Модератор
Команда форума
Глобальный модератор
Сообщения
5,379
Репутация
2,724
Это уже было здесь. Я его немного изменил для WinAPIEx v3.0.

Код:
#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $hParent, $hForm, $Pos, $Go = 1, $XPrev = MouseGetPos(0), $YPrev = MouseGetPos(1)

HotKeySet('{ESC}', '_Quit')

$hParent = GUICreate('', -1, -1, -1, -1, -1, $WS_EX_TOOLWINDOW)
$hForm = GUICreate('', 200, 200, $XPrev + 25, $YPrev + 25, BitOR($WS_DISABLED, $WS_POPUPWINDOW), BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST), $hParent)
GUISetState(@SW_SHOWNOACTIVATE, $hForm)

While 1
    GUIGetMsg()
    $Pos = MouseGetPos()
    If ($Go) Or ($Pos[0] <> $XPrev) Or ($Pos[1] <> $YPrev) Then
        WinMove($hForm, '', $Pos[0] + 25, $Pos[1] + 25)
        _Capture($Pos[0] - 25, $Pos[1] - 25, 50, 50)
        $XPrev = $Pos[0]
        $YPrev = $Pos[1]
        $Go = 0
    EndIf
WEnd

Func _Capture($iX, $iY, $iWidth, $iHeight)

    Local $tRect, $hDC, $hMemDC, $hBitmap, $hScreenshort

	$hScreenshort = _ScreenCapture($iX, $iY, $iWidth, $iHeight)
    $hBitmap = _WinAPI_ResizeBitmap($hScreenshort, 200, 200)
    _WinAPI_DeleteObject($hScreenshort)
    $hDC = _WinAPI_GetDC($hForm)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($NULL_BRUSH))
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($DC_PEN))
    _WinAPI_SetDCPenColor($hMemDC, 0xA00000)
    $tRect = _WinAPI_CreateRect(0, 0, 200, 200)
    _WinAPI_Rectangle($hMemDC, $tRect)
    _WinAPI_ReleaseDC($hForm, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    _SetBitmap($hForm, $hBitmap, 255)
    _WinAPI_DeleteObject($hBitmap)
EndFunc   ;==>_Capture

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func _ScreenCapture($iX, $iY, $iWidth, $iHeight)

    Local $hWnd, $hDC, $hMemDC, $hBitmap

    $hWnd = _WinAPI_GetDesktopWindow()
    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $iWidth, $iHeight, $hDC, $iX, $iY, $SRCCOPY)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    Return $hBitmap
EndFunc   ;==>_ScreenCapture

Func _SetBitmap($hWnd, $hBitmap, $iOpacity)

    Local $hDC, $hMemDC, $hSv, $pBlend, $tBlend, $pSize, $tSize, $pSource, $tSource

    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hSv = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = _WinAPI_GetBitmapDimension($hBitmap)
    $pSize = DllStructGetPtr($tSize)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, 'Alpha', $iOpacity)
    DllStructSetData($tBlend, 'Format', 0)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hMemDC, $hSv)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap
 

Sniper

Новичок
Сообщения
23
Репутация
1
немного подправил:
Код:
#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $hParent, $hForm, $Pos, $Go = 1, $XPrev = MouseGetPos(0), $YPrev = MouseGetPos(1)

HotKeySet('{ESC}', '_Quit')

$hParent = GUICreate('', -1, -1, -1, -1, -1, $WS_EX_TOOLWINDOW)
$hForm = GUICreate('', 200, 200, $XPrev + 25, $YPrev + 25, BitOR($WS_DISABLED, $WS_POPUPWINDOW), BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST), $hParent)
GUISetState(@SW_SHOWNOACTIVATE, $hForm)

While 1
    GUIGetMsg()
    $Pos = MouseGetPos()
	If $pos[0] >= @DesktopWidth - 250 And $pos[1] >= @DesktopHeight - 250 And (($Go) Or ($Pos[0] <> $XPrev) Or ($Pos[1] <> $YPrev)) Then
		WinMove($hForm, '', $Pos[0] - 225, $Pos[1] - 225)
        $XPrev = $Pos[0]
        $YPrev = $Pos[1]
        $Go = 0
	EndIf
	If $pos[0] >= @DesktopWidth - 250 And (($Go) Or ($Pos[0] <> $XPrev) Or ($Pos[1] <> $YPrev)) Then
		WinMove($hForm, '', $Pos[0] - 225, $Pos[1] + 25)
        $XPrev = $Pos[0]
        $YPrev = $Pos[1]
        $Go = 0
	EndIf
	If $pos[1] >= @DesktopHeight - 250 And (($Go) Or ($Pos[0] <> $XPrev) Or ($Pos[1] <> $YPrev)) Then
		WinMove($hForm, '', $Pos[0] + 25, $Pos[1] - 225)
        $XPrev = $Pos[0]
        $YPrev = $Pos[1]
        $Go = 0
	EndIf
    If ($Go) Or ($Pos[0] <> $XPrev) Or ($Pos[1] <> $YPrev) Then
        WinMove($hForm, '', $Pos[0] + 25, $Pos[1] + 25)
        $XPrev = $Pos[0]
        $YPrev = $Pos[1]
        $Go = 0
    EndIf
	_Capture($Pos[0] - 25, $Pos[1] - 25, 50, 50)
	Sleep(1)
WEnd

Func _Capture($iX, $iY, $iWidth, $iHeight)

    Local $tRect, $hDC, $hMemDC, $hBitmap, $hScreenshort

    $hScreenshort = _ScreenCapture($iX, $iY, $iWidth, $iHeight)
    $hBitmap = _WinAPI_ResizeBitmap($hScreenshort, 200, 200)
    _WinAPI_DeleteObject($hScreenshort)
    $hDC = _WinAPI_GetDC($hForm)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($NULL_BRUSH))
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($DC_PEN))
    _WinAPI_SetDCPenColor($hMemDC, 0xA00000)
    $tRect = _WinAPI_CreateRect(0, 0, 200, 200)
    _WinAPI_Rectangle($hMemDC, $tRect)
    _WinAPI_ReleaseDC($hForm, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    _SetBitmap($hForm, $hBitmap, 255)
    _WinAPI_DeleteObject($hBitmap)
EndFunc   ;==>_Capture

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func _ScreenCapture($iX, $iY, $iWidth, $iHeight)

    Local $hWnd, $hDC, $hMemDC, $hBitmap

    $hWnd = _WinAPI_GetDesktopWindow()
    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $iWidth, $iHeight, $hDC, $iX, $iY, $SRCCOPY)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    Return $hBitmap
EndFunc   ;==>_ScreenCapture

Func _SetBitmap($hWnd, $hBitmap, $iOpacity)

    Local $hDC, $hMemDC, $hSv, $pBlend, $tBlend, $pSize, $tSize, $pSource, $tSource

    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hSv = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = _WinAPI_GetBitmapDimension($hBitmap)
    $pSize = DllStructGetPtr($tSize)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, 'Alpha', $iOpacity)
    DllStructSetData($tBlend, 'Format', 0)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hMemDC, $hSv)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap
 
Автор
B

Belfigor

Модератор
Локальный модератор
Сообщения
3,608
Репутация
941
Спасибо всем!
 

Redline

AutoIT Гуру
Сообщения
506
Репутация
375
И мой Zoom =)
Код:
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Dim $coord[2], $oldCoord[2], $pict, $hBit, $hGraph, $side = 60, $zoom = 2, $desk = WinGetPos("Program Manager")

$hGUI = GUICreate("Zoo-o-o-M", $side*$zoom + 2, $side*$zoom + 2, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)

GUISetState()
_GDIPlus_Startup()
While GUIGetMsg() <> -3
    $coord = MouseGetPos()
    If $coord[0] <> $oldCoord[0] Or $coord[1] <> $oldCoord[1]  Then
        $oldCoord = $coord
        _GDIPlus_GraphicsDispose($hGraph)
        _GDIPlus_ImageDispose($hBit)
        _WinAPI_DeleteObject($pict)
        $pict = _ScreenCapture_Capture("", $coord[0] - $side/2, $coord[1] - $side/2, $coord[0] + $side/2, $coord[1] + $side/2)
        $hBit = _GDIPlus_BitmapCreateFromHBITMAP($pict)
        $hGraph = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        _GDIPlus_GraphicsDrawImageRectRect($hGraph, $hBit, 0, 0, $side, $side, 1, 1, $side*$zoom, $side*$zoom)
        If $coord[0] > $desk[2] - $side*($zoom + 0.5) - 2 Then $coord[0] = $coord[0] - $side*$zoom - $side - 2
        If $coord[1] > $desk[3] - $side*($zoom + 0.5) - 2 Then $coord[1] = $coord[1] - $side*$zoom - $side - 2
        WinMove("Zoo-o-o-M", "", $coord[0] + $side/2 , $coord[1] + $side/2)
    EndIf
    Sleep(50)
WEnd
_GDIPlus_Shutdown()
 

Alex2019

Новичок
Сообщения
1
Репутация
0
Redline. Все работает. Спасибо! А что надо сделать чтобы все работало в directX? Еще вопрос. Как добавить горячую клавишу? Извените за глупые вопросы. Решил изучить AutoIT. Пока плаваю, но язык нравится. Просто и со вкусом. Заранее спасибо!
 
Верх