Jump to content
Sign in to follow this  
KaFu

Resize Image and display centered in control

Recommended Posts

Hiho Forum,

I'm still not that good using GDI, but this should be no problem for the real pros :oops:.

I want to load a picture of any size, resize it while maintaining the aspect ratio and display it centered in a 320x240 control. Anyone got a hint for me what I'm doing wrong?

#include <GDIPlus.au3>
#include <WinAPI.au3>
HotKeySet("{ESC}", "_Exit")
_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172
Global Const $IMAGE_BITMAP = 0
GUICreate("Test", 340, 260)
$c_Pic = GUICtrlCreatePic("", 10, 10, 320, 240)
$h_Pic = GUICtrlGetHandle($c_Pic)
GUISetState()
_SetPicture($h_Pic, @ScriptDir & "\test.jpg")
While 1
 Sleep(10)
WEnd
Func _SetPicture($hWnd, $sFile)
 Local $hDC = _WinAPI_GetWindowDC($hWnd)
 Local $hDC_Sub = _WinAPI_CreateCompatibleDC($hDC)
 _WinAPI_ReleaseDC($hWnd, $hDC)
 Local $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)
 Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
 Local $_PC_iX = _GDIPlus_ImageGetWidth($hImage)
 Local $_PC_iY = _GDIPlus_ImageGetHeight($hImage)
 Local $_PC_aScale = _GetScale($_PC_iX, $_PC_iY, 320)
 Local $_PC_iX_New = (320 - $_PC_aScale[2] / 2) - (320 / 2)
 Local $_PC_iY_New = (240 - $_PC_aScale[3] / 2) - (240 / 2)
 _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $_PC_iX_New, $_PC_iY_New, $_PC_aScale[2], $_PC_aScale[3])
 $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
 _WinAPI_DeleteObject(GUICtrlSendMsg($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hbmp))
 _WinAPI_DeleteObject($hbmp)
 _GDIPlus_ImageDispose($hImage)
 _GDIPlus_GraphicsDispose($hGraphic)
 _WinAPI_DeleteDC($hDC_Sub)
EndFunc   ;==>_SetPicture
Func _Exit()
 _GDIPlus_Shutdown()
 Exit
EndFunc   ;==>_Exit
Func _GetScale($iW, $iH, $i_TargetWidth)
 Local $aRet[4]
 If $iW <= $i_TargetWidth And $iH <= $i_TargetWidth Then
  $aRet[2] = $iW
  $aRet[3] = $iH
  $aRet[0] = ($i_TargetWidth - $aRet[2]) / 2
  $aRet[1] = ($i_TargetWidth - $aRet[3]) / 2
 ElseIf $iW > $iH Then
  $aRet[2] = $i_TargetWidth
  $aRet[3] = $iH / ($iW / $i_TargetWidth)
  $aRet[0] = 0
  $aRet[1] = ($i_TargetWidth - $aRet[3]) / 2
 ElseIf $iW < $iH Then
  $aRet[2] = $iW / ($iH / $i_TargetWidth)
  $aRet[3] = $i_TargetWidth
  $aRet[0] = ($i_TargetWidth - $aRet[2]) / 2
  $aRet[1] = 0
 ElseIf $iW = $iH Then
  $aRet[2] = $i_TargetWidth
  $aRet[3] = $i_TargetWidth
  $aRet[0] = 0
  $aRet[1] = 0
 EndIf
 Return $aRet
EndFunc   ;==>_GetScale

Share this post


Link to post
Share on other sites

Hmmm, not quite what I was looking for. This does what I want... except that I can't get the $STM_SETIMAGE part to work properly. On XP and Vista+ with DWM disabled the image is lost on redraw (e.g. another window covers the pic) :oops:...

#include <GDIPlus.au3>
#include <WinAPI.au3>
HotKeySet("{ESC}", "_Exit")
_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172
Global Const $IMAGE_BITMAP = 0
GUICreate("Test", 340, 260)
$c_Pic = GUICtrlCreatePic("", 10, 10, 320, 240)
$h_Pic = GUICtrlGetHandle($c_Pic)
GUISetState()
_SetPicture($h_Pic, @ScriptDir & "test.jpg")
While 1
    Sleep(10)
