Sign in to follow this  
Followers 0
playlet

---

16 posts in this topic

#1 ·  Posted (edited)

---

Edited by playlet

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

---

Edited by playlet

Share this post


Link to post
Share on other sites

Hi Playlet

I think this is what you are asking for.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <Array.au3>
#include <Constants.au3>
Opt("GUIOnEventMode",1)

_GDIPlus_Startup()
Global $GUI
Global $iW = 64
Global $iH = 32
global $object,$background
    $GUI = GUICreate("test", $iW, $iH, -1, -1, $WS_POPUP,bitor($WS_EX_TOOLWINDOW,$WS_EX_LAYERED))
        GUISetState(@SW_SHOWNOACTIVATE, $GUI)
global $xco=150,$yco=0
$object=_Imagechange()
SetBitmap__OK_($GUI, $object, 255)
    _WinAPI_DeleteObject($object)
    _GDIPlus_Shutdown()

While 1
sleep(100)

WEnd
Func SetBitmap__OK_($hGUI, $hImage, $iOpacity)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld
    Local Const $AC_SRC_ALPHA = 1
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _Imagechange()
    ;resize the png
    Local $GC, $newBmp, $newGC
   ; Load Image

   ;Create New image
       $hGraphic = _GDIPlus_GraphicsCreateFromHWND(0)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics(64,32, $hGraphic)

        $hBitmap1 = _drawicon($hBitmap1, 32, 32,0,  "C:\applications\opera10\opera.exe", "0")
        $hBitmap1 = _drawicon($hBitmap1, 32, 32,32,  "C:\WINDOWS\NOTEPAD.EXE", "0")
        ;;;;;;;;;;;;;;;;
   
    $GC = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    $newBmp = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $GC)
    $newGC = _GDIPlus_ImageGetGraphicsContext($newBmp)
   ;Draw
    _GDIPlus_GraphicsDrawImageRect($newGC,  $hBitmap1, 0, 0, $iW, $iH)

   ;Cleanup
    _GDIPlus_GraphicsDispose($GC)
    _GDIPlus_GraphicsDispose($newGC)
_GDIPlus_BitmapDispose($hBitmap1)
_GDIPlus_GraphicsDispose($hGraphic)
    Return $newBmp
EndFunc  ;==>_ImageResize

