Sign in to follow this  
Followers 0
UEZ

Pseudo Aero Look for WinXP (Glass Effect)

4 posts in this topic

#1 ·  Posted (edited)

Actually, I do not work with WinXP but by chance I discovered an effect.

This is experimentell only and not fully implemented!

Aero must be disabled (will done by script) on Vista+ os!

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

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global Const $hDwmApiDll = DllOpen("dwmapi.dll")
Global $sChkAero = DllStructCreate("int;")
DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero))
Global $aero = DllStructGetData($sChkAero, 1)
If $aero Then DllCall($hDwmApiDll, "int", "DwmEnableComposition", "uint", False)
Global $dy
If @OSBuild < 6000 Then
    Global $aTheme = _WinAPI_GetCurrentThemeName()
    If Not @error Then
        $dy = -54
    Else
        $dy = -40
    EndIf
Else
        $dy = -47
EndIf

_GDIPlus_Startup()

Global Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")
Global Const $aFullScreen = WinGetPos($hFullScreen)

Global Const $fW = 4
Global Const $fH = 32
Global Const $iW = 640
Global Const $iH = 400
Global Const $hGUI = GUICreate("", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_OVERLAPPEDWINDOW + $WS_EX_TOPMOST)
Global Const $idTitle = GUICtrlCreateLabel("Pseudo Aero Effect by UEZ", $fW + 16, $fh / 3, 150, 16)
GUICtrlSetFont(-1, 9, 800, 0, "Arial", 4)
GUICtrlSetBkColor(-1, -2)

Global Const $idLabel = GUICtrlCreateLabel(@LF & @LF & @LF & @TAB & "Done by UEZ 2011", $fW, $fH, $iW - 2 * $fW - 2, $iH - $fH - $fW)
GUICtrlSetFont(-1, 30, 400, 0, "Arial", 4)
GUICtrlSetBkColor(-1, -2)
Global Const $idLabel_Min = GUICtrlCreateLabel("[_]", $iW - 50, $fH / 3, $fh / 2, $fh / 2)
GUICtrlSetBkColor(-1, -2)
Global Const $idLabel_Close = GUICtrlCreateLabel("[X]", $iW - 30, $fH / 3, $fh / 2, $fh / 2)
GUICtrlSetBkColor(-1, -2)

WinSetTrans($hGUI, "", 0xFF)

Global Const $hGUI_Hidden = GUICreate("", $iW, $iH, 0, 0, Default, $WS_EX_MDICHILD + $WS_EX_LAYERED, $hGUI)
GUISetState(@SW_HIDE, $hGUI_Hidden)
GUISetState(@SW_SHOW, $hGUI)
_SetGuiRoundCorners($hGUI, 16, True, False, True, False)


Global $hDev = _WinAPI_GetDC($hGUI)
Global $hDC_Area = _WinAPI_CreateCompatibleDC($hDev)
Global $hBitmap_Area = _WinAPI_CreateCompatibleBitmap($hDev, $aFullScreen[2], $aFullScreen[3])


Global Const $hDC_Zoom = _WinAPI_GetDC(0)
Global Const $hGUI_ZoomDC = _WinAPI_GetDC($hGUI_Hidden)

Global Const $memDC = _WinAPI_CreateCompatibleDC($hGUI_ZoomDC)
Global Const $memBmp = _WinAPI_CreateCompatibleBitmap($hGUI_ZoomDC, $iW, $iH)
_WinAPI_SelectObject($memDC, $memBmp)

Global $aPos = WinGetPos($hGUI)
_WinAPI_StretchBlt($hGUI_ZoomDC, 0, 0, $iW, $iH, $hDC_Zoom, $aPos[0], $aPos[1], $iW, $iH, $SRCCOPY)

_WinAPI_BitBlt($memDC, 0, 0, $iW, $iH, $hGUI_ZoomDC, 0, $dy, 0x00CC0020)

Global Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global Const $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphic)
Global Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

Global Const $GW_CHILD = 5
Global Const $GW_HWNDNEXT = 2
Global $hRegion = _GDIPlus_RegionCreateFromRect(_GDIPlus_RectFCreate(0, 0, $iW, $iH))
Global $hChild = _WinAPI_GetWindow($hGUI, $GW_CHILD)
Global $aRect, $msg

Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, _GDIPlus_RectFCreate($aRect[0], $aRect[1], $aRect[2], $aRect[3]), 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGraphic, $hRegion)
_GDIPlus_RegionDispose($hRegion)

Global $tRectF = _GDIPlus_RectFCreate(0, 0, $iW / 1.5, $iH / 1.5)
Global $hBrush = _GDIPlus_LineBrushCreateFromRectWithAngle($tRectF, 0x80201010, 0xA0F0F0F0, -60, False, 1)

Global $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($memBmp)
Global $hBmp_Blur = _Blur($hBmp, $iW, $iH)
_GDIPlus_GraphicsDrawImage($hContext, $hBmp_Blur, 0, 0)

_GDIPlus_GraphicsFillRect($hContext, 0, 0, $iW, $iH, $hBrush)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH)
_GDIPlus_BitmapDispose($hBmp)
_GDIPlus_BitmapDispose($hBmp_Blur)

GUIRegisterMsg($WM_WINDOWPOSCHANGED, "WM_WINDOWPOSCHANGED")
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

Global $exit = False

GUISetOnEvent($GUI_EVENT_RESTORE, "Restored", $hGUI)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $hGUI)
GUICtrlSetOnEvent($idLabel_Close, "_Exit")
GUICtrlSetOnEvent($idLabel_Min, "_MinWin")

While Sleep(30)
;~  Repaint()
    If $exit Then ExitLoop
WEnd

GUIRegisterMsg($WM_WINDOWPOSCHANGED, "")
_WinAPI_DeleteDC($memDC)
_WinAPI_DeleteObject($memBmp)
_WinAPI_DeleteObject($hBitmap_Area)
_WinAPI_ReleaseDC($hGUI, $hDev)
_WinAPI_ReleaseDC($hGUI, $hGUI_ZoomDC)
_WinAPI_ReleaseDC(0, $hDC_Zoom)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
GUIDelete()
$tRectF = 0
If $aero Then DllCall($hDwmApiDll, "int", "DwmEnableComposition", "uint", True)
Exit

Func _Exit()
    $exit = True
EndFunc

Func _MinWin()
    GUISetState(@SW_MINIMIZE, $hGUI)
EndFunc

Func Restored()
    Repaint()
EndFunc

Func WM_WINDOWPOSCHANGED($hWnd, $iMsg, $StartWIndowPosaram, $lParam)
    Repaint()
    Return "GUI_RUNDEFMSG"
EndFunc

Func Repaint()
    $aPos = WinGetPos($hGUI)
    _WinAPI_StretchBlt($hGUI_ZoomDC, 0, 0, $iW, $iH, $hDC_Zoom, $aPos[0]+16, $aPos[1] + 3, $iW, $iH, $SRCCOPY)
    _WinAPI_BitBlt($memDC, 0, 0, $iW, $iH, $hGUI_ZoomDC, 0, $dy, 0x00CC0020)
    DllStructSetData($tRectF, "X", $aPos[0])
    DllStructSetData($tRectF, "Y", $aPos[1])
    $hBrush = _GDIPlus_LineBrushCreateFromRectWithAngle($tRectF, 0x80302020, 0xA0F0F0F0, -60, False, 1)
    $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($memBmp)
    $hBmp_Blur = _Blur($hBmp, $iW, $iH)
    _GDIPlus_GraphicsDrawImage($hContext, $hBmp_Blur, 0, 0)
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $iW, $iH, $hBrush)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH)
    _GDIPlus_BitmapDispose($hBmp)
    _GDIPlus_BitmapDispose($hBmp_Blur)
    _GDIPlus_BrushDispose($hBrush)
EndFunc

Func WM_NCHITTEST($hWndGUI, $MsgID, $WParam, $LParam)
    If ($hWndGUI = $hGui) And ($MsgID = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

Func _Blur($hBitmap, $iW, $iH, $fScale = 0.30, $qual = 6); by eukalyptus
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
    Local $hBmpSmall = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
    Local $hGfxSmall = _GDIPlus_ImageGetGraphicsContext($hBmpSmall)
    DllCall($ghGDIPDll, "uint", "GdipSetPixelOffsetMode", "hwnd", $hGfxSmall, "int", 2)
    Local $hBmpBig = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
    Local $hGfxBig = _GDIPlus_ImageGetGraphicsContext($hBmpBig)
    DllCall($ghGDIPDll, "uint", "GdipSetPixelOffsetMode", "hwnd", $hGfxBig, "int", 2)
    _GDIPlus_GraphicsScaleTransform($hGfxSmall, $fScale, $fScale)
    _GDIPlus_GraphicsSetInterpolationMode($hGfxSmall, $qual)

    _GDIPlus_GraphicsScaleTransform($hGfxBig, 1 / $fScale, 1 / $fScale)
    _GDIPlus_GraphicsSetInterpolationMode($hGfxBig, $qual)

    _GDIPlus_GraphicsDrawImageRect($hGfxSmall, $hBitmap, 0, 0, $iW, $iH)
    _GDIPlus_GraphicsDrawImageRect($hGfxBig, $hBmpSmall, 0, 0, $iW, $iH)

    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBmpSmall)
    _GDIPlus_GraphicsDispose($hGfxSmall)
    _GDIPlus_GraphicsDispose($hGfxBig)
    Return $hBmpBig
