Hi rcmaehl
Here is the display when I launch your script (the light grey background comes from my Windows theme, on your computer it's probably a white background) :
So you're asking how to get rid of the red background displayed behind the icon ?
I was lucky to find this thread where Yashied attached a function named _SetBkIcon()
Unfortunately his function can't be downloaded from there as it's not hosted on AutoIt. Trying some google search, I found Yashied's function inside a script from funkey.
Here is the result, based on the way you scripted it (the icon over the label) :
#Include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>
Example()
Func Example()
$hGUI = GUICreate("Icons", 200, 250)
$BKC = _WinAPI_GetSysColor($COLOR_WINDOW) ; window background (help file)
; ConsoleWrite("0x" & Hex($BKC, 6) & @crlf) ; 0xE3DFE0 (light grey, my windows theme)
GUISetBkColor(0xFF0000) ; red (Gui)
GUICtrlSetDefColor(0x0000FF) ; blue (controls)
GUICtrlSetDefBKColor(0x00FF00) ; green (controls)
GUICtrlCreateLabel("test label", 0, 0, 100, 20, BitOR($SS_CENTERIMAGE, $SS_CENTER)) ; blue on green
GUICtrlCreateLabel("", 0, 20, 100, 230)
GUICtrlSetBkColor(-1, $BKC) ; light grey (background)
$Icon1 = GUICtrlCreateIcon('', -1, 30, 40) ; left, top
$Icon2 = GUICtrlCreateIcon('', -1, 20, 100)
$Icon3 = GUICtrlCreateIcon('', -1, 25, 180)
_GDIPlus_Startup()
_SetBkIcon($Icon1, $BKC, @SystemDir & '\shell32.dll', 10, 32, 32) ; icon #10, width, height
_SetBkIcon($Icon2, $BKC, @SystemDir & '\shell32.dll', 130, 48, 48)
_SetBkIcon($Icon3, $BKC, @SystemDir & '\shell32.dll', 131, 48, 48)
_GDIPlus_Shutdown()
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
GUIDelete()
EndFunc ;==>Example
;============================================================================
Func _SetBkIcon($ControlID, $iBackground, $sIcon, $iIndex, $iWidth, $iHeight)
Local Static $STM_SETIMAGE = 0x0172
Local $tIcon, $tID, $hDC, $hBackDC, $hBackSv, $hBitmap, $hImage, $hIcon, $hBkIcon
$tIcon = DllStructCreate('hwnd')
$tID = DllStructCreate('hwnd')
$hIcon = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0)
If (@error) Or ($hIcon[0] = 0) Then
Return SetError(1, 0, 0)
EndIf
$hIcon = DllStructGetData($tIcon, 1)
$tIcon = 0
$tID = 0
$hDC = _WinAPI_GetDC(0)
$hBackDC = _WinAPI_CreateCompatibleDC($hDC)
$hBitmap = _WinAPI_CreateSolidBitmap(0, $iBackground, $iWidth, $iHeight)
$hBackSv = _WinAPI_SelectObject($hBackDC, $hBitmap)
_WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, 0, 0, 0, 0, $DI_NORMAL)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$hBkIcon = DllCall($__g_hGDIPDll, 'int', 'GdipCreateHICONFromBitmap', 'hWnd', $hImage, 'int*', 0)
$hBkIcon = $hBkIcon[2]
_GDIPlus_ImageDispose($hImage)
GUICtrlSendMsg($ControlID, $STM_SETIMAGE, $IMAGE_ICON, _WinAPI_CopyIcon($hBkIcon))
_WinAPI_RedrawWindow(GUICtrlGetHandle($ControlID))
_WinAPI_SelectObject($hBackDC, $hBackSv)
_WinAPI_DeleteDC($hBackDC)
_WinAPI_ReleaseDC(0, $hDC)
_WinAPI_DeleteObject($hBkIcon)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteObject($hIcon)
Return SetError(0, 0, 1)
EndFunc ;==>_SetBkIcon
Hope it helps and good luck