Func _drawicon($bitmap, $width, $height,$lpos, $ico, $ind)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
    $hIcon = _WinAPI_SHExtractIcons($ico, $ind, 32, 32)
    $hDC = _WinAPI_GetDC(0)
    $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBackSv = _WinAPI_SelectObject($hBackDC, $hbmp)
    If $hIcon <> 0 Then _WinAPI_DrawIconEx($hBackDC, $lpos, $height / 2 - 15, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
    $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_SelectObject($hBackDC, $hBackSv)
    _WinAPI_DeleteDC($hBackDC)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DestroyIcon($hIcon)
    Return $bitmap
    Return
EndFunc ;==>_drawicon

Func _WinAPI_SHExtractIcons($sIcon, $iIndex, $iWidth, $iHeight)
    Local $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
    If (@error) Or ($Ret[0] = 0) Or ($Ret[5] = Ptr(0)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[5]
EndFunc ;==>_WinAPI_SHExtractIcons

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

---

Edited by playlet

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I'm hoping someone with more knowledge than me will jump in...but until then, I share what little I know. The problem is drawing the icons. Whenever I draw icons, the background turns black. Not sure how to get around it. I have to work arounds to attempt to answer your questions while guessing that this is for your playlet launcher. Could be wrong on that. Anyways. First example shows erasing all black in the bmp. 2nd example adds a picture behind the images and text. Needs "normal.png" in the same directory.

I however believe that putting the fully created image into a guictrl will yield the best results and would suggesting combining some of the ideas from this post with an example I made in this post. Just my opinion.

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

$gui=guicreate("",200,200,-1,-1)
$pic=GUICtrlCreatePic("",15,15,80,40)
createbutton_3($pic, "Picture", "Arial", 12, 0, "0xFFFFFF", 0)
GUISetState()
while 1
sleep(100)
WEnd
Func createbutton_3($control, $text = "", $font = "Arial", $size = 12, $style = 0, $fontcol = "0xFFFFFF", $halign = 0)
    _GDIPlus_Startup()
    If $font = "" Then $font = "Arial"
    If $size = "" Then $size = "12"
    If $style = "" Then $style = 0
    If $fontcol = "" Then $fontcol = "0x222222"
    If $halign = "" Then $halign = 0
    $hwd = GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width = _WinAPI_GetClientWidth($hwd)
    $height = _WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)

        $hBitmap1 = _drawicon($hBitmap1, $width, $height,0,  "C:\applications\opera10\opera.exe", "0")
        $hBitmap1 = _drawicon($hBitmap1, $width, $height,32,  "C:\WINDOWS\NOTEPAD.EXE", "0")
$hBitmap1 = _ImageColorRegExpReplace($hBitmap1, "(000000FF)" , "FFFFFF00" ); Change white to transparent
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    If Not $text = "" Then $hBitmap1 = _drawtext($hBitmap1, $width, $height, $text, $font, $size, $style, $fontcol)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
    _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_GraphicsDispose($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc ;==>createbutton_3

Func _drawtext($hBitmap1, $leftpos, $toppos, $text, $font, $size, $style, $fontcol)
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    $fcol = StringReplace($fontcol, "0x", "0xFF")
    $hBrushed = _GDIPlus_BrushCreateSolid($fcol)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate($font)
    $hFont = _GDIPlus_FontCreate($hFamily, $size, $style)
    $tLayout = _GDIPlus_RectFCreate($leftpos, $toppos, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hImage1, $text, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    $tLayout = _GDIPlus_RectFCreate(5, ($toppos / 2) - ($iHeight / 2), 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hImage1, $text, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hImage1, $text, $hFont, $aInfo[0], $hFormat, $hBrushed)
    _GDIPlus_GraphicsDispose($hImage1)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrushed)
    Return $hBitmap1
EndFunc ;==>_drawtext

Func _GetTextSize($nText, $iFontSize = 8.5, $sFont = 'Microsoft Sans Serif', $iFontAttributes = 0)
    ;Author: Bugfix
    ;Modified: funkey
    If $nText = '' Then Return
    Local $hGUI = GUICreate("Textmeter by Bugfix")
    _GDIPlus_Startup()
    Local $hFormat = _GDIPlus_StringFormatCreate(0)
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontAttributes, 3)
    Local $tLayout = _GDIPlus_RectFCreate(15, 171, 0, 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Local $aSize[2] = [$iWidth, $iHeight]
    Return $aSize
EndFunc ;==>_GetTextSize

Func _drawicon($bitmap, $width, $height,$lpos, $ico, $ind)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
    $hIcon = _WinAPI_SHExtractIcons($ico, $ind, 32, 32)
    $hDC = _WinAPI_GetDC(0)
    $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBackSv = _WinAPI_SelectObject($hBackDC, $hbmp)
    If $hIcon <> 0 Then _WinAPI_DrawIconEx($hBackDC, $lpos, $height / 2 - 15, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
    $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_SelectObject($hBackDC, $hBackSv)
    _WinAPI_DeleteDC($hBackDC)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DestroyIcon($hIcon)
    Return $bitmap
    Return
EndFunc ;==>_drawicon

Func _WinAPI_SHExtractIcons($sIcon, $iIndex, $iWidth, $iHeight)
    Local $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
    If (@error) Or ($Ret[0] = 0) Or ($Ret[5] = Ptr(0)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[5]
EndFunc ;==>_WinAPI_SHExtractIcons

Func SetBitmap__OK_($hGUI, $hImage, $iOpacity)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld
    Local Const $AC_SRC_ALPHA = 1
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc

; ====== Examples calling _ImageColorRegExpReplace() =========================
; Note colour format hex 0xBBGGRRAA - Blue, Green, Red, Alpha (transparency)

;$hImage2 = _ImageColorRegExpReplace($hImage, "(000000FF)" , "FFFFFFFF" ); Change black to white
;$hImage2 = _ImageColorRegExpReplace($hImage, "(FFFFFFFF)" , "FFFFFF00" ); Change white to transparent
; $hImage2 = _ImageColorRegExpReplace($hImage, "(([0-1][0-9A-F]){3})(FF)" , "${1}00" ); Change near to white to transparent
;$hImage2 = _ImageColorRegExpReplace($hImage, "(FF0000FF|0000AAFF|FFFFFFFF)", "000000FF"); Change blue, off red, white to black

;Swap red and blue channels on half the image. Image is 400x300 = 120,000 pixels. Number of pixels to replace is 60,000.
;$hImage2 = _ImageColorRegExpReplace($hImage, "([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})(FF)", "${3}${2}${1}${4}", 60000)

;$hImage2 = _ImageColorRegExpReplace($hImage, "(([0-9E-F]){6})(FF)", "0000FFFF"); Change near to white to red

; $hImage2 = _ImageColorRegExpReplace($hImage, "av", "FF0000FF"); Change Average colour to blue in BBGGRRAA hex colour format.
;==============================================================================================
Func _ImageColorRegExpReplace($hImage, $iColSrch, $iColNew, $iCount = 0)
    Local $Reslt, $stride, $format, $Scan0, $iIW, $iIH, $hBitmap1
    Local $v_BufferA, $AllPixels, $sREResult1, $sResult

    $iIW = _GDIPlus_ImageGetWidth($hImage)
    $iIH = _GDIPlus_ImageGetHeight($hImage)

    $hBitmap1 = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iIW, $iIH, $GDIP_PXF32ARGB)

    ; Locks a portion of a bitmap for reading or writing
    $Reslt = _GDIPlus_BitmapLockBits($hBitmap1, 0, 0, $iIW, $iIH, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)

    ;Get the returned values of _GDIPlus_BitmapLockBits ()
    $width = DllStructGetData($Reslt, "width")
    $height = DllStructGetData($Reslt, "height")
    $stride = DllStructGetData($Reslt, "stride")
    $format = DllStructGetData($Reslt, "format")
    $Scan0 = DllStructGetData($Reslt, "Scan0")

    $v_BufferA = DllStructCreate("byte[" & $height * $width * 4 & "]", $Scan0) ; Create DLL structure for all pixels
    $AllPixels = DllStructGetData($v_BufferA, 1)
    ;ConsoleWrite("$AllPixels, raw data, first 9 colours = " & StringRegExpReplace($AllPixels, "(.{98})(.*)", "\1") & @CRLF)

    ; Searches on this string - $sREResult1 whch has the prefix "0x" removed and a space put between pixels 8 characters long.
    $sREResult1 = StringRegExpReplace(StringTrimLeft($AllPixels, 2), "(.{8})", "\1 ")
    ;ConsoleWrite("$sREResult1 first 9 colours = " & StringRegExpReplace($sREResult1, "(.{81})(.*)", "\1") & @CRLF)

    ;====================== Average colour ===============================
    If StringInStr($iColSrch, "av") > 0 Then
        Local $iBlue, $iGreen, $iRed, $iAlpha, $avBlue, $avGreen, $avRed, $aviAlpha
        For $x = 1 To StringLen($sREResult1) Step 9
            $iBlue += Dec(Hex("0x" & StringMid($sREResult1, $x, 2)))
            $iGreen += Dec(Hex("0x" & StringMid($sREResult1, $x + 2, 2)))
            $iRed += Dec(Hex("0x" & StringMid($sREResult1, $x + 4, 2)))
            $iAlpha += Dec(Hex("0x" & StringMid($sREResult1, $x + 6, 2)))
            ;MsgBox(0,"","0x" & Hex($iAlpha,2) & Hex($iRed,2) & Hex($iGreen,2) & Hex($iBlue,2) )
        Next
        $avBlue = Hex(Round($iBlue / ($height * $width), 0), 2)
        $avGreen = Hex(Round($iGreen / ($height * $width), 0), 2)
        $avRed = Hex(Round($iRed / ($height * $width), 0), 2)
        $aviAlpha = Hex(Round($iAlpha / ($height * $width), 0), 2)

        MsgBox(0, "", "$width = " & $width & @CRLF & _
                "$height = " & $height & @CRLF & _
                "Blue = " & $avBlue & @CRLF & _
                "$iGreen = " & $avGreen & @CRLF & _
                "$iRed = " & $avRed & @CRLF & _
                "$iAlpha = " & $aviAlpha & @CRLF & _
                "Av.Col ARGB = " & "0x" & $aviAlpha & $avRed & $avGreen & $avBlue)

        Local $iRnge = 30 ; Range 30 is plus or minus 15 for each colour channel, max 0xFF and min 0x00.
    EndIf
    ;=================> End of Average colour ===============================

    If StringInStr($iColNew, "0x") > 0 Then $iColNew = StringReplace($iColNew, "0x", ""); Remove "0x" not needed

    ; StringRegExpReplace performed and white spaces removed
    $sResult = StringStripWS(StringRegExpReplace($sREResult1, $iColSrch, $iColNew, $iCount), 8)

    ; Replace "0x" prefix and set modified data back to DLL structure, $v_BufferA
    DllStructSetData($v_BufferA, 1, "0x" & $sResult)
    _GDIPlus_BitmapUnlockBits($hBitmap1, $Reslt) ; releases the locked region

    Return $hBitmap1
EndFunc ;==>_ImageColorRegExpReplace

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <Constants.au3>
_GDIPlus_Startup()
Global $Image1 = _GDIPlus_ImageLoadFromFile("normal.png")
   Global $width2=_GDIPlus_ImageGetWidth($Image1)
   Global $height2=_GDIPlus_ImageGetHeight($Image1)
$gui=guicreate("", $width2,$height2,-1,-1)

$pic=GUICtrlCreatePic("",0,0,$width2,$height2)
createbutton_3($pic, "Picture", "Arial", 12, 0, "0xFFFFFF", 0)

    _GDIPlus_ImageDispose($Image1)
_GDIPlus_Shutdown()
GUISetState()
while 1
sleep(100)
WEnd
Func createbutton_3($control, $text = "", $font = "Arial", $size = 12, $style = 0, $fontcol = "0xFFFFFF", $halign = 0)
    

    
    If $font = "" Then $font = "Arial"
    If $size = "" Then $size = "12"
    If $style = "" Then $style = 0
    If $fontcol = "" Then $fontcol = "0x222222"
    If $halign = "" Then $halign = 0
    $hwd = GUICtrlGetHandle($control)
    ;$guiname=_WinAPI_GetParent($hwd)
    $width = _WinAPI_GetClientWidth($hwd)
    $height = _WinAPI_GetClientHeight($hwd)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd)

    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
        _GDIPlus_GraphicsDrawImageRect($hImage1, $Image1,-5,-5,$width2,$height2)
        $hBitmap1 = _drawicon($hBitmap1, $width, $height,0,  "C:\applications\opera10\opera.exe", "0")
        $hBitmap1 = _drawicon($hBitmap1, $width, $height,32,  "C:\WINDOWS\NOTEPAD.EXE", "0")


    If Not $text = "" Then $hBitmap1 = _drawtext($hBitmap1, $width, $height, $text, $font, $size, $style, $fontcol)
    _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2)
    $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
    _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1))
    _GDIPlus_GraphicsDispose($hImage1)
    _WinAPI_DeleteObject($hBMP1)
    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic)
    