WEnd
Func _SetPicture($hWnd, $sFile)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    Local $_PC_iX = _GDIPlus_ImageGetWidth($hImage)
    Local $_PC_iY = _GDIPlus_ImageGetHeight($hImage)

    If $_PC_iX > $_PC_iY Then
        Local $_PC_aScale = _GetScale($_PC_iX, $_PC_iY, 320)
    Else
        Local $_PC_aScale = _GetScale($_PC_iX, $_PC_iY, 240)
    EndIf

    ConsoleWrite($_PC_aScale[0] & @TAB & $_PC_aScale[1] & @TAB & $_PC_aScale[2] & @TAB & $_PC_aScale[3] & @CRLF)
    Local $_PC_iX_New = (320 - $_PC_aScale[2] / 2) - (320 / 2)
    Local $_PC_iY_New = (240 - $_PC_aScale[3] / 2) - (240 / 2)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $_PC_iX_New, $_PC_iY_New, $_PC_aScale[2], $_PC_aScale[3])

    #cs
        $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        _WinAPI_DeleteObject(GUICtrlSendMsg($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hbmp))
        _WinAPI_DeleteObject($hbmp)
    #ce
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
EndFunc   ;==>_SetPicture

Func _Exit()
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit
Func _GetScale($iW, $iH, $i_TargetWidth)
    Local $aRet[4]
    If $iW <= $i_TargetWidth And $iH <= $i_TargetWidth Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($i_TargetWidth - $aRet[2]) / 2
        $aRet[1] = ($i_TargetWidth - $aRet[3]) / 2
    ElseIf $iW > $iH Then
        $aRet[2] = $i_TargetWidth
        $aRet[3] = $iH / ($iW / $i_TargetWidth)
        $aRet[0] = 0
        $aRet[1] = ($i_TargetWidth - $aRet[3]) / 2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW / ($iH / $i_TargetWidth)
        $aRet[3] = $i_TargetWidth
        $aRet[0] = ($i_TargetWidth - $aRet[2]) / 2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $i_TargetWidth
        $aRet[3] = $i_TargetWidth
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc   ;==>_GetScale

Share this post


Link to post
Share on other sites

You have to repaint the GDI+ stuff when the window gets repaint message:

#include <windowsconstants.au3>
#include <gdiplus.au3>

HotKeySet("{ESC}", "_Exit")

_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172
Global Const $IMAGE_BITMAP = 0
GUICreate("Test", 340, 260)
$c_Pic = GUICtrlCreatePic("", 10, 10, 320, 240)
$h_Pic = GUICtrlGetHandle($c_Pic)
GUISetState()

Global $aRet = _SetPicture($h_Pic, @ScriptDir & "test.jpg")
GUIRegisterMsg($WM_ERASEBKGND, "RePaint")

While 1
    Sleep(10)
WEnd

Func RePaint($hWnd, $msg, $wParam, $lParam)
    ; The sequencial order of these two commands is important.
    _GDIPlus_GraphicsDrawImageRect($aRet[0], $aRet[1], $aRet[2], $aRet[3], $aRet[4], $aRet[5])
    _WinAPI_RedrawWindow($hWnd, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)); , $RDW_ALLCHILDREN
    Return 1
EndFunc ;==>MY_PAINT

Func _SetPicture($hWnd, $sFile)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    Local $_PC_iX = _GDIPlus_ImageGetWidth($hImage)
    Local $_PC_iY = _GDIPlus_ImageGetHeight($hImage)

    If $_PC_iX > $_PC_iY Then
        Local $_PC_aScale = _GetScale($_PC_iX, $_PC_iY, 320)
    Else
        Local $_PC_aScale = _GetScale($_PC_iX, $_PC_iY, 240)
    EndIf

    ConsoleWrite($_PC_aScale[0] & @TAB & $_PC_aScale[1] & @TAB & $_PC_aScale[2] & @TAB & $_PC_aScale[3] & @CRLF)
    Local $_PC_iX_New = (320 - $_PC_aScale[2] / 2) - (320 / 2)
    Local $_PC_iY_New = (240 - $_PC_aScale[3] / 2) - (240 / 2)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $_PC_iX_New, $_PC_iY_New, $_PC_aScale[2], $_PC_aScale[3])

    #cs
        $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        _WinAPI_DeleteObject(GUICtrlSendMsg($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hbmp))
        _WinAPI_DeleteObject($hbmp)
    #ce
    Local $aReturn[6] = [$hGraphic, $hImage, $_PC_iX_New, $_PC_iY_New, $_PC_aScale[2], $_PC_aScale[3]]
    Return $aReturn
EndFunc   ;==>_SetPicture

Func _Exit()
    _GDIPlus_ImageDispose($aRet[1])
    _GDIPlus_GraphicsDispose($aRet[0])
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Func _GetScale($iW, $iH, $i_TargetWidth)
    Local $aRet[4]
    If $iW <= $i_TargetWidth And $iH <= $i_TargetWidth Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($i_TargetWidth - $aRet[2]) / 2
        $aRet[1] = ($i_TargetWidth - $aRet[3]) / 2
    ElseIf $iW > $iH Then
        $aRet[2] = $i_TargetWidth
        $aRet[3] = $iH / ($iW / $i_TargetWidth)
        $aRet[0] = 0
        $aRet[1] = ($i_TargetWidth - $aRet[3]) / 2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW / ($iH / $i_TargetWidth)
        $aRet[3] = $i_TargetWidth
        $aRet[0] = ($i_TargetWidth - $aRet[2]) / 2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $i_TargetWidth
        $aRet[3] = $i_TargetWidth
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc   ;==>_GetScale