EndFunc   ;==>_Blur

Func _WinAPI_StretchBlt($hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iRop)
    Local $Ret = DllCall("gdi32.dll", "int", "StretchBlt", "hwnd", $hDestDC, "int", $iXDest, "int", $iYDest, "int", $iWidthDest, "int", $iHeightDest, "hwnd", $hSrcDC, "int", $iXSrc, "int", $iYSrc, "int", $iWidthSrc, "int", $iHeightSrc, "dword", $iRop)
    If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
    Return 1
EndFunc   ;==>_WinAPI_StretchBlt

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_GetCurrentThemeName
; Description....: Retrieves the name of the current visual styles, color scheme name, and size name.
; Syntax.........: _WinAPI_GetCurrentThemeName ( )
; Parameters.....: None
; Return values..: Success - The array that contains the following information:
;
;                           [0] - The theme path and file name.
;                           [1] - The color scheme name.
;                           [2] - The size name.
;
;                 Failure - 0 and sets the @error flag to non-zero, @extended flag may contain the system error code.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........:
; Link...........: @@MsdnLink@@ GetCurrentThemeName
; Example........: Yes
; ===============================================================================================================================
Func _WinAPI_GetCurrentThemeName()
    Local $Ret = DllCall('uxtheme.dll', 'uint', 'GetCurrentThemeName', 'wstr', '', 'int', 4096, 'wstr', '', 'int', 2048, 'wstr', '', 'int', 2048)
    If @error Then
        Return SetError(1, 0, 0)
    Else
        If $Ret[0] Then
            Return SetError(1, $Ret[0], 0)
        EndIf
    EndIf
    Local $Result[3]
    For $i = 0 To 2
        $Result[$i] = $Ret[$i * 2 + 1]
    Next
    Return $Result
EndFunc   ;==>_WinAPI_GetCurrentThemeName

Func _SetGuiRoundCorners($hGUI, $iEllipse, $iLeftUp = True, $iLeftDown = True, $iRightUp = True, $iRightDown = True)
    Local $hCornerRgn
    Local $aGuiSize = WinGetPos($hGUI)
    Local $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $aGuiSize[2], $aGuiSize[3], $iEllipse, $iEllipse)
    If $iLeftUp = False Then
        $hCornerRgn = _WinAPI_CreateRectRgn(0, 0, $aGuiSize[2] / 2, $aGuiSize[3] / 2)
        _WinAPI_CombineRgn($hRgn, $hRgn, $hCornerRgn, $RGN_OR)
        _WinAPI_DeleteObject($hCornerRgn)
    EndIf
    If $iLeftDown = False Then
        $hCornerRgn = _WinAPI_CreateRectRgn(0, $aGuiSize[3] / 2, $aGuiSize[2] / 2, $aGuiSize[3])
        _WinAPI_CombineRgn($hRgn, $hRgn, $hCornerRgn, $RGN_OR)
        _WinAPI_DeleteObject($hCornerRgn)
    EndIf
    If $iRightUp = False Then
        $hCornerRgn = _WinAPI_CreateRectRgn($aGuiSize[2] / 2, 0, $aGuiSize[2], $aGuiSize[3] / 2)
        _WinAPI_CombineRgn($hRgn, $hRgn, $hCornerRgn, $RGN_OR)
        _WinAPI_DeleteObject($hCornerRgn)
    EndIf
    If $iRightDown = False Then
        $hCornerRgn = _WinAPI_CreateRectRgn($aGuiSize[2] / 2, $aGuiSize[3] / 2, $aGuiSize[2] - 1, $aGuiSize[3] - 1)
        _WinAPI_CombineRgn($hRgn, $hRgn, $hCornerRgn, $RGN_OR)
        _WinAPI_DeleteObject($hCornerRgn)
    EndIf
    _WinAPI_SetWindowRgn($hGUI, $hRgn)
EndFunc   ;==>_SetGuiRoundCorners