EndFunc ;==>createbutton_3

Func _drawtext($hBitmap1, $leftpos, $toppos, $text, $font, $size, $style, $fontcol)
    $hImage1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    $fcol = StringReplace($fontcol, "0x", "0xFF")
    $hBrushed = _GDIPlus_BrushCreateSolid($fcol)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate($font)
    $hFont = _GDIPlus_FontCreate($hFamily, $size, $style)
    $tLayout = _GDIPlus_RectFCreate($leftpos, $toppos, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hImage1, $text, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    $tLayout = _GDIPlus_RectFCreate(70, ($toppos / 2) - ($iHeight / 2)-7, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString($hImage1, $text, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hImage1, $text, $hFont, $aInfo[0], $hFormat, $hBrushed)
    _GDIPlus_GraphicsDispose($hImage1)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrushed)
    Return $hBitmap1
EndFunc ;==>_drawtext

Func _GetTextSize($nText, $iFontSize = 8.5, $sFont = 'Microsoft Sans Serif', $iFontAttributes = 0)
    ;Author: Bugfix
    ;Modified: funkey
    If $nText = '' Then Return
    Local $hGUI = GUICreate("Textmeter by Bugfix")
    _GDIPlus_Startup()
    Local $hFormat = _GDIPlus_StringFormatCreate(0)
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontAttributes, 3)
    Local $tLayout = _GDIPlus_RectFCreate(15, 171, 0, 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Local $aSize[2] = [$iWidth, $iHeight]
    Return $aSize
EndFunc ;==>_GetTextSize

Func _drawicon($bitmap, $width, $height,$lpos, $ico, $ind)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
    $hIcon = _WinAPI_SHExtractIcons($ico, $ind, 32, 32)
    $hDC = _WinAPI_GetDC(0)
    $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBackSv = _WinAPI_SelectObject($hBackDC, $hbmp)
    If $hIcon <> 0 Then _WinAPI_DrawIconEx($hBackDC, $lpos+10, 6, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
    $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_SelectObject($hBackDC, $hBackSv)
    _WinAPI_DeleteDC($hBackDC)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DestroyIcon($hIcon)
    Return $bitmap
    Return
EndFunc ;==>_drawicon

Func _WinAPI_SHExtractIcons($sIcon, $iIndex, $iWidth, $iHeight)
    Local $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
    If (@error) Or ($Ret[0] = 0) Or ($Ret[5] = Ptr(0)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[5]
EndFunc ;==>_WinAPI_SHExtractIcons

Func SetBitmap__OK_($hGUI, $hImage, $iOpacity)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld
    Local Const $AC_SRC_ALPHA = 1
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc
Edited by picea892

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

---

Edited by playlet

Share this post


Link to post
Share on other sites

One other possible workaround is using a gdiclip. Still not the correct solution though. The best solution would be to never have the black background appear.

Goodluck. I hope someone can help

Share this post


Link to post
Share on other sites

Try the examples / functions from this UDF and see if it works for you:

http://www.autoitscript.com/forum/index.php?showtopic=92675

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

---

Edited by playlet

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

---

Edited by playlet

Share this post


Link to post
Share on other sites

http://www.autoitscript.com/forum/index.php?showtopic=102626&st=0&p=728034&hl=save%20png&fromsearch=1&#entry728034

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

---

Edited by playlet

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Hi,

It may not be a disposal problem, but more of a redraw problem.

I think you need to insert one of these lines, just a guess, if it doesn't work, maybe give some code we can play with. (replace $taskbar with either your gui name or the handle to a control)

_WinAPI_RedrawWindow($taskbar,0,0,BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW,$RDW_FRAME,$RDW_ALLCHILDREN)) ; works, but redraws entire screen.
_WinAPI_RedrawWindow($taskbar, "", "", BitOR($WM_ERASEBKGND, $RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))

You can also redraw only a certain location on the window by passing a rect. That might be worth exploring in order to reduce flicker.

Edited by picea892

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

---

Edited by playlet

Share this post


Link to post
Share on other sites

Yes, I think you are right in your decision. When I provided you the "_winapi_redrawwindow" code I started to remember a previous project I worked on (windows 7 taskbar). One the main problems I had with that code was flickering. You would have had a serious flicker problem if you updated labels every few seconds.

As for the other labels. I think the guictrllabels is working well enough, probably don't need to change. A lot of it rests with personal preference I think.

I personally stay away from child gui's as much as possible for rendering one window because of problems with focus that arise. I usually navigate with keyboard as much as possible and guictrl focus is a pet peeve of mine:) I can't see how this problem could apply in your application. You are using a mouse to access it.....

Where you might consider implementing as I suggested is if you want to have large and small font or two different colours on the same label. You would be looking at having more than one label in that case, could get messy quick, would probably be cleaner to draw it right on. I guess the decision rests on what is simplest, in your case I think you landed on the simpler solution.

I'm really glad you've got this figured out, I'm curious to see how you worked smashly's code into yours.

Picea

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

---

Edited by playlet

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