Tested on Win7 x64 + Aero enabled.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

The problem occurs on XP and Vista+ with Aero disabled.

With Aero enabled my example above works fine too, yours of course too.

But with Aero disabled my example does not work at all and yours adds parts of the underlying background to the GUI for me :oops: ...

Share this post


Link to post
Share on other sites

I would do something like this (only because yours looks so complicated):

#include "GifAnimation.au3"
#include <WindowsConstants.au3>
Opt("GUICloseOnESC", 1); ESC to exit
Opt("MustDeclareVars", 1)
Global $sPic = @ScriptDir & "test.jpg"
Global $hGUI = GUICreate("", 700, 500)
Global $hPic = BzzThatThingDone($sPic, 10, 10, 320, 240)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $hPic
            MsgBox(32, "", "OK?", 0, $hGUI)
    EndSwitch
WEnd

Func BzzThatThingDone($sPic, $iX, $iY, $iWidth, $iHeight)
    Local $aSize = _GIF_GetDimension($sPic)
    Local $nScaleX = $iWidth / $aSize[0]
    Local $nScaleY = $iHeight / $aSize[1]
    Local $nScale = $nScaleX
    If $nScale > $nScaleY Then $nScale = $nScaleY
    Local $iWidthNew = $aSize[0] * $nScale
    Local $iHeightNew = $aSize[1] * $nScale
    Return _GUICtrlCreateGIF($sPic, "", $iX + ($iWidth - $iWidthNew) / 2, $iY + $iY + ($iHeight - $iHeightNew) / 2, $iWidthNew, $iHeightNew)
EndFunc

GifAnimation.au3 is something I wrote once. Can be found in examples. Uses Gdip too.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Sorry, did not read your post carefully!

Can you try this here please?

#include <windowsconstants.au3>
#include <gdiplus.au3>

_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172
Global Const $IMAGE_BITMAP = 0
GUICreate("Test", 340, 260)
$c_Pic = GUICtrlCreatePic("", 10, 10, 320, 240)
$h_Pic = GUICtrlGetHandle($c_Pic)
GUISetState()

Global $aRet = _SetPicture($h_Pic, @ScriptDir & "test.jpg")
If @OSBuild < 6000 Then
    GUIRegisterMsg($WM_PAINT, "WM_REDRAW_XP")
Else
    GUIRegisterMsg($WM_PAINT, "WM_REDRAW")
EndIf

HotKeySet("{ESC}", "_Exit")

While 1
    Sleep(10)
WEnd

Func WM_REDRAW($hWnd, $msg, $wParam, $lParam)
    #forceref $msg, $wParam, $lParam
    _WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_UPDATENOW + $RDW_NOINTERNALPAINT)
    _GDIPlus_GraphicsDrawImageRect($aRet[0], $aRet[1], $aRet[2], $aRet[3], $aRet[4], $aRet[5])
    Return "GUI_RUNDEFMSG"
EndFunc ;==>MY_PAINT

Func WM_REDRAW_XP($hWnd, $msg, $wParam, $lParam)
    #forceref $msg, $wParam, $lParam
    _WinAPI_RedrawWindow($hWnd, 0, 0, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))
    _GDIPlus_GraphicsDrawImageRect($aRet[0], $aRet[1], $aRet[2], $aRet[3], $aRet[4], $aRet[5])
    Return "GUI_RUNDEFMSG"
EndFunc ;==>MY_PAINT

Func _SetPicture($hWnd, $sFile)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    Local $_PC_iX = _GDIPlus_ImageGetWidth($hImage)
    Local $_PC_iY = _GDIPlus_ImageGetHeight($hImage)

    If $_PC_iX > $_PC_iY Then
        Local $_PC_aScale = _GetScale($_PC_iX, $_PC_iY, 320)
    Else
        Local $_PC_aScale = _GetScale($_PC_iX, $_PC_iY, 240)
    EndIf

    ConsoleWrite($_PC_aScale[0] & @TAB & $_PC_aScale[1] & @TAB & $_PC_aScale[2] & @TAB & $_PC_aScale[3] & @CRLF)
    Local $_PC_iX_New = (320 - $_PC_aScale[2] / 2) - (320 / 2)
    Local $_PC_iY_New = (240 - $_PC_aScale[3] / 2) - (240 / 2)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $_PC_iX_New, $_PC_iY_New, $_PC_aScale[2], $_PC_aScale[3])

    #cs
        $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        _WinAPI_DeleteObject(GUICtrlSendMsg($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hbmp))
        _WinAPI_DeleteObject($hbmp)
    #ce
    Local $aReturn[6] = [$hGraphic, $hImage, $_PC_iX_New, $_PC_iY_New, $_PC_aScale[2], $_PC_aScale[3]]
    Return $aReturn