#region additional GDI+ functions
Func _GDIPlus_GraphicsScaleTransform($hGraphics, $nScaleX, $nScaleY, $iOrder = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipScaleWorldTransform", "hwnd", $hGraphics, "float", $nScaleX, "float", $nScaleY, "int", $iOrder)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsScaleTransform

Func _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGraphics, "int", $iInterpolationMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsSetInterpolationMode

Func _GDIPlus_LineBrushCreateFromRectWithAngle($tRectF, $iARGBClr1, $iARGBClr2, $nAngle, $fIsAngleScalable = True, $iWrapMode = 0)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrushFromRectWithAngle", "ptr", $pRectF, "uint", $iARGBClr1, "uint", $iARGBClr2, "float", $nAngle, "int", $fIsAngleScalable, "int", $iWrapMode, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[7]
EndFunc   ;==>_GDIPlus_LineBrushCreateFromRectWithAngle

Func _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion, $iCombineMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipRegion", "hwnd", $hGraphics, "hwnd", $hRegion, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc

Func _GDIPlus_RegionCreateFromRect($tRectF)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateRegionRect", "ptr", $pRectF, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc

Func _GDIPlus_RegionCombineRect($hRegion, $tRectF, $iCombineMode = 2)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCombineRegionRect", "hwnd", $hRegion, "ptr", $pRectF, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc

Func _GDIPlus_RegionDispose($hRegion)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteRegion", "hwnd", $hRegion)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc
#endregion

If you have the classic theme activate adjust -52 to -38 in _WinAPI_BitBlt($memDC, 0, 0, $iW, $iH, $hGUI_ZoomDC, 0, -52, 0x00CC0020) lines!

Btw, how can I check whether classical or Luna theme is activated?

Limitations:

  • only updates when window is moved
  • no transparent labels
  • relatively slow
Screenshot, short AVI video and optimized version by eukalyptus here: AutoIt.de

Maybe this effect comes 4 years too late...

Br,

UEZ

Edited by UEZ
1 person likes this

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



#3 ·  Posted (edited)

Nice Example UEZ ! :D

Did you look at _WinAPI_GetCurrentThemeName() for get the name of the current visual styles ?

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

@wakillon: thanks for the hint. Code updated in post#1.

Btw, eukalyptus optimized the code whereas you don't need to check the theme to display the effect properly in the window (link in post#1)!

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

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  
Followers 0

  • Similar Content

    • c.haslam
      By c.haslam
      sometimes!
      Running the script below and entering a for All seems to work every time Running it and choosing 1 for One returns a gibberish string However with the same functions, I have seen it succeed when 1 is chosen, i.e. show the value for the test property ID 0x0103 as OLYMPUS DIGITAL CAMERA I have also seen GetOne() succeed when a diagnostic MsgBox() is added,  and when I include my debugging functions, so the problem appears to be a memory location being overwritten, probably in a DLLStruct.. call.
      I know that value OLYMPUS DIGITAL CAMERA is correct from Irfanview and from running GetAll().
      All but one of the _GDIPlus functions were written by ChrisL. I have modified those that returned a DLLStruct object such that they now return an array.
      Both getting one and getting  all involve calling _GDIPlus_ImageGetPropertyItemValue() which I wrote, so perhaps the problem partly lies with ChrisL's functions as modified.
      Suggestions?
      #include <GDIPlus.au3> #include <Array.au3> Opt('MustDeclareVars',1) ; #VARIABLES# =================================================================================================================== Global $GDIP_STATUS = 0 Global $GDIP_ERROR = 0 ; =============================================================================================================================== ; Property Item structure Global Const $tagGDIPPROPERTYITEM = _ "uint id;" & _ ; ID of this property "uint length;" & _ ; Length of the property value, in bytes "ushort type;" & _ ; Type of the value, as one of TAG_TYPE_XXX constants "ptr value;" ; property value ; Image property types constants ; Ref: https://www.media.mit.edu/pia/Research/deepview/exif.html Global Const $GDIP_PROPERTYTAGTYPEUBYTE = 1 Global Const $GDIP_PROPERTYTAGTYPEASCII = 2 Global Const $GDIP_PROPERTYTAGTYPEUSHORT = 3 Global Const $GDIP_PROPERTYTAGTYPEULONG = 4 Global Const $GDIP_PROPERTYTAGTYPEURATIONAL = 5 Global Const $GDIP_PROPERTYTAGTYPESBYTE = 6 Global Const $GDIP_PROPERTYTAGTYPEUNDEFINED = 7 Global Const $GDIP_PROPERTYTAGTYPESSHORT = 8 Global Const $GDIP_PROPERTYTAGTYPESLONG = 9 Global Const $GDIP_PROPERTYTAGTYPESRATIONAL = 10 Global Const $GDIP_PROPERTYTAGTYPESFLOAT = 11 Global Const $GDIP_PROPERTYTAGTYPEDFLOAT = 12 main() Func main() _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile('H:\b\PA160005 - Copy.JPG') Local $sAns = InputBox('','Enter 1 or a') If $sAns=1 Then GetOne($hImage) ElseIf $sAns='a' Then GetAll($hImage) EndIf _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() EndFunc Func GetOne($hImage) Local $vecPrim = _GDIPlus_ImageGetPropertyItem($hImage,0x010e) Local $vecUser[3] $vecUser[0] = '0x'&StringRight(Hex($vecPrim[0]),4) $vecUser[1] = $vecPrim[2] Local $vecVals = _GDIPlus_ImageGetPropertyItemValue($vecPrim[1],$vecPrim[2],$vecPrim[3]) $vecUser[2] = $vecVals[0] _ArrayDisplay($vecUser) EndFunc Func GetAll($hImage) Local $ar1 = _GDIPlus_ImageGetAllPropertyItems($hImage) Local $ar[UBound($ar1,1)][3] For $i = 1 To $ar1[0][0] $ar[$i][0] = '0x'&StringRight(Hex($ar1[$i][0]),4) $ar[$i][1] =$ar1[$i][2] $ar[$i][2] = (_GDIPlus_ImageGetPropertyItemValue($ar1[$i][1],$ar1[$i][2],$ar1[$i][3]))[0] Next _ArrayDisplay($ar) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetAllPropertyItems ; Description ...: Gets all the property items (metadata) stored in an Image object ; Syntax.........: _GDIPlus_ImageGetAllPropertyItems($hImage) ; Parameters ....: $hImage - Pointer to an Image object ; Return values .: Success - Array containing the image property items: ; |[0][0] - Number of property items ; |[1][0] - Property item 1 identifier (see remarks) ; |[1][1] - Property item 1 value length, in bytes ; |[1][2] - Property item 1 value type ; |[1][1] - Property item 1 value pointer ; |. ; |. ; |[n][0] - Property item n identifier ; |[n][1] - Property item n value length, in bytes ; |[n][2] - Property item n value type ; |[n][1] - Property item n value pointer ; Possible property value types are: ; |1 - The value pointer points to an array of bytes ; |2 - The value pointer points to a null-terminated ASCII string ; |3 - The value pointer points to unsigned short ; |4 - The value pointer points to an unsigned long ; |5 - The value pointer points to an array of unsigned two longs (numerator, denominator) ; |7 - The value pointer points to an array of bytes of any type, or is unterminated string\ ; |8 - The value pointer points to signed short ; |9 - The value pointer points to a signed long ; |10 - The value pointer points to an array of signed two longs (numerator, denominator) ; |11 - The value pointer points to a float ; |12 - The value pointer points to a double ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; |$GDIP_ERROR: ; | 1 - The _GDIPlus_ImageGetPropertySize function failed, $GDIP_STATUS contains the error code ; | 2 - The image contains no property items metadata ; | 3 - The _GDIPlus_ImageGetAllPropertyItems function failed, $GDIP_STATUS contains the error code ; Author.........: Authenticity ; Modified.......: c.haslam ; Remarks .......: The property item tag identifiers are declared in GDIPConstants.au3, those that start with $GDIP_PROPERTYTAG ; +The value size is given in bytes, divide this by the size of the data (4 for integers, 2 for shorts, etc..) ; Related .......: _GDIPlus_ImageGetPropertySize, _GDIPlus_ImageGetPropertyItemValue, _GDIPlus_ImageGetAllPropertyItems ; Link ..........; @@MsdnLink@@ GdipGetAllPropertyItems ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetAllPropertyItems($hImage) Local $iI, $iCount, $tBuffer, $pBuffer, $iBuffer, $tPropertyItem, $aSize, $aPropertyItems[1][1], $aResult $aSize = _GDIPlus_ImageGetPropertySize($hImage) If @error Then Return SetError(@error, @extended, -1) If $GDIP_STATUS Then $GDIP_ERROR = 1 Return -1 ElseIf $aSize[1] = 0 Then $GDIP_ERROR = 2 Return -1 EndIf $iBuffer = $aSize[0] $tBuffer = DllStructCreate("byte[" & $iBuffer & "]") $pBuffer = DllStructGetPtr($tBuffer) $iCount = $aSize[1] $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetAllPropertyItems", "hwnd", $hImage, "uint", $iBuffer, "uint", $iCount, "ptr", $pBuffer) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then $GDIP_ERROR = 3 Return -1 EndIf ReDim $aPropertyItems[$iCount + 1][4] $aPropertyItems[0][0] = $iCount For $iI = 1 To $iCount $tPropertyItem = DllStructCreate($tagGDIPPROPERTYITEM, $pBuffer) $aPropertyItems[$iI][0] = DllStructGetData($tPropertyItem, "id") $aPropertyItems[$iI][1] = DllStructGetData($tPropertyItem, "length") $aPropertyItems[$iI][2] = DllStructGetData($tPropertyItem, "type") $aPropertyItems[$iI][3] = DllStructGetData($tPropertyItem, "value") $pBuffer += DllStructGetSize($tPropertyItem) Next Return $aPropertyItems EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GDIPlus_ImageGetPropertyItemValue ; Description ...: Get property item values from fields in $tagGDIPPROPERTYITEM data ; Syntax ........: _GDIPlus_ImageGetPropertyItemValue($iLength, $iType, $pValue) ; Parameters ....: $iLength Length of the property value, in bytes ; |$iType Type of the value (a $GDIP_PROPERTYTAGTYPE* value - see GDIPConstants.au3) ; |$pValue Pointer to value ; Return values .: Success - An array ; | [0] value 1 ; | [1] value 2 (only for properties that have numerator and denominator) ; Failure - -1 ; Author ........: c.haslam ; Modified ......: ; Remarks........: If type is 7 ($GDIP_PROPERTYTAGTYPEUNDEFINED) value returned is an unsigned long. ; Depending on ID and originator of the image, value may actually be an unterminated string ; Related .......: _GDIPlus_ImageGetPropertyItem,_GDIPlus_ImageGetAllPropertyItems ; Link ..........: http://www.cipa.jp/std/documents/e/DC-008-Translation-2016-E.pdf, ; https://www.media.mit.edu/pia/Research/deepview/exif.html ; Example .......: No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyItemValue($iLength, $iType, $pValue) Switch $iType Case $GDIP_PROPERTYTAGTYPEURATIONAL,$GDIP_PROPERTYTAGTYPESRATIONAL Local $aRet[2] Case Else Local $aRet[1] EndSwitch Switch $iType Case $GDIP_PROPERTYTAGTYPEUBYTE,$GDIP_PROPERTYTAGTYPESBYTE Local $tvalue = DllStructCreate('byte val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEASCII Local $tvalue = DllStructCreate('char val['&$iLength&']',$pValue) If @error Then MsgBox(0,@ScriptLineNumber,'@error='&@error) $aRet[0] = DllStructGetData($tvalue,'val') If @error Then MsgBox(0,@ScriptLineNumber,'@error='&@error) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEUSHORT Local $tvalue = DllStructCreate('ushort val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEULONG Local $tvalue = DllStructCreate('ulong val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEURATIONAL Local $tvalue = DllStructCreate('ulong val1;ulong val2',$pValue) $aRet[0] = $tvalue.val1 $aRet[1] = $tvalue.val2 Case $GDIP_PROPERTYTAGTYPESBYTE Local $tvalue = DllStructCreate('byte val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEUNDEFINED ; undefined, per specification, but may be a long but is sometimes a string Local $tvalue = DllStructCreate('ulong val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPESSHORT Local $tvalue = DllStructCreate('short val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEULONG Local $tvalue = DllStructCreate('ulong val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPESRATIONAL Local $tvalue = DllStructCreate('long val1;long val2',$pValue) $aRet[0] = $tvalue.val1 $aRet[1] = $tvalue.val2 Case $GDIP_PROPERTYTAGTYPESFLOAT Local $tvalue = DllStructCreate('float val',$pValue) $aRet[0] = $tvalue.val Case $GDIP_PROPERTYTAGTYPEDFLOAT Local $tvalue = DllStructCreate('double val',$pValue) $aRet[0] = $tvalue.val EndSwitch $tvalue = 0 Return $aRet EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyItem ; Description ...: Gets a specified property item (piece of metadata) from an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyItem($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an Image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success - Array ; | [0] Property ID ; | [1] Property length ; | [2] Property type ; | [3] pointer to Property value ; Possible values of type are: ; |1 - The value pointer points to an array of bytes ; |2 - The value pointer points to a null-terminated ASCII string ; |3 - The value pointer points to unsigned short ; |4 - The value pointer points to an unsigned long ; |5 - The value pointer points to an array of unsigned two longs (numerator, denominator) ; |7 - The value pointer points to an array of bytes of any type, or is unterminated string\ ; |8 - The value pointer points to signed short ; |9 - The value pointer points to a signed long ; |10 - The value pointer points to an array of signed two longs (numerator, denominator) ; |11 - The value pointer points to a float ; |12 - The value pointer points to a double ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non-zero value specifying the error code ; |$GDIP_ERROR: ; | 1 - The _GDIPlus_ImageGetPropertyItemSize function failed, $GDIP_STATUS contains the error code ; | 2 - The specified property identifier does not exist in the image ; | 3 - The _GDIPlus_ImageGetPropertyItem function failed, $GDIP_STATUS contains the error code ; Author.........: Authenticity ; Modified.......: c.haslam ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetPropertyIdList, _GDIPlus_ImageGetPropertyItemSize, _GDIPlus_ImageGetPropertyItemValue, ; $tagGDIPPROPERTYITEM ; Link ..........; @@MsdnLink@@ GdipGetPropertyItem http://www.cipa.jp/std/documents/e/DC-008-Translation-2016-E.pdf, ; https://www.media.mit.edu/pia/Research/deepview/exif.html ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyItem($hImage, $iPropID) Local $iBuffer, $tBuffer, $pBuffer, $tPropertyItem, $aResult $iBuffer = _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) If @error Then Return SetError(@error, @extended, -1) If $GDIP_STATUS Then $GDIP_ERROR = 1 Return -1 ElseIf $iBuffer = 0 Then $GDIP_ERROR = 2 Return -1 EndIf $tBuffer = DllStructCreate("byte[" & $iBuffer & "]") $pBuffer = DllStructGetPtr($tBuffer) $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyItem", "hwnd", $hImage, "uint", $iPropID, "uint", $iBuffer, "ptr", $pBuffer) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then $GDIP_ERROR = 3 Return -1 EndIf Local $tPropertyItem = DllStructCreate($tagGDIPPROPERTYITEM, $pBuffer) Local $aRet = [$tPropertyItem.id, $tPropertyItem.length,$tPropertyItem.type, $tPropertyItem.value] Return $aRet EndFunc ;==>_GDIPlus_ImageGetPropertyItem ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertySize ; Description ...: Gets the total size, in bytes, and the number of all the property items stored in an Image object ; Syntax.........: _GDIPlus_ImageGetPropertySize($hImage) ; Parameters ....: $hImage - Pointer to an Image object ; Return values .: Success - Array containing the total size and the number of property items: ; |[0] - Total size, in bytes, of the property items ; |[1] - Number of the property items ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Author.........: Authenticity ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetPropertyIdList, _GDIPlus_ImageGetPropertyItem ; Link ..........; @@MsdnLink@@ GdipGetPropertyItemSize ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertySize($hImage) Local $aSize[2], $aResult $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertySize", "hwnd", $hImage, "uint*", 0, "uint*", 0) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then Return -1 $aSize[0] = $aResult[2] $aSize[1] = $aResult[3] Return $aSize EndFunc ;==>_GDIPlus_ImageGetPropertySize ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyItemSize ; Description ...: Gets the size, in bytes, of a specified property item of an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an Image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success - $tagGDIPPROPERTYITEM structure containing the property size, type and value pointer ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Author.........: Authenticity ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetPropertyIdList, _GDIPlus_ImageGetPropertyItem ; Link ..........; @@MsdnLink@@ GdipGetPropertyItemSize ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyItemSize", "hwnd", $hImage, "uint", $iPropID, _ "uint*", 0) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then Return -1 Return $aResult[3] EndFunc ;==>_GDIPlus_ImageGetPropertyItemSize  
    • c.haslam
      By c.haslam
      The following code is one of my many attempts to get the value of a string property from an image. It doesn't work. I know that IMAGEDESCRIPTION has a string value.
      In one of my many attempts, I did get the string OLYMPUS .., which I know is correct from IrfanView, but I can't get it again.
      How should I get this string?
       
      #include <GDIPlus.au3> Opt('MustDeclareVars',1) ; Property Item structure Global Const $tagGDIPPROPERTYITEM = _ "uint id;" & _ ; ID of this property "uint length;" & _ ; Length of the property value, in bytes "ushort type;" & _ ; Type of the value, as one of TAG_TYPE_XXX constants "ptr value;" ; property value Global Const $GDIP_PROPERTYTAGIMAGEDESCRIPTION = 0x010E ; #VARIABLES# =================================================================================================================== Global $ghGDIPMatrix = 0 Global $GDIP_STATUS = 0 Global $GDIP_ERROR = 0 Local $Dsk_ghImage _GDIPlus_Startup() $Dsk_ghImage = _GDIPlus_ImageLoadFromFile('H:\b\PA160005 - Copy.JPG') Local $propListVec = _GDIPlus_ImageGetPropertyIdList($Dsk_ghImage) Local $qProps = $propListVec[0] For $i = 1 To $qProps $propListVec[$i] = Hex($propListVec[$i]) While StringLeft($propListVec[$i],1)='0' $propListVec[$i] = StringMid($propListVec[$i],2) WEnd ConsoleWrite($propListVec[$i]&@CRLF) Next Local $tProp = _GDIPlus_ImageGetPropertyItem($Dsk_ghImage,$GDIP_PROPERTYTAGIMAGEDESCRIPTION) Local $len = $tProp.length Local $s = 'char str['&$len&']' Local $ptr = $tProp.value Local $tStr = DllStructCreate($s,$ptr) MsgBox(0,'@error',@error) Local $strval = DllStructGetData($tStr,'str') MsgBox(0,'','@error '&@error&' strval '&$strval) ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyIdList ; Description ...: Gets a list of the property identifiers used in the metadata of an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyIdList($hImage) ; Parameters ....: $hImage - Pointer to an Image object ; Return values .: Success - Array of property identifiers: ; |[0] - Number of property identifiers ; |[1] - Property identifier 1 ; |[2] - Property identifier 2 ; |[n] - Property identifier n ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; |$GDIP_ERROR: ; | 1 - The _GDIPlus_ImageGetPropertyCount function failed, $GDIP_STATUS contains the error code ; | 2 - The image does not contain any property items ; | 3 - The _GDIPlus_ImageGetPropertyIdList function failed, $GDIP_STATUS contains the error code ; Author.........: Authenticity ; Remarks .......: The property item identifiers are declared in GDIPConstants.au3, those that start with $GDIP_PROPERTYTAGN* ; Related .......: _GDIPlus_ImageGetAllPropertyItems, _GDIPlus_ImageGetPropertyCount, _GDIPlus_ImageGetPropertyItem ; Link ..........; @@MsdnLink@@ GdipGetPropertyIdList ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyIdList($hImage) Local $iI, $iCount, $tProperties, $pProperties, $aProperties[1], $aResult $iCount = _GDIPlus_ImageGetPropertyCount($hImage) If @error Then Return SetError(@error, @extended, -1) If $GDIP_STATUS Then $GDIP_ERROR = 1 Return -1 ElseIf $iCount = 0 Then $GDIP_ERROR = 2 Return -1 EndIf $tProperties = DllStructCreate("uint[" & $iCount & "]") $pProperties = DllStructGetPtr($tProperties) $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyIdList", "hwnd", $hImage, "int", $iCount, "ptr", $pProperties) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then $GDIP_ERROR = 3 Return -1 EndIf ReDim $aProperties[$iCount + 1] $aProperties[0] = $iCount For $iI = 1 To $iCount $aProperties[$iI] = DllStructGetData($tProperties, 1, $iI) Next Return $aProperties EndFunc ;==>_GDIPlus_ImageGetPropertyIdList ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyItem ; Description ...: Gets a specified property item (piece of metadata) from an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyItem($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an Image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success - $tagGDIPPROPERTYITEM structure containing the property size, type and value pointer ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; |$GDIP_ERROR: ; | 1 - The _GDIPlus_ImageGetPropertyItemSize function failed, $GDIP_STATUS contains the error code ; | 2 - The specified property identifier does not exist in the image ; | 3 - The _GDIPlus_ImageGetPropertyItem function failed, $GDIP_STATUS contains the error code ; Author.........: Authenticity ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetPropertyIdList, _GDIPlus_ImageGetPropertyItemSize, $tagGDIPPROPERTYITEM ; Link ..........; @@MsdnLink@@ GdipGetPropertyItem ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyItem($hImage, $iPropID) Local $iBuffer, $tBuffer, $pBuffer, $tPropertyItem, $aResult $iBuffer = _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) If @error Then Return SetError(@error, @extended, -1) If $GDIP_STATUS Then $GDIP_ERROR = 1 Return -1 ElseIf $iBuffer = 0 Then $GDIP_ERROR = 2 Return -1 EndIf $tBuffer = DllStructCreate("byte[" & $iBuffer & "]") $pBuffer = DllStructGetPtr($tBuffer) $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyItem", "hwnd", $hImage, "uint", $iPropID, "uint", $iBuffer, "ptr", $pBuffer) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then $GDIP_ERROR = 3 Return -1 EndIf $tPropertyItem = DllStructCreate($tagGDIPPROPERTYITEM, $pBuffer) Return $tPropertyItem EndFunc ;==>_GDIPlus_ImageGetPropertyItem ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyCount ; Description ...: Gets the number of properties (pieces of metadata) stored in an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyCount($hImage) ; Parameters ....: $hImage - Pointer to an Image object ; Return values .: Success - Number of property items store in the Image object ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Author.........: Authenticity ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetAllPropertyItems, _GDIPlus_ImageGetPropertyIdList ; Link ..........; @@MsdnLink@@ GdipGetPropertyCount ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyCount($hImage) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyCount", "hwnd", $hImage, "uint*", 0) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then Return -1 Return $aResult[2] EndFunc ;==>_GDIPlus_ImageGetPropertyCount ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_ImageGetPropertyItemSize ; Description ...: Gets the size, in bytes, of a specified property item of an Image object ; Syntax.........: _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an Image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success - $tagGDIPPROPERTYITEM structure containing the property size, type and value pointer ; Failure - -1 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Author.........: Authenticity ; Remarks .......: None ; Related .......: _GDIPlus_ImageGetPropertyIdList, _GDIPlus_ImageGetPropertyItem ; Link ..........; @@MsdnLink@@ GdipGetPropertyItemSize ; Example .......; No ; =============================================================================================================================== Func _GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertyItemSize", "hwnd", $hImage, "uint", $iPropID, "uint*", 0) If @error Then Return SetError(@error, @extended, -1) $GDIP_STATUS = $aResult[0] If $GDIP_STATUS Then Return -1 Return $aResult[3] EndFunc ;==>_GDIPlus_ImageGetPropertyItemSize  
    • c.haslam
      By c.haslam
      I have found that:
      there are 276 functions in Authenticity's GDIP.au3 (written for 3.3.6.1) that are not in 3.3.14.2's GDIPlus.au3.  there are many constants in his GDIPConstants.au3 that are not in 3.3.14.2's GDIPlus.au3, but there are some that are. So:
      GDIP extras.au3 contains functions that are not in GDIPlus.au3. They have been extracted from GDIP.au3 The revised GDIPConstants.au3 has constants that are duplicates of those in GDIPlus.au3 commented out. They are attached.
      I have done limited testing on 3.3.14.2 with GDIP extras.au3 and the revised GDIPConstants.au3 included.
      I have undertaken this effort in thanks for the help with GDI+ that I have received on this form, especially from UEZ.
      Authenticity's thread is here. For those who do not 7zip, I am attaching his GDIP as a zip file. It contains many examples.
      GDIP33142.zip
      GDIPAuthenticity.zip
    • NHD
      By NHD
      Hi,
      I've been translated code from FreeBasic to AutoIt. And it didn't work correctly.
      Please help me!
      FreeBasic:
      #Include Once "windows.bi" #Define _RGB(r,g,b) BGR(b,g,r) CONST GRADIENT_FILL_RECT_H = 0 CONST GRADIENT_FILL_RECT_V = 1 Dim Shared hInstance As HINSTANCE ' This dll is located in Windows directory DECLARE FUNCTION Gradientfill Lib "MSIMG32" ALIAS "GradientFill" _ (hDC AS HDC, pVertex As PTRIVERTEX, dwNumVertex As Integer,pMesh AS PGRADIENT_RECT, dwNumMesh As Integer, dwMode As Integer) As Integer '******************************************************************** ' A FB Control Template '******************************************************************** Declare Function NiceButt(ByVal hWnd as HWND,byval Msg as UINT,byval wParam as WPARAM,byval lParam as LPARAM) as LRESULT Declare FUNCTION IsMouseOver (hWnd As HWND )As Integer Declare SUB Draw_Gradient (hdc as HDC, x As Integer, y As integer, w As integer, h As Integer, r As integer, g As integer, b As integer) Declare FUNCTION Register_NiceButt()As Integer ' 'Windows calls this function when the dll is loaded. /'Function DllMain alias "MAIN"(byval hModule as HMODULE,byval reason as Integer,byval lpReserved as LPVOID) as BOOL Select case reason case DLL_PROCESS_ATTACH hInstance=hModule Register_NiceButt() MessageBox(GetActiveWindow(),"OK","OK",MB_OK) Return 0 case DLL_PROCESS_DETACH ' end select return TRUE end function '/ FUNCTION Register_NiceButt()As Integer Export DIM wc AS WNDCLASSEX DIM szClassName As String szClassName = "NiceButt" wc.cbSize = SIZEOF(WNDCLASSEX) wc.style = CS_HREDRAW OR CS_VREDRAW OR CS_GLOBALCLASS wc.hInstance = GetmoduleHandle(0) 'hInstance wc.hbrBackground = Cast(HBRUSH,COLOR_BTNFACE+1) wc.lpszClassName = StrPtr(szClassName) wc.lpfnWndProc = @NiceButt wc.cbClsExtra = 0 wc.cbWndExtra = 0 wc.hIcon = 0 wc.hCursor = 0 wc.lpszMenuName = 0 wc.hIconSm = 0 FUNCTION = RegisterClassEx(@wc) END FUNCTION '******************************************************************** ' Custom Control Procedure '******************************************************************** Function NiceButt(ByVal hWnd as HWND,byval Msg as UINT,byval wParam as WPARAM,byval lParam as LPARAM) as LRESULT STATIC As Integer ButtDown,mouseover STATIC Captured AS HWND SELECT Case Msg '************************** CASE WM_CREATE '************************** DIM Region AS HRGN DIM Rct AS RECT DIM As Integer x, y, w, h ButtDown = FALSE GetClientRect (hWnd,@Rct) ' <<-- Get the size of our control x = Rct.left y = Rct.top w = Rct.right - Rct.left h = Rct.bottom - Rct.top 'Region = CreateRoundRectRgn(10,10,w,h, h * 0.90 , h * 0.90 ) 'SetWindowRgn (hWnd,Region,True) InvalidateRect(hWnd,0,0) 'EXIT FUNCTION ' ******************* CASE WM_PAINT ' ******************* DIM hDC AS HDC DIM ps AS PAINTSTRUCT DIM hPen AS HPEN DIM hBrush AS HBRUSH DIM hOldBrush AS HBRUSH DIM Rct AS RECT DIM Size AS SIZE DIM T As ZString*2048 DIM As Integer i DIM As Integer XCtr DIM As Integer YCtr DIM As Integer x,y,w,h DIM As Integer r,g,b ' ******************* GetClientRect (hWnd,@Rct) ' <<-- Get the size of our control x = Rct.left y = Rct.top w = Rct.right - Rct.left h = Rct.bottom - Rct.top XCtr = (Rct.left + Rct.right) / 2 ' Horizontal center of our ctrl YCtr = (Rct.top + Rct.bottom) / 2 ' Vertical center of our ctrl GetWindowText(hWnd,T ,255) ' Grab a copy of control caption '********************************** ' Draw our control '********************************** hDC = BeginPaint (hWnd, @ps) GetTextExtentPoint32(hDC, T , LEN(T),@Size) ' Get caption size r = 30 : g = 90 : b = 90 Draw_Gradient (hDC, x, y, w, h, r, g, b) SetBkMode (hDC,TRANSPARENT) IF ButtDown THEN SetTextColor(hDC,_RGB(255,0,0)) TextOut(hDC, XCtr-(Size.cx/2)+1, YCtr-(Size.cy/2)+1,T,LEN(T)) ELSE SetTextColor(hDC,_RGB(0,0,255)) TextOut(hDC, XCtr-Size.cx/2, YCtr-Size.cy/2,T,LEN(T)) END IF EndPaint (hWnd,@ps) 'EXIT FUNCTION '****************************** CASE WM_LBUTTONUP '****************************** IF hWnd = Captured THEN DIM hParent AS HWND ReleaseCapture() ButtDown = FALSE InvalidateRect(hWnd,0,0) hParent=GetParent(hWnd) SendMessage(hParent,WM_COMMAND,MAKELONG(GetWindowLong(hWnd,GWL_ID), BN_CLICKED),Cast(LONG,hWnd)) END IF 'EXIT FUNCTION '****************************** CASE WM_LBUTTONDOWN '****************************** SetCapture(hWnd) Captured = hWnd ButtDown = TRUE SetFocus (hWnd) InvalidateRect(hWnd,0,0) 'EXIT FUNCTION '****************************** CASE WM_MOUSEMOVE '****************************** IF ButtDown THEN IF IsMouseOver(hWnd) THEN ButtDown = TRUE InvalidateRect(hWnd,0,0) ELSE ReleaseCapture() ButtDown = FALSE InvalidateRect(hWnd,0,0) END IF END IF 'EXIT FUNCTION '****************************** CASE WM_MOVING '****************************** ReleaseCapture() ButtDown = FALSE InvalidateRect(hWnd,0,0) 'EXIT FUNCTION '****************************** CASE WM_SIZE '****************************** ReleaseCapture() ButtDown = FALSE InvalidateRect(hWnd,0,0) 'EXIT FUNCTION END Select Return DefWindowProc(hwnd,Msg,wparam,lparam) END FUNCTION SUB Draw_Gradient (hdc as HDC, x As Integer, y As integer, w As integer, h As Integer, r As integer, g As integer, b As integer) DIM Vert(2) AS TRIVERTEX DIM Rect AS GRADIENT_RECT '****************************************************** Vert (0).x = 0 Vert (0).y = 0 Vert (0).Red = 65535-(65535-(r*256)) Vert (0).Green = 65535-(65535-(g*256)) Vert (0).Blue = 65535-(65535-(b*256)) Vert (0).Alpha = 0 '****************************************************** Vert (1).x = w Vert (1).y = h/2 Vert (1).Red = 65535-(65535-(255*256)) Vert (1).Green = 65535-(65535-(255*256)) Vert (1).Blue = 65535-(65535-(255*256)) Vert (1).Alpha = 0 '****************************************************** Rect.UpperLeft = 0 Rect.LowerRight = 1 '****************************************************** Gradientfill(hdc,@Vert(0),2,@Rect,1,GRADIENT_FILL_RECT_V) '****************************************************** Vert (0).x = 0 Vert (0).y = h/2 Vert (0).Red = 65535-(65535-(255*256)) Vert (0).Green = 65535-(65535-(255*256)) Vert (0).Blue = 65535-(65535-(255*256)) Vert (0).Alpha = 0 '****************************************************** Vert (1).x = w Vert (1).y = h Vert (1).Red = 65535-(65535-(r*256)) Vert (1).Green = 65535-(65535-(g*256)) Vert (1).Blue = 65535-(65535-(b*256)) Vert (1).Alpha = 0 '****************************************************** Rect.UpperLeft = 0 Rect.LowerRight = 1 '****************************************************** Gradientfill(hdc,@Vert(0),2,@Rect,1,GRADIENT_FILL_RECT_V) END SUB FUNCTION IsMouseOver (hWnd As HWND )As Integer DIM Rect As RECT DIM Pt As POINT GetWindowRect (hWnd, @Rect) GetCursorPos(@Pt) FUNCTION = PtInRect (@Rect, Pt) END FUNCTION  
      AutoIt:
      #include-once #include <WinAPI.au3> #include <WinAPIGdi.au3> #include <WinAPISys.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;~ #Include <windows.bi> Global Const $_tagRect = "struct;long left;long top;long right;long bottom;endstruct" Global Const $_tagSize = "struct;long cx;long cy;endstruct" Global Const $_tagGradient_Rect = "struct;ulong UpperLeft;ulong LowerRight;endstruct" Global Const $_tagPoint = "struct;long x;long y;endstruct" Global Const $_tagTrivertex = "struct;long x;long y;int Red;int Greed;int Blue;int Alpha;endstruct" Global Const $_tagPaintStruct = "struct;handle hdc;bool fErase;long left;long top;long right;long bottom;bool fRestore;bool fIncUpdate;byte rgbReserved[32];endstruct" Global Const $_tagWNDCLASSEX = "struct;uint cbSize;uint style;ptr lpfnWndProc;int cbClsExtra;int cbWndExtra;ptr hInstance;ptr hIcon;" & _ "ptr hCursor; ptr hbrBackground; ptr lpszMenuName;ptr lpszClassName;ptr hIconSm;endstruct" Global Const $CS_VREDRAW = 0x0001, $CS_HREDRAW =0x0002, $CS_GLOBALCLASS = 0x4000 Global Const $BN_CLICKED = 0 ;~ #Define _RGB(r,g,b) BGR(b,g,r) Global Const $GRADIENT_FILL_RECT_H = 0 Global Const $GRADIENT_FILL_RECT_V = 1 ;~ Dim Shared hInstance As HINSTANCE ;~ ' This dll is located in Windows directory ;~ DECLARE FUNCTION Gradientfill Lib "MSIMG32" ALIAS "GradientFill" _ ;~ (hDC AS HDC, pVertex As PTRIVERTEX, dwNumVertex As Integer,pMesh AS PGRADIENT_RECT, dwNumMesh As Integer, dwMode As Integer) As Integer ;~ '******************************************************************** ;~ ' A FB Control Template ;~ '******************************************************************** ;~ Declare Function NiceButt(ByVal hWnd as HWND,byval Msg as UINT,byval wParam as WPARAM,byval lParam as LPARAM) as LRESULT ;~ Declare FUNCTION IsMouseOver (hWnd As HWND )As Integer ;~ Declare SUB Draw_Gradient (hdc as HDC, x As Integer, y As integer, w As integer, h As Integer, r As integer, g As integer, b As integer) ;~ Declare FUNCTION Register_NiceButt()As Integer #cs ' 'Windows calls this function when the dll is loaded. /'Function DllMain alias "MAIN"(byval hModule as HMODULE,byval reason as Integer,byval lpReserved as LPVOID) as BOOL Select case reason case DLL_PROCESS_ATTACH hInstance=hModule Register_NiceButt() MessageBox(GetActiveWindow(),"OK","OK",MB_OK) Return 0 case DLL_PROCESS_DETACH ' end select return True end function '/ #ce #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) RegisterButton() Global $Ctrl = _winapi_CreateWindowEx(0, "TestButton", "Test", BitOR($WS_VISIBLE, $WS_CHILD), 10, 10, 80, 30, $Form1) ConsoleWrite(@CRLF & $Ctrl) GUISetState(@SW_SHOW) _WinAPI_UpdateWindow($Form1) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func RegisterButton() Local $hDll = DllCallbackRegister('TestButtonProc', 'lresult', 'hwnd;uint;wparam;lparam') ;~ DIM wc AS WNDCLASSEX ;~ DIM szClassName As String Local $sClass = "TestButton" Local $wc = DllStructCreate($_tagWNDCLASSEX & ';wchar szClassName[' & (StringLen($sClass) + 1) & ']') ;~ szClassName = "NiceButt" ;~ wc.cbSize = SIZEOF(WNDCLASSEX) $wc.cbSize = DllStructGetPtr($wc, 'szClassName') - DllStructGetPtr($wc) ;~ wc.style = CS_HREDRAW OR CS_VREDRAW OR CS_GLOBALCLASS $wc.style = BitOR($CS_HREDRAW, $CS_VREDRAW, $CS_GLOBALCLASS) ;~ wc.hInstance = GetmoduleHandle(0) 'hInstance $wc.hInstance = _WinAPI_GetModuleHandle(0) ;~ wc.hbrBackground = Cast(HBRUSH,COLOR_BTNFACE+1) ;/// $wc.hbrBackground = _WinAPI_CreateSolidBrush(_WinAPI_GetSysColor($COLOR_BTNFACE)) ;~ wc.lpszClassName = StrPtr(szClassName) $wc.lpszClassName = DllStructGetPtr($wc, 'szClassName') ;~ wc.lpfnWndProc = @NiceButt $wc.lpfnWndProc = DllCallbackGetPtr($hDll) ;~ wc.cbClsExtra = 0 $wc.cbClsExtra = 0 ;~ wc.cbWndExtra = 0 $wc.cbWndExtra = 0 ;~ wc.hIcon = 0 $wc.hIcon = 0 ;~ wc.hCursor = 0 $wc.hCursor = 0 ;~ wc.lpszMenuName = 0 $wc.lpszMenuName = 0 ;~ wc.hIconSm = 0 $wc.hIconSm = 0 $wc.szClassName = $sClass ;~ FUNCTION = RegisterClassEx(@wc) Local $aRet = _WinAPI_RegisterClassEx($wc) Return $aRet ;~ END FUNCTION EndFunc ;******************************************************************** ; Custom Control Procedure ;******************************************************************** ;~ Function NiceButt(ByVal hWnd as HWND,byval Msg as UINT,byval wParam as WPARAM,byval lParam as LPARAM) as LRESULT Func TestButtonProc($hWnd, $iMsg, $wParam, $lParam) Static $bBtnDown, $bMouseOver, $hCaptured Switch $iMsg Case $WM_CREATE Local $Rct = DllStructCreate($_tagRect) Local $iX, $iY, $iW, $iH $bBtnDown = False GetClientRect($hWnd, $Rct) $iX = $Rct.left $iY = $Rct.top $iW = $Rct.right - $Rct.left $iH = $Rct.bottom - $Rct.top InvalidateRect($hWnd, 0, False) ;~ EXIT FUNCTION ;~ Return 0 Case $WM_PAINT Local $ps ;= DllStructCreate($_tagPaintStruct) Local $hPen, $hBrush, $hOldBrush Dim $Rct = DllStructCreate($_tagRect) Dim $Size = DllStructCreate($_tagSize) Dim $T = "", $i Dim $XCtr, $YCtr Dim $iX, $iY, $iW, $iH Dim $iR, $iG, $iB GetClientRect($hWnd, $Rct) $iX = $Rct.left $iY = $Rct.top $iW = $Rct.right - $Rct.left $iH = $Rct.bottom - $Rct.top $XCtr = ($Rct.left + $Rct.right) / 2 $YCtr = ($Rct.top + $Rct.bottom) / 2 ;~ GetWindowText(hWnd,T ,255) ' Grab a copy of control caption ;~ DllCall("user32.dll", "int", "GetWindowTextW", "hwnd", $hWnd, "LPTSTR ", $T, "int", 255) ; not work $T = "Test" ;********************************** ; Draw our control ;********************************** Local $hDC = BeginPaint($hWnd, $ps) ;~ GetTextExtentPoint32(hDC, T , LEN(T),@Size) ' Get caption size GetTextExtentPoint32($hDC, $T, StringLen($T), $Size) $iR = 30 $iG = 90 $iB = 90 Draw_Gradient($hDC, $iX, $iY, $iW, $iH, $iR, $iG, $iB) SetBkMode($hDC, $TRANSPARENT) If $bBtnDown Then ;~ SetTextColor(hDC,_RGB(255,0,0)) SetTextColor($hDC, Dec(0xFF0000)) TextOut($hDC, $XCtr-($Size.cx/2)+1, $YCtr-($Size.cy/2)+1, $T) Else ;~ SetTextColor(hDC,_RGB(0,0,255)) SetTextColor($hDC, Dec(0x0000FF)) TextOut($hDC, $XCtr-$Size.cx/2, $YCtr-$Size.cy/2, $T) EndIf EndPaint($hWnd, $ps) ;~ EXIT FUNCTION ;~ Return 0 Case $WM_LBUTTONUP If $hWnd = $hCaptured Then ReleaseCapture() $bBtnDown = False InvalidateRect($hWnd, 0, 0) Local $hParent = GetParent($hWnd) ;~ SendMessage(hParent,WM_COMMAND,MAKELONG(GetWindowLong(hWnd,GWL_ID), BN_CLICKED),Cast(LONG,hWnd)) DllCall("user32.dll", "LRESULT", "SendMessageW", _ "hwnd", $hParent, _ "uint", $WM_COMMAND, _ "WPARAM", _WinAPI_MakeLong(_WinAPI_GetWindowLong($hWnd, $GWL_ID), $BN_CLICKED), _ "LPARAM", $hWnd) EndIf ;~ EXIT FUNCTION Return 0 Case $WM_LBUTTONDOWN SetCapture($hWnd) $hCaptured = $hWnd $bBtnDown = True SetFocus($hWnd) InvalidateRect($hWnd, 0, False) ;~ EXIT FUNCTION Return 0 Case $WM_MOUSEMOVE If $bBtnDown Then If IsMouseOver($hWnd) Then $bBtnDown = True InvalidateRect($hWnd, 0, False) ELSE ReleaseCapture() $bBtnDown = False InvalidateRect($hWnd, 0, False) EndIf EndIf ;~ EXIT FUNCTION ;~ Return 0 Case $WM_MOVING ReleaseCapture() $bBtnDown = False InvalidateRect($hWnd, 0, False) ;~ EXIT FUNCTION ;~ Return 0 Case $WM_SIZE ReleaseCapture() $bBtnDown = False InvalidateRect($hWnd, 0, False) ;~ EXIT FUNCTION ;~ Return 0 EndSwitch ;~ Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) Return DllCall("user32.dll", "lresult", "DefWindowProcW", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, _ "lparam", $lParam)[0] EndFunc ;~ SUB Draw_Gradient (hdc as HDC, x As Integer, y As integer, w As integer, h As Integer, r As integer, g As integer, b As integer) Func Draw_Gradient($hDC, $iX, $iY, $iW, $iH, $iR, $iG, $iB) ;~ DIM Vert(2) AS TRIVERTEX Local $Vert[2] $Vert[0] = DllStructCreate($_tagTrivertex) $Vert[1] = DllStructCreate($_tagTrivertex) ;~ DIM Rect AS GRADIENT_RECT Local $Rect = DllStructCreate($_tagGradient_Rect) ;~ Vert (0).x = 0 $Vert[0].x = 0 ;~ Vert (0).y = 0 $Vert[0].y = 0 ;~ Vert (0).Red = 65535-(65535-(r*256)) $Vert[0].Red = 65535-(65535-($iR*256)) ;~ Vert (0).Green = 65535-(65535-(g*256)) $Vert[0].Green = 65535-(65535-($iG*256)) ;~ Vert (0).Blue = 65535-(65535-(b*256)) $Vert[0].Blue = 65535-(65535-($iB*256)) ;~ Vert (0).Alpha = 0 $Vert[0].Alpha = 0 ;~ '****************************************************** ;~ Vert (1).x = w $Vert[1].x = $iW ;~ Vert (1).y = h/2 $Vert[1].y = $iH/2 ;~ Vert (1).Red = 65535-(65535-(255*256)) $Vert[1].Red = 65535-(65535-(255*256)) ;~ Vert (1).Green = 65535-(65535-(255*256)) $Vert[1].Green = 65535-(65535-(255*256)) ;~ Vert (1).Blue = 65535-(65535-(255*256)) $Vert[1].Blue = 65535-(65535-(255*256)) ;~ Vert (1).Alpha = 0 $Vert[1].Alpha = 0 ;~ '****************************************************** ;~ Rect.UpperLeft = 0 $Rect.UpperLeft = 0 ;~ Rect.LowerRight = 1 $Rect.LowerRight = 1 ;~ '****************************************************** ;~ Gradientfill(hdc,@Vert(0),2,@Rect,1,GRADIENT_FILL_RECT_V) GradientFill($hDC, $Vert[0], 2, $Rect, 1, $GRADIENT_FILL_RECT_V) ;~ '****************************************************** ;~ Vert (0).x = 0 $Vert[0].x = 0 ;~ Vert (0).y = h/2 $Vert[0].y = $iH/2 ;~ Vert (0).Red = 65535-(65535-(255*256)) $Vert[0].Red = 65535-(65535-(255*256)) ;~ Vert (0).Green = 65535-(65535-(255*256)) $Vert[0].Green = 65535-(65535-(255*256)) ;~ Vert (0).Blue = 65535-(65535-(255*256)) $Vert[0].Blue = 65535-(65535-(255*256)) ;~ Vert (0).Alpha = 0 $Vert[0].Alpha = 0 ;~ '****************************************************** ;~ Vert (1).x = w $Vert[1].x = $iW ;~ Vert (1).y = h $Vert[1].y = $iH ;~ Vert (1).Red = 65535-(65535-(r*256)) $Vert[1].Red = 65535-(65535-($iR*256)) ;~ Vert (1).Green = 65535-(65535-(g*256)) $Vert[1].Green = 65535-(65535-($iG*256)) ;~ Vert (1).Blue = 65535-(65535-(b*256)) $Vert[1].Blue = 65535-(65535-($iB*256)) ;~ Vert (1).Alpha = 0 $Vert[1].Alpha = 0 ;~ '****************************************************** ;~ Rect.UpperLeft = 0 $Rect.UpperLeft = 0 ;~ Rect.LowerRight = 1 $Rect.LowerRight = 1 ;~ '****************************************************** ;~ Gradientfill(hdc,@Vert(0),2,@Rect,1,GRADIENT_FILL_RECT_V) GradientFill($hDC, $Vert[0], 2, $Rect, 1, $GRADIENT_FILL_RECT_V) ;~ END SUB EndFunc Func IsMouseOver($hWnd) Local $Rect = DllStructCreate($_tagRect) Local $Pt = DllStructCreate($_tagPoint) GetWindowRect ($hWnd, $Rect) GetCursorPos($Pt) Return PtInRect($Rect, $Pt) EndFunc Func _RGB($iR, $iG, $iB) Return ('0x' & Hex($iR, 2) & Hex($iG, 2) & Hex($iB, 2)) EndFunc Func _BGR($iB, $iG, $iR) Return ('0x' & Hex($iB, 2) & Hex($iG, 2) & Hex($iR, 2)) EndFunc Func InvalidateRect($hWnd, $tRECT = 0, $bErase = True) DllCall("user32.dll", "bool", "InvalidateRect", "hwnd", $hWnd, "struct*", $tRECT, "bool", $bErase) EndFunc Func SetFocus($hWnd) DllCall("user32.dll", "hwnd", "SetFocus", "hwnd", $hWnd) EndFunc Func PtInRect($tRect, $tPoint) Local $aRet = DllCall("user32.dll", "bool", "PtInRect", "ptr", DllStructGetPtr($tRect), "struct*", $tPoint) If IsArray($aRet) Then Return $aRet[0] Return False EndFunc Func GetWindowRect($hWnd, ByRef $tRect) DllCall("user32.dll", "bool", "GetWindowRect", "hwnd", $hWnd, "struct*", $tRect) EndFunc Func GetCursorPos(ByRef $tPoint) DllCall("user32.dll", "bool", "GetCursorPos", "struct*", $tPoint) EndFunc Func SetCapture($hWnd) DllCall("user32.dll", "hwnd", "SetCapture", "hwnd", $hWnd) EndFunc Func ReleaseCapture() DllCall("user32.dll", "bool", "ReleaseCapture") EndFunc Func SetTextColor($hDC, $iColor) DllCall("gdi32.dll", "INT", "SetTextColor", "handle", $hDC, "INT", $iColor) EndFunc Func BeginPaint($hWnd, ByRef $tPAINTSTRUCT) $tPAINTSTRUCT = DllStructCreate($tagPAINTSTRUCT) Local $aRet = DllCall('user32.dll', 'handle', 'BeginPaint', 'hwnd', $hWnd, 'struct*', $tPAINTSTRUCT) If @error Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc Func GetTextExtentPoint32($hDC, $sText, $iTextLen, ByRef $tSize) DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sText, "int", $iTextLen, "struct*", $tSize) EndFunc Func GradientFill($hDC, $tVertex, $nVertex, $tMesh, $nMesh, $ulMode) DllCall("Msimg32.dll", "BOOL", "GradientFill", _ "handle", $hDC, _ "struct*", $tVertex, _ "ulong", $nVertex, _ "struct*", $tMesh, _ "ulong", $nMesh, _ "ulong", $ulMode) EndFunc Func GetParent($hWnd) Local $aResult = DllCall("user32.dll", "hwnd", "GetParent", "hwnd", $hWnd) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Func SetBkMode($hDC, $iBkMode) Local $aResult = DllCall("gdi32.dll", "int", "SetBkMode", "handle", $hDC, "int", $iBkMode) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Func EndPaint($hWnd, ByRef $tPAINTSTRUCT) Local $aRet = DllCall('user32.dll', 'bool', 'EndPaint', 'hwnd', $hWnd, 'struct*', $tPAINTSTRUCT) If @error Then Return SetError(@error, @extended, False) Return $aRet[0] EndFunc Func GetClientRect($hWnd, ByRef $tRect) Local $aRet = DllCall("user32.dll", "bool", "GetClientRect", "hwnd", $hWnd, "struct*", $tRect) If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) Return $tRect EndFunc Func TextOut($hDC, $iX, $iY, $sText, $iTextLen = Default) If $iTextLen = Default Then $iTextLen = StringLen($sText) DllCall('gdi32.dll', 'bool', 'TextOutW', 'handle', $hDC, 'int', $iX, 'int', $iY, 'wstr', $sText, 'int', $iTextLen) EndFunc  
    • c.haslam
      By c.haslam
      UEZ has kindly provided me with code that rotates an image per a line: see here
      Because I want to trim a photograph after rotation, I need to crop the photo. I wrote code which calls _GDIPlus_GraphicsSetClipRect() to do this, but it places spurious stuff in the corners: see 2.jpg attached.
      I want only the trimmed photo to show.
      The original jpeg is also attached.
      The arguments to _GDIPlus_GraphicsSetClipRect() come from solving 2 simultaneous equations: if a and b are the width and height of the original photo, find x and y, the width and height of the rotated and cropped rectangle;
      a = x cos(ang) + y sin(ang)
      b = x sin(ang) + y cos(ang)
      My solution is:
      x = (b * sin(ang) - a*cos(ang)) / (sin(ang)^2 - (cos(ang)^2)
      y = (b * cos(ang) - a * sin(ang)) / (cos(ang)^2 - sin(ang)^2)
      To try to get a handle on the problem, I have temporarily added in several lines in Case $btn. In 2.jpg, you can see that the rectangle bounding the area to be retained is in the wrong place.
      The code is:
      #include <ButtonConstants.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars',1) Global Const $MK_SHIFT = 0x4 Global Const $MK_CONTROL = 0x8 Global Const $fPi = ACos(-1), $fPi2 = $fPi / 2, $fRad = 180 / $fPi GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") GUIRegisterMsg($WM_PAINT,'WM_PAINT') Global $gX0=10,$gX1=580,$gY0,$gY1,$gForm1,$glblPic,$iLW,$iLH,$iW,$iH Global $ghCanvas,$ghImage,$ghPen,$gGraphicPic,$ghBitmap,$ghMatrix,$ghImageClone,$ghGfxClone Global Const $kDegToRads = 3.14159/180 main() Func main() $gForm1 = GUICreate("Form1", 623, 601, 192, 114) $iLW = 589 $iLH = 500 $glblPic = GUICtrlCreateLabel("", 8, 8, $iLW, $iLH) Local $btn = GUICtrlCreateButton("Rotate", 472, 560, 65, 25) GUISetState(@SW_SHOW) Local $oldY0,$oldY1,$fAngle _GDIPlus_Startup() $ghPen = _GDIPlus_PenCreate(0xFF999999,2) $ghImage = _GDIPlus_ImageLoadFromFile('H:\b\pergola.jpg') Local $h = GUICtrlGetHandle($glblPic) $gGraphicPic = _GDIPlus_GraphicsCreateFromHWND($h) $gY0 = 400 $gY1 = 400 $iW = _GDIPlus_ImageGetWidth($ghImage) $iH = _GDIPlus_ImageGetHeight($ghImage) $ghBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) $ghCanvas = _GDIPlus_ImageGetGraphicsContext($ghBitmap) $ghMatrix = _GDIPlus_MatrixCreate() ; Loop until the user exits. While True If $gY0<>$oldY0 Or $gY1<>$oldY1 Then Paint() $oldY0 = $gY0 $oldY1 = $gY1 Else Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btn $ghImageClone=_GDIPlus_BitmapCreateFromScan0($iW, $iH) $ghGfxClone=_GDIPlus_ImageGetGraphicsContext($ghImageClone) _GDIPlus_MatrixTranslate($ghMatrix, $iW/2, $iH/2) $gY1 = 300 ; temp Local $ang = -Angle($gY1-$gY0, $gX1-$gX0) _GDIPlus_MatrixRotate($ghMatrix, $ang) ;~ _GDIPlus_MatrixRotate($ghMatrix, -Angle($gY1-$gY0, $gX1-$gX0)) _GDIPlus_MatrixTranslate($ghMatrix, -$iW/2, -$iH/2) _GDIPlus_GraphicsSetTransform($ghGfxClone, $ghMatrix) _GDIPlus_GraphicsDrawImageRect($ghGfxClone,$ghImage,0,0,$iW,$iH) Local $angRads = $ang*$kDegToRads Local $sinAng = Sin($angRads) Local $cosAng = Cos($angRads) Local $wid = ($iLH*$sinAng-$iLW*$cosAng)/($sinAng^2-$cosAng^2) Local $left = ($iLW-$wid)/2 Local $ht = ($iLH*$cosAng-$iLW*$sinAng)/($cosAng^2-$sinAng^2) Local $top = ($iLH-$ht)/2 _GDIPlus_GraphicsDrawRect($ghGfxClone,$left,$top,$wid,$ht,$ghPen) ; temp _GDIPlus_GraphicsSetClipRect($ghGfxClone,$left,$top,$wid,$ht,0) _GDIPlus_GraphicsDispose($ghGfxClone) $ghGfxClone=_GDIPlus_ImageGetGraphicsContext($ghImage) _GDIPlus_GraphicsClear($ghImage) _GDIPlus_GraphicsDrawImageRect($ghGfxClone,$ghImageClone,0,0,$iW,$iH) _GDIPlus_GraphicsDispose($ghGfxClone) _GDIPlus_ImageDispose($ghImageClone) $gy0 = 400 $gy1 = 400 Paint() _GDIPlus_ImageSaveToFile($ghImage,'H:\b\2.jpg') ; added - is rotated, with same size as original file EndSwitch EndIf WEnd ; Clean up resources _GDIPlus_MatrixDispose($ghMatrix) _GDIPlus_ImageDispose($ghCanvas) _GDIPlus_ImageDispose($ghImage) _GDIPlus_ImageDispose($ghBitmap) _GDIPlus_PenDispose($ghPen) _GDIPlus_GraphicsDispose($gGraphicPic) _GDIPlus_Shutdown() EndFunc Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local Const $kYmax=$iLH-1,$kDelta=2 Local $vec = GUIGetCursorInfo($gForm1) If $vec[4] = $vec[4]=$glblPic Then Local $iDelta = BitShift($wParam, 16) ; positive = up Local $iKeys = _WinAPI_LoWord($wParam) If BitAND($iKeys,$MK_CONTROL)=$MK_CONTROL Then If BitAND($iKeys,$MK_SHIFT)=$MK_SHIFT Then ; do nothing Else If $iDelta > 0 And $gY0>3 Then $gY0 -= $kDelta If $iDelta < 0 And $gY0<$kYmax Then $gY0 += $kDelta EndIf Else If BitAND($iKeys,$MK_SHIFT)=$MK_SHIFT Then If $iDelta > 0 And $gY1>3 Then $gY1 -= $kDelta If $iDelta < 0 And $gY1<$kYmax Then $gY1 += $kDelta Else If $iDelta > 0 And $gY0>3 Then $gY0 -= $kDelta If $iDelta < 0 And $gY0<$kYmax Then $gY0 += $kDelta If $iDelta > 0 And $gY1>3 Then $gY1 -= $kDelta If $iDelta < 0 And $gY1<$kYmax Then $gY1 += $kDelta EndIf EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOUSEWHEEL Func Paint() _GDIPlus_GraphicsClear($ghCanvas,0) _GDIPlus_GraphicsDrawImageRect($ghCanvas, $ghImage, 0,0, $iLW, $iLH) _GDIPlus_GraphicsDrawLine($ghCanvas, $gX0, $gY0, $gX1, $gY1, $ghPen) _GDIPlus_GraphicsDrawImageRect($gGraphicPic, $ghBitmap, 0, 0, $iW, $iH) EndFunc Func WM_PAINT() _WinAPI_RedrawWindow($gForm1, 0, 0, $RDW_UPDATENOW) Paint() _WinAPI_RedrawWindow($gForm1, 0, 0, $RDW_VALIDATE) EndFunc Func Angle($y, $x) ;return value is in degree Local Const $fPi = ACos(-1), $fPi2 = ACos(-1) / 2, $fRad = 180 / $fPi Switch True Case ($x > 0) Return ATan($y / $x) * $fRad Case ($x < 0 And $y >= 0) Return ATan($y / $x + $fPi) * $fRad Case ($x < 0 And $y < 0) Return ATan($y / $x - $fPi) * $fRad Case ($x = 0 And $y > 0) Return $fPi2 * $fRad Case ($x = 0 And $y < 0) Return -$fPi2 * $fRad Case ($x = 0 And $y = 0) Return 0 EndSwitch EndFunc I also don't understand how the rotated picture gets displayed. There are graphics objects, graphics contexts and PDI+ bitmaps. How are they related?
      Help would be much appreciated.