1. Tải bản cài đặt AutoIT mới nhất

    Chào Khách. Nếu bạn mới tham gia và chưa cài đặt AutoIT.
    Vui lòng vào topic trên để tải bản AutoIT mới nhất nhé
    Dismiss Notice
  2. Quy định và nội quy

    Chào Khách. Vui lòng đọc kỹ nội quy và quy định của diễn đàn
    Để tránh bị ban một cách đáng tiếc nhé!
    Dismiss Notice
  3. Hướng dẫn chèn mã AutoIT trong diễn đàn

    Chào Khách. Vui lòng xem qua bài viết này
    Để biết cách chèn mã AutoIT trong diễn đàn bạn nhé :)
    Dismiss Notice

Source Phóng to phần giữa màn hình (Magnifier)

Thảo luận trong 'Chia sẻ mã nguồn' bắt đầu bởi King Harem, 19/5/18.

  1. King Harem

    King Harem Thành viên mới
    • 3/6

    Tham gia ngày:
    19/7/16
    Bài viết:
    1
    Đã được thích:
    1
    Mã (AutoIt):

    #include <WindowsConstants.au3>
    #include <WinAPI.au3>
    #include <StaticConstants.au3>
    Local $run_=0
    Local $x_center = @DesktopWidth/2 , $y_center = @DesktopHeight/2
    HotKeySet('{F8}','_run')
           MagWindow()
       Func _run()
          $run_ = Not $run_
       EndFunc
    Func MagWindow()
        Global $iMagZoom = 4
        Global $iMagWidth = Ceiling(200 / $iMagZoom)
        Global $iMagHeight = Ceiling(200 / $iMagZoom)
        Global $hDCDesk = 0, $hDCZoom = 0, $hPen = 0
        Global $hUser32 = DllOpen("user32.dll")
        Global $hGDI32 = DllOpen("gdi32.dll")
        Global $mag_open = False
        Local  $mX = 0, $mY = 0
        Global $hZoom = GUICreate("MagPicker", $iMagWidth * $iMagZoom, $iMagHeight * $iMagZoom, 0, 0, $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST)
        Global $mag_label = GUICtrlCreateLabel("placehold", (($iMagHeight * $iMagZoom) / 2) + 2, ($iMagHeight * $iMagZoom) - 13, _
                (($iMagHeight * $iMagZoom) / 2) - 3, 12, $SS_RIGHT)
        Global $__hMouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
        Global $__hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($__hMouseProc), _WinAPI_GetModuleHandle(0))
        $mag_open = True
        _Magnify()
        While $mag_open
             If $run_=1 Then
                GUISetState(@SW_SHOW, $hZoom)
            Else
                GUISetState(@SW_HIDE, $hZoom)
                EndIf
            WinSetOnTop('MagPicker', "", $WINDOWS_ONTOP)
            Sleep(50)
       WEnd
        GUIDelete($hZoom)
        ReleaseHooks()
    EndFunc
    Func _Magnify($_iX = -1, $_iY = -1, $reset = False)
        Local Static $fInit = True
        If $fInit Then
            $fInit = False
            $hDCDesk = (DllCall($hUser32, "int", "GetDC", "hwnd", 0))[0]
            $hDCZoom = (DllCall($hUser32, "int", "GetDC", "hwnd", $hZoom))[0]
            $hPen = (DllCall($hGDI32, "int", "CreatePen", "int", 0, "int", 3, "int", 0x008b9094))[0] ;
            DllCall($hGDI32, "int", "SelectObject", "int", $hDCZoom, "hwnd", $hPen)
            $_iX = MouseGetPos(0)
            $_iY = MouseGetPos(1)
        EndIf
        Local $iW = $iMagWidth * $iMagZoom, $iH = $iMagHeight * $iMagZoom
        If Not @error Then
            DllCall($hGDI32, "int", "StretchBlt", "int", $hDCZoom, "int", _
                    0, "int", 0, "int", $iW, "int", $iH, "int", $hDCDesk, "int", _
                    $_iX - $iMagWidth / 2, "int", $_iY - $iMagHeight / 2, "int", $iMagWidth, "int", $iMagHeight, _
                   "long", $SRCCOPY)
        EndIf
        If $reset Then
            $fInit = True
        EndIf
    EndFunc
    Func _MouseProc($_nCode, $_wParam, $_lParam)
        Local $tMSLLHOOKSTRUCT = DllStructCreate("struct; long X;long Y; endstruct; " & _
                "DWORD mouseData; DWORD flags; DWORD time; ULONG_PTR dwExtraInfo;endstruct", $_lParam)
        If $_nCode < 0 Then Return _WinAPI_CallNextHookEx($__hHook, $_nCode, $_wParam, $_lParam)
        Local $iX = $tMSLLHOOKSTRUCT.X, $iY = $tMSLLHOOKSTRUCT.Y
        Switch $_wParam
            Case $WM_MBUTTONDOWN
                CloseMag()
            Case $WM_MOUSEMOVE
                If Not $mag_open Then Return
                Local $iXz = ($iX + 24 + $iMagWidth * $iMagZoom > @DesktopWidth) ? $iX - (24 + $iMagWidth * $iMagZoom) : $iX + 24
                Local $iYz = ($iY + 24 + $iMagHeight * $iMagZoom > @DesktopHeight) ? $iY - (24 + $iMagHeight * $iMagZoom) : $iY + 24
                _Magnify($iX, $iY)
        EndSwitch
        Return _WinAPI_CallNextHookEx($__hHook, $_nCode, $_wParam, $_lParam)
    EndFunc
    Func ReleaseHooks()
        _Magnify(Default, Default, True)
        DllCall($hUser32, "int", "ReleaseDC", "int", $hDCZoom, "hwnd", $hPen)
        DllCall($hUser32, "int", "ReleaseDC", "int", $hDCDesk, "hwnd", 0)
        DllCall($hUser32, "int", "ReleaseDC", "int", $hDCZoom, "hwnd", 0)
        DllClose($hUser32)
        DllClose($hGDI32)
        _WinAPI_UnhookWindowsHookEx($__hHook)
        DllCallbackFree($__hMouseProc)
    EndFunc
    Func CloseMag()
        $mag_open = False
    EndFunc
     
    Em có tìm trên mạng được đoạn code của Joe trong autoitscript.com thấy hay hay.
     
    Nguyên Ary thích bài này.

Chia sẻ trang này

Đang tải...