EndFunc   ;==>_SetPicture

Func _Exit()
    GUIRegisterMsg($WM_PAINT, "")
    _GDIPlus_ImageDispose($aRet[1])
    _GDIPlus_GraphicsDispose($aRet[0])
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Func _GetScale($iW, $iH, $i_TargetWidth)
    Local $aRet[4]
    If $iW <= $i_TargetWidth And $iH <= $i_TargetWidth Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($i_TargetWidth - $aRet[2]) / 2
        $aRet[1] = ($i_TargetWidth - $aRet[3]) / 2
    ElseIf $iW > $iH Then
        $aRet[2] = $i_TargetWidth
        $aRet[3] = $iH / ($iW / $i_TargetWidth)
        $aRet[0] = 0
        $aRet[1] = ($i_TargetWidth - $aRet[3]) / 2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW / ($iH / $i_TargetWidth)
        $aRet[3] = $i_TargetWidth
        $aRet[0] = ($i_TargetWidth - $aRet[2]) / 2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $i_TargetWidth
        $aRet[3] = $i_TargetWidth
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc   ;==>_GetScale

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Couldn't stop tinkering myself :oops:, thanks for all your input!

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

_GDIPlus_Startup()

Global Const $STM_SETIMAGE = 0x0172
Global Const $IMAGE_BITMAP = 0

GUICreate("Test", 340, 260)
GUICtrlCreateLabel("", 10, 10, 320, 240)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetState(-1, $GUI_DISABLE)
$c_Pic = GUICtrlCreatePic("", 10, 10, 320, 240)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()

Sleep(2000)
_GUIPicCtrl_SetFile($c_Pic, @ScriptDir & "test.jpg")
Sleep(2000)
_WinAPI_DeleteObject(GUICtrlSendMsg($c_Pic, $STM_SETIMAGE, $IMAGE_BITMAP, 0))
Sleep(2000)
_GUIPicCtrl_SetFile($c_Pic, @ScriptDir & "test2.jpg")

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

_GDIPlus_Shutdown()
Exit

Func _GUIPicCtrl_SetFile($iCtrlId, $sFile)

    Local $hWnd = GUICtrlGetHandle($iCtrlId)

    Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    Local $iX_Input = _GDIPlus_ImageGetWidth($hImage)
    Local $iY_Input = _GDIPlus_ImageGetHeight($hImage)

    Local $iRatio = $iX_Input / $iY_Input, $iX_Output, $iY_Output, $iX_Output_Offset, $iY_Output_Offset

    If $iRatio > 1 Then
        $iX_Output = 320
        $iY_Output = 320 / $iRatio
        $iX_Output_Offset = 0
        $iY_Output_Offset = (240 / 2) - ($iY_Output / 2)
    Else
        $iX_Output = 240 * $iRatio
        $iY_Output = 240
        $iX_Output_Offset = (320 / 2) - ($iX_Output / 2)
        $iY_Output_Offset = 0
    EndIf

    Local $hHBITMAP = _WinAPI_CreateBitmap(320, 240, 1, 32)
    Local $hCDC = _WinAPI_CreateCompatibleDC(0)
    _WinAPI_SelectObject($hCDC, $hHBITMAP)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hCDC)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $iX_Output_Offset, $iY_Output_Offset, $iX_Output, $iY_Output)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteDC($hCDC)

    _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrlId, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP)) ; works with $iCtrlId, fails with control handle!
    _WinAPI_DeleteObject($hHBITMAP)

    _WinAPI_RedrawWindow($hWnd)

