Dear Ladies and Sirs
I want to apply a colored icon to my Tab-Control.
This works well if I have the file present as ".ico" file.
Now I want to apply an Icon which is defined by HEX-color: e.g. "0xC0C0C0", but can not get it to work.
I have a similiar code to create Bitmap-files (temporary):
;~ ;-------------------------------------------------------------------------------
#include-once
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiMenu.au3>
#include <File.au3>
;~ ;-------------------------------------------------------------------------------
_GDIPlus_Startup() ; Color Icons + Menu Icons ; _GDIPlus_Shutdown()
;~; -------------------------------------------------------------------------------
Local $hWnd = GUICreate("Icon Test", 200, 200)
GUISetState()
Local $idContextmenu = GUICtrlCreateContextMenu()
GUICtrlCreateMenuItem("Item 1", $idContextmenu)
Local $Item2 = GUICtrlCreateMenuItem("Item 2", $idContextmenu)
Local $Menu = GUICtrlCreateMenu("Menu", $idContextmenu)
Local $Item3 = GUICtrlCreateMenuItem("Item 3", $Menu)
Local $hTMP = _Return_colored_BitMapFile("0xC0C0C0", @TempDir) ; ($vColor, $pTargetFolder = Default(TEMP), $vWidth = Default(16), $vHeight = Default(16), $iBitMapFileOut = Default(_TempFile))
;~ Local $hTMP = _Return_colored_BitMapFile("0x345345", @TempDir,Default ,Default,"C:\sdfgdfhg.bmp") ; ($vColor, $pTargetFolder = Default(TEMP), $vWidth = Default(16), $vHeight = Default(16), $iBitMapFileOut = Default(_TempFile))
Local $hBitM = _WinAPI_LoadImage(0, $hTMP, $IMAGE_BITMAP, 16, 16, BitOR($LR_LOADTRANSPARENT, $LR_LOADFROMFILE, $LR_SHARED))
_GUICtrlMenu_SetItemBitmaps(GUICtrlGetHandle($idContextmenu), $Item2, $hBitM, $hBitM, False)
_GUICtrlMenu_SetItemBitmaps(GUICtrlGetHandle($Menu), $Item3, $hBitM, $hBitM, False)
While GUIGetMsg() <> -3
WEnd
_GDIPlus_Shutdown()
; #FUNCTION# ====================================================================================================================
; Name...........: _Return_colored_BitMapFile
; Description ...: Creates a Bitmap file based on a HEX Color
; Syntax.........: _Return_colored_BitMapFile($HexColor, $pTargetFolder = Default, $Width = Default, $Height = Default, $iBitMapFileOut = Default)
; Parameters ....: $HexColor ; Format: 0xDADADA
; Parameters ....: $pTargetFolder ; where to store the file
; Parameters ....: $Width ; width of the file to create
; Parameters ....: $Height ; Height of the file to create
; Parameters ....: $iBitMapFileOut ; Path and extension of the file to create
; Return values .: Success: ; returns path of created bitmap-file
; Return values .: @Error = 1 ; if file was not created
; Remarks .......:
; Related .......: _GDIPlus_BitmapCreateFromScan0, _GDIPlus_ImageSaveToFile
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
;~; ------------------------------------------------------------------------------------------------------
Func _Return_colored_BitMapFile($HexColor, $pTargetFolder = Default, $Width = Default, $Height = Default, $iBitMapFileOut = Default) ; ($Color, $pTargetFolder = Default(TEMP), $Width = Default(16), $Height = Default(16), $iBitMapFileOut = Default(_TempFile))
;~; ------------------------------------------------------------------------------
If $Width = Default Then $Width = 16
If $Height = Default Then $Height = 16
If $pTargetFolder = Default Then
$pTargetFolder = @TempDir
ElseIf StringIsSpace($pTargetFolder) Then
$pTargetFolder = @TempDir
ElseIf DirCreate($pTargetFolder) = 0 Then
$pTargetFolder = @TempDir
EndIf
If $iBitMapFileOut = Default Then $iBitMapFileOut = _TempFile($pTargetFolder, "~", ".bmp", 7) ; NUR bmp !!!
If StringLen($HexColor) <> 8 Then Return SetError(1)
Local $0xAARRGGBB = "0xFF" & StringRight($HexColor, 6) ; weiß(00) ist hier der AlphaKanal
Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($Width, $Height) ; create an empty bitmap
Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; get the graphics context of the bitmap
_GDIPlus_GraphicsSetSmoothingMode($hBmpCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ; muss angegeben werden
_GDIPlus_GraphicsClear($hBmpCtxt, $0xAARRGGBB) ; fill bitmap with color ; Alpha, Red, Green and Blue components.
_GDIPlus_ImageSaveToFile($hBitmap, $iBitMapFileOut) ; save bitmap to disk
If @error Then Return SetError(1) ; file was not created
If Not @Compiled Then ConsoleWrite('> ' & @TAB & @ScriptLineNumber & @TAB & '$hBmpCtxt ' & @TAB & $hBmpCtxt & @CRLF) ; > = blue text color BLAU
If Not @Compiled Then ConsoleWrite('+ ' & @TAB & @ScriptLineNumber & @TAB & '$hBitmap ' & @TAB & $hBitmap & @CRLF) ; > = blue text color BLAU
If FileExists($iBitMapFileOut) Then
Return $iBitMapFileOut ; kein ERROR ; --> Datei-Pfad als ReturnValue
Else
Return SetError(1)
EndIf
EndFunc ;==>_Return_colored_BitMapFile
;~; ------------------------------------------------------------------------------------------------------
Is there a chance to turn the colored bitmap to icon?
Have mercy, I am new to the GDIPlus thing!
Thank you in advance. M.