EndFunc   ;==>_SetPicture

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By UEZ
      Here another example to mark the desktop to get the marked region for capturing. This example is not perfect and not very fast (room for improvements).
      ;Coded by UEZ build 2020-08-07 beta ;Code cleanup up mLipok ; ;Short instruction: mark area on your desktop and press return key to capture. #include <APISysConstants.au3> #include <Array.au3> ;#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <ScreenCapture.au3> #include <WinAPIGdi.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> ; enum _PROCESS_DPI_AWARENESS -> https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx Global Enum $DPI_AWARENESS_INVALID = -1, $PROCESS_DPI_UNAWARE = 0, $PROCESS_SYSTEM_DPI_AWARE, $PROCESS_PER_MONITOR_DPI_AWARE ;https://docs.microsoft.com/en-us/windows/desktop/hidpi/dpi-awareness-context Global Enum $Context_UnawareGdiScaled = -5, $Context_PerMonitorAwareV2, $Context_PerMonitorAware, $Context_SystemAware, $Context_Unaware _WinAPI_SetProcessDpiAwarenessContext($Context_PerMonitorAware) Global $__g_hGUI_MarkArea, $__g_hGUI_Bg, $__g_iLabel_TL, $__g_iLabel_TM, $__g_iLabel_TR, $__g_iLabel_LM, $__g_iLabel_RM, $__g_iLabel_BL, $__g_iLabel_BM, _ $__g_iLabel_BR, $__g_iOldCursor, $__g_iW, $__g_iH, $__g_iColor_ResizeDots = 0xFFFFFF, $__g_iBorder = 4, $__g_bSelectionDone = False Global $aRect = _GDIPlus_MarkScreenRegionAnimated() Global $hImage_Capture = _ScreenCapture_Capture(@TempDir & "\Test.png", $aRect[0], $aRect[1], $aRect[0] + $aRect[2] - 1, $aRect[1] + $aRect[3] - 1, False) ShellExecute(@TempDir & "\Test.png") ;_ArrayDisplay($aRect, "Marked area coordinates") Func _GDIPlus_MarkScreenRegionAnimated($bAnim = True) _GDIPlus_Startup() Local Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Local Const $aFullScreen = WinGetPos($hFullScreen) $__g_hGUI_Bg = GUICreate("", $aFullScreen[2], $aFullScreen[3], $aFullScreen[0], $aFullScreen[1], BitOR($WS_CLIPCHILDREN, $WS_POPUP), $WS_EX_TOPMOST) ;to avoid cursor flickering and for proper control read WinSetTrans($__g_hGUI_Bg, "", 0x01) $__g_hGUI_MarkArea = GUICreate("", 1, 1, -1, -1, $bAnim ? $WS_POPUP : BitOR($WS_POPUP, $WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED), $__g_hGUI_Bg) GUISetBkColor(0xABCDEF, $__g_hGUI_MarkArea) If Not $bAnim Then $__g_iColor_ResizeDots = 0xFF0000 $__g_iLabel_TL = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;top left GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_TM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;top mid GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_TR = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;top right GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_LM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;left mid GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_RM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;right mid GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_BL = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;bottom left GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_BM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;bottom mid GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_BR = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;bottom right GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) GUISetState(@SW_SHOWNA, $__g_hGUI_Bg) GUISetState(@SW_SHOW, $__g_hGUI_MarkArea) $__g_iOldCursor = MouseGetCursor() GUISetCursor(3, 1, $__g_hGUI_Bg) GUISetCursor(3, 1, $__g_hGUI_MarkArea) _WinAPI_SetLayeredWindowAttributes($__g_hGUI_MarkArea, 0xABCDEF, 0xF0) Local $aMPos, $aPrevMPos[2] = [MouseGetPos(0) + 1, MouseGetPos(1) + 1], $iID, $aCI, $iX, $iY, $aOldWinPos, $aOldMPos, $bMoved Local $aGUIStartPos, $iKey_Exit = GUICtrlCreateButton("", $aFullScreen[0] - 10, $aFullScreen[1] - 10, 1, 1), $aAccelKeys[1][2] = [["{ENTER}", $iKey_Exit]] GUISetAccelerators($aAccelKeys, $__g_hGUI_Bg) GUISetAccelerators($aAccelKeys, $__g_hGUI_MarkArea) #forceref $bMoved Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iKey_Exit If $bAnim Then GUIRegisterMsg($WM_TIMER, "") DllCall("user32.dll", "bool", "KillTimer", "hwnd", $__g_hGUI_MarkArea, "uint_ptr", $iID) GUIRegisterMsg($WM_ERASEBKGND, "") EndIf _GDIPlus_Shutdown() Local $aResult = WinGetPos($__g_hGUI_MarkArea) $aResult[2] = WinGetClientSize($__g_hGUI_MarkArea)[0] $aResult[3] = WinGetClientSize($__g_hGUI_MarkArea)[1] GUIDelete($__g_hGUI_MarkArea) GUIDelete($__g_hGUI_Bg) If Not $__g_bSelectionDone Then $aResult = 0 Return $aResult EndSwitch $aMPos = MouseGetPos() If ($aMPos[0] <> $aPrevMPos[0] Or $aMPos[1] <> $aPrevMPos[1]) And (Not $__g_bSelectionDone) Then WinMove($__g_hGUI_MarkArea, "", $aMPos[0], $aMPos[1]) $aPrevMPos = $aMPos EndIf $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) If $aCI[2] And (Not $__g_bSelectionDone) Then $aGUIStartPos = WinGetPos($__g_hGUI_MarkArea) If $bAnim Then GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND") GUIRegisterMsg($WM_TIMER, "PlayBorderAnim") $iID = DllCall("User32.dll", "uint_ptr", "SetTimer", "hwnd", $__g_hGUI_MarkArea, "uint_ptr", 1, "uint", 50, "ptr", 0)[0] EndIf While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) $aMPos = MouseGetPos() $__g_iW = Abs($aMPos[0] - $aGUIStartPos[0]) + 1 $__g_iH = Abs($aMPos[1] - $aGUIStartPos[1]) + 1 If $aMPos[0] < $aGUIStartPos[0] Then $iX = $aMPos[0] Else $iX = $aGUIStartPos[0] EndIf If $aMPos[1] < $aGUIStartPos[1] Then $iY = $aMPos[1] Else $iY = $aGUIStartPos[1] EndIf WinMove($__g_hGUI_MarkArea, "", $iX, $iY, $__g_iW, $__g_iH) UpdateCtrlPos($bAnim) WEnd $__g_bSelectionDone = True GUISetCursor(3, 1, $__g_hGUI_MarkArea) ElseIf $aCI[3] And $__g_bSelectionDone Then $aGUIStartPos = WinGetPos($__g_hGUI_MarkArea) If _WinAPI_PtInRectEx(MouseGetPos(0), MouseGetPos(1), $aGUIStartPos[0], $aGUIStartPos[1], $aGUIStartPos[0] + $aGUIStartPos[2], $aGUIStartPos[1] + $aGUIStartPos[3]) Then $aMPos = MouseGetPos() $aGUIStartPos = WinGetPos($__g_hGUI_MarkArea) While $aCI[3] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aGUIStartPos[0] - ($aMPos[0] - MouseGetPos(0)), $aGUIStartPos[1] - ($aMPos[1] - MouseGetPos(1)), $__g_iW, $__g_iH) GUISetCursor(0, 1, $__g_hGUI_Bg) GUISetCursor(0, 1, $__g_hGUI_MarkArea) WEnd GUISetCursor(3, 1, $__g_hGUI_Bg) GUISetCursor(3, 1, $__g_hGUI_MarkArea) EndIf EndIf If $__g_bSelectionDone Then $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) If @error Then ContinueLoop Switch $aCI[4] Case $__g_iLabel_TL GUISetCursor(12, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", MouseGetPos(0), MouseGetPos(1), $aOldWinPos[2] + ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3] + ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_BR GUISetCursor(12, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aOldWinPos[0], $aOldWinPos[1], $aOldWinPos[2] - ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3] - ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_TR GUISetCursor(10, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aOldWinPos[0], MouseGetPos(1), $aOldWinPos[2] - ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3] + ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_BL GUISetCursor(10, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", MouseGetPos(0), $aOldWinPos[1], $aOldWinPos[2] + ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3] - ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_LM GUISetCursor(13, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", MouseGetPos(0), $aOldWinPos[1], $aOldWinPos[2] + ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3]) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_RM GUISetCursor(13, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aOldWinPos[0], $aOldWinPos[1], $aOldWinPos[2] - ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3]) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_TM GUISetCursor(11, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aOldWinPos[0], MouseGetPos(1), $aOldWinPos[2], $aOldWinPos[3] + ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_BM GUISetCursor(11, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aOldWinPos[0], $aOldWinPos[1], $aOldWinPos[2], $aOldWinPos[3] - ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case Else GUISetCursor(3, 1, $__g_hGUI_MarkArea) EndSwitch EndIf Until False EndFunc ;==>_GDIPlus_MarkScreenRegionAnimated Func UpdateCtrlPos($bAnim = True) Local Const $aGUIStartPos = WinGetPos($__g_hGUI_MarkArea) If $__g_bSelectionDone And $bAnim Then GUIRegisterMsg($WM_TIMER, "") $__g_iW = $aGUIStartPos[2] $__g_iH = $aGUIStartPos[3] ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_TL, 0, 0, $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_TM, ($__g_iW - $__g_iBorder) / 2, 0, $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_TR, ($__g_iW - $__g_iBorder - $__g_iBorder / 2), 0, $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_LM, 0, ($__g_iH - $__g_iBorder) / 2, $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_RM, ($__g_iW - $__g_iBorder - $__g_iBorder / 2), ($__g_iH - $__g_iBorder) / 2, $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_BL, 0, ($__g_iH - $__g_iBorder - $__g_iBorder / 2), $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_BM, ($__g_iW - $__g_iBorder) / 2, ($__g_iH - $__g_iBorder - $__g_iBorder / 2), $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_BR, ($__g_iW - $__g_iBorder - $__g_iBorder / 2), ($__g_iH - $__g_iBorder - $__g_iBorder / 2), $__g_iBorder, $__g_iBorder) If $__g_bSelectionDone And $bAnim Then GUIRegisterMsg($WM_TIMER, "PlayBorderAnim") EndFunc ;==>UpdateCtrlPos Func PlayBorderAnim() Local $aWinPos = WinGetClientSize($__g_hGUI_MarkArea), $iW = $aWinPos[0], $iH = $aWinPos[1] Local Static $fOffset = 0 Local Const $iSize = $__g_iBorder / 2 Local Const $hDC = _WinAPI_GetDC($__g_hGUI_MarkArea) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Local Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) Local Const $hPen = _GDIPlus_PenCreate(0xFF0178D7, $iSize), $hPen2 = _GDIPlus_PenCreate(0xFFFFFFFF, $iSize), _ $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000 + $__g_iColor_ResizeDots), $hPen3 = _GDIPlus_PenCreate(0xFF000000) _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDASHDOT) _GDIPlus_GraphicsClear($hCanvas, 0xFFABCDEF) ;for faster performance direct dll calls DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen2, "float", 1 + $iSize, "float", 1 + $iSize, "float", $iW - 2 * $iSize - 2, "float", $iH - 2 * $iSize - 2) DllCall($__g_hGDIPDll, "int", "GdipSetPenDashOffset", "handle", $hPen, "float", $fOffset) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen, "float", 1 + $iSize, "float", 1 + $iSize, "float", $iW - 2 * $iSize - 2, "float", $iH - 2 * $iSize - 2) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", 0, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", 0, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", ($iW - $__g_iBorder) / 2, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", ($iW - $__g_iBorder) / 2, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", ($iW - $__g_iBorder) - 2, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", ($iW - $__g_iBorder) - 2, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", 0, "float", ($iH - $__g_iBorder) / 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", 0, "float", ($iH - $__g_iBorder) / 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", ($iW - $__g_iBorder) - 2, "float", ($iH - $__g_iBorder) / 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", ($iW - $__g_iBorder) - 2, "float", ($iH - $__g_iBorder) / 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", 0, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", 0, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", ($iW - $__g_iBorder) / 2, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", ($iW - $__g_iBorder) / 2, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", ($iW - $__g_iBorder) - 2, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", ($iW - $__g_iBorder) - 2, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hDC_backbuffer, 0, 0, $SRCCOPY) $fOffset += 0.5 _GDIPlus_GraphicsDispose($hCanvas) _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _WinAPI_ReleaseDC($__g_hGUI_MarkArea, $hDC) _GDIPlus_PenDispose($hPen) _GDIPlus_PenDispose($hPen2) _GDIPlus_PenDispose($hPen3) _GDIPlus_BrushDispose($hBrush) EndFunc ;==>PlayBorderAnim Func WM_ERASEBKGND($hWnd, $iMsgm, $wParam, $lParam) ;suppress repainting to avoid flickering but causes some other side effects #forceref $iMsgm, $wParam, $lParam, $hWnd Local Const $hBrush = _WinAPI_CreateSolidBrush(0xEFCDAB) ;BGR format ;~ _WinAPI_RedrawWindow($__g_hGUI_MarkArea, 0, 0, BitOR($RDW_NOERASE, $RDW_NOCHILDREN, $RDW_NOFRAME, $RDW_VALIDATE)) _WinAPI_SetClassLongEx($__g_hGUI_MarkArea, $GCL_HBRBACKGROUND, $hBrush) _WinAPI_DeleteObject($hBrush) Return 0 EndFunc ;==>WM_ERASEBKGND ;https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setprocessdpiawarenesscontext Func _WinAPI_SetProcessDpiAwarenessContext($DPIAwareContext = $Context_PerMonitorAware, $hGUI = 0, $iMode = 3) ;https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setprocessdpiawarenesscontext $DPIAwareContext = ($DPIAwareContext < -5) ? -5 : ($DPIAwareContext > -1) ? -1 : $DPIAwareContext $iMode = ($iMode < 1) ? 1 : ($iMode > 3) ? 3 : $iMode Switch $iMode Case 1 Local $hDC = _WinAPI_GetDC($hGUI) Local $aResult1 = DllCall("user32.dll", "ptr", "GetDpiFromDpiAwarenessContext", "ptr", $hDC) If @error Or Not IsArray($aResult1) Then Return SetError(11, 0, 0) _WinAPI_ReleaseDC(0, $hDC) Local $aResult = DllCall("user32.dll", "Bool", "SetProcessDpiAwarenessContext", "int", $aResult1[0] + $DPIAwareContext) If @error Or Not IsArray($aResult) Then Return SetError(12, 0, 0) Case 2 ;~ If Not $hGUI Then $hGUI = WinGetHandle(AutoItWinGetTitle()) Local $aResult2 = DllCall("user32.dll", "int", "GetWindowDpiAwarenessContext", "ptr", $hGUI) If @error Or Not IsArray($aResult2) Then Return SetError(21, 0, 0) Local $aResult = DllCall("user32.dll", "Bool", "SetProcessDpiAwarenessContext", "int", $aResult2[0] + $DPIAwareContext) If @error Or Not IsArray($aResult) Then Return SetError(22, 0, 0) Case 3 Local $aResult31 = DllCall("user32.dll", "ptr", "GetThreadDpiAwarenessContext") If @error Or Not IsArray($aResult31) Then Return SetError(31, 0, 0) Local $aResult32 = DllCall("user32.dll", "ptr", "GetAwarenessFromDpiAwarenessContext", "ptr", $aResult31[0]) If @error Or Not IsArray($aResult32) Then Return SetError(32, 0, 0) Local $aResult = DllCall("user32.dll", "Bool", "SetThreadDpiAwarenessContext", "int", $aResult32[0] + $DPIAwareContext) If @error Or Not IsArray($aResult) Then Return SetError(33, 0, 0) EndSwitch Return 1 EndFunc ;==>_WinAPI_SetProcessDpiAwarenessContext  
      Just press the lmb and move your mouse. When lmb is released you can adjust the size of the window by dragging the white rectangle to any direction. Rmb will move the marked area.
      Press ESC to get the coordinates of the marked region.
      If you have any improvements, please post it here.
       
      Tested on Win10 x64 only.
       
    • By UEZ
      Here some graphical examples written completely in FreeBasic just for fun.  
      _WinAPI_SetWindowTitleIcon Check for Numeric Entry in an EditBox using RegEx CreateWindowEx (hGUI) Example FB 3D Starfield Rotating Flight FB File2Bas Code Generator FB Fire Particles FB Fireworks FB GFX Examples FB Image to Trapezoid Transformation FB Layered Parallax Effect FB Plasma FB Puristic Clock FB Rotating Cube FB Rotating Earth FB Rutt Etra Izer Effect FB Simple Recursive Tree Generator FB Snowfall FB Tunnel Flight FB Water Effect FMOD Examples GDI - GDI+ 3D Sinus Wave GDI - GDI+ Animated Pythagoras Tree GDI - GDI+ Bezier Lines GDI - GDI+ Particles - Repulsive Force Sim v2.0 GDI - GDI+ Plasma v5 Booster GDI - GDI+ Random Pattern GDI - GDI+ Space Flight GDI - GDI+ Tunnel Flight - WipeOut Style GDI Classic Raytraced Tunnel GDI Elastic Twister Effect GDI Exploding Pixels GDI Infinite Image Zoom Flight GDI Liquid Pixels GDI Mandelbrot GDI Particle Repulsion Grid GDI Particles Mouse Attraction GDI Starfield GDI The Nautilus Raymarcher GDI Worm Tunnel Flight GDI+ 3D Starfield Scrolling v1 Booster GDI+ 3D Starfield Scrolling v3 Booster GDI+ Convert Bitmap to ASCII GDI+ GIF Anim to ASCII Player GDI+ Image Painting GDI+ Impossible Possible GDI+ Kaleidoscope GDI+ Performance Test - Au3 vs FB GDI+ Polar Clock GDI+ Rotating Earth GDI+ Spiral Text GDI+ Star Wars Scroller GDI+ Streamer GDI+ Swiss Railway Clock GDI+ The MATRIX Ini Read - Write Rutt_Etra_Izer_Booster Stack TitchySID uFMOD  
      Download: FreeBasic Examples build 2019-05-08.rar
       
      I will add new examples from time to time.
       
      FreeBasic source codes are also included.
       
    • By Miliardsto
      hello Im wondering if it is possible to process image in autoit like this
      1. firstly there is colorfull wallpaper
      2. Fill all colors (exception rose color) - with white
      3. Fill rose color with black color
      I see Gdi functions have things to manipulate images
      https://imgur.com/a/lFdY26g
    • By badcoder123
      I was looking around the help file and I came across _GDIPlus_GraphicsDrawRect and _WinAPI_DrawLine and I seem to be having the same "problem" where every time it draws into a window and you lose or gain focus it has to redraw itself. Is there anyway around this? 
      #include <WindowsConstants.au3> #include <WinAPI.au3> #Include <GDIPlus.au3> _GDIPlus_Startup() Run("notepad.exe") $hWnd = WinWait("Untitled") $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) $Color = 0xFFFF0000 $hPen = _GDIPlus_PenCreate($Color, 2) For $i = 1 To 10 _GDIPlus_GraphicsDrawRect($hGraphic, 200, 200, 25 ,25, $hPen) ToolTip($i) Sleep(1000) Next _WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_PenDispose($hPen) _GDIPlus_Shutdown()  
    • By bhns
      try it for make flyers old games xml + Gdi, i belive many sources had lost 
      AIT-ADRLIST.au3

×
×
  • Create New...