Hallo Zusammen,
Ich würde auf meinem gerne GUICtrlSetImage anwenden, doch sobald ich den Buttonhintergrund auf schwarz ändere, was ziemlich wichtig für mein Programm ist, verschwindet das Icon auf dem Button.
Kann mir jemand weiter helfen?
Hallo Zusammen,
Ich würde auf meinem gerne GUICtrlSetImage anwenden, doch sobald ich den Buttonhintergrund auf schwarz ändere, was ziemlich wichtig für mein Programm ist, verschwindet das Icon auf dem Button.
Kann mir jemand weiter helfen?
Wo ist Dein Script?
Ach ja @Oscar
#include <GUIButton.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$GUI = GUICreate("",100,100)
GUISetBkColor(0x00000)
$Button_Refresh = GUICtrlCreateButton("",30,30,30,30,$BS_ICON)
GUICtrlSetBkColor(-1,0x00000)
GUICtrlSetImage(-1,@ScriptDir & "\ICO.ico",3,1)
GUISetState(@SW_SHOW, $GUI)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Alles anzeigen
Lol...
Wirklich niemand eine Idee?
SO?
#include <GUIButton.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIShellEx.au3>
#include <WinAPIGdi.au3>
$GUI = GUICreate("", 100, 100)
GUISetBkColor(0x0)
Global $hIcon = _WinAPI_ShellExtractIcon(@ScriptDir & "\ICO.ico", 0, 48, 48)
$Button_Refresh = GUICtrlCreateButton("", 30, 30, 30, 30)
GUICtrlSetStyle($Button_Refresh, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW))
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUISetState(@SW_SHOW, $GUI)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_WinAPI_DestroyIcon($hIcon)
Exit
EndSwitch
WEnd
Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam)
#forceref $iMsg, $wParam, $lParam
Local $tDrawItem = DllStructCreate("uint CtlType; uint CtlID; uint ItemID; uint ItemAction; uint ItemState; hwnd hWndItem; hwnd hDC; int Left; int Top; int Right; int Bottom; ptr ItemData;", $lParam)
Local Const $ODT_BUTTON = 4
Switch $tDrawItem.CtlType
Case 4 ;ODT_BUTTON
Switch $tDrawItem.CtlID
Case $Button_Refresh
_WinAPI_ExtFloodFill($tDrawItem.hDC, 0, 0, 0)
_WinAPI_DrawIconEx($tDrawItem.hDC, $tDrawItem.Left, $tDrawItem.Top, $hIcon, $tDrawItem.Right - $tDrawItem.Left, $tDrawItem.Bottom - $tDrawItem.Top)
Return 1
EndSwitch
EndSwitch
$tDrawItem = 0
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_DRAWITEM
Alles anzeigen
Vielen Dank @eukalyptus
_WinAPI_ExtFloodFill($tDrawItem.hDC, 0, 0, 0)
Wie ich gerade festgestellt habe, zeigt diese Funktion keine Wirkung in deinem Script.
So funktioniert es aber...
;-- TIME_STAMP 2017-04-04 21:34:08
#Region ;************ Includes ************
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <WinAPIShellEx.au3>
#include <WinAPIGdi.au3>
#EndRegion ;************ Includes ************
Global $GUI = GUICreate("", 150, 160, -1, -1)
GUISetBkColor(0x0)
Global $hIcon = _WinAPI_ShellExtractIcon("shell32.dll", 170, 48, 48)
Global $idButton_Refresh = GUICtrlCreateButton("", 20, 20, 60, 60)
Global Const $hBrush1 = _WinAPI_CreateBrushIndirect($BS_SOLID, 0xFF0000), $hBrush2 = _WinAPI_CreateBrushIndirect($BS_SOLID, 0x00FF00), $hBrush3 = _WinAPI_CreateBrushIndirect($BS_SOLID, 0x0000FF)
GUICtrlSetStyle($idButton_Refresh, BitOR($WS_TABSTOP, $BS_CENTER, $BS_NOTIFY, $BS_OWNERDRAW))
GUIStartGroup()
Global $idRadio_ExtFloodFill = GUICtrlCreateRadio("_WinAPI_ExtFloodFill", 20, 120, 160, 20)
Global $idRadio_FillRect = GUICtrlCreateRadio("_WinAPI_FillRect", 20, 140, 160, 20)
GUICtrlSetState($idRadio_FillRect, $GUI_CHECKED)
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUISetState(@SW_SHOW, $GUI)
ConsoleWrite('$BST_PUSHED = ' & $BST_PUSHED & @CRLF)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_WinAPI_DestroyIcon($hIcon)
Exit
Case $idButton_Refresh
EndSwitch
WEnd
_WinAPI_DeleteObject($hBrush1)
_WinAPI_DeleteObject($hBrush2)
_WinAPI_DeleteObject($hBrush3)
Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam)
#forceref $iMsg, $wParam, $lParam
Local $iFill, $tPoint, $tDrawItem = DllStructCreate("uint CtlType; uint CtlID; uint ItemID; uint ItemAction; uint ItemState; hwnd hWndItem; hwnd hDC; int Left; int Top; int Right; int Bottom; ptr ItemData;", $lParam)
Local Const $ODT_BUTTON = 4
Local Static $iInit = 0, $hBrush = ''
Switch $tDrawItem.CtlType
Case 4 ;ODT_BUTTON
Switch $tDrawItem.CtlID
Case $idButton_Refresh
; Button - nicht gedrückt = $hBrush1 (rot), gedrückt = $hBrush2 (grün), Button inaktiv = $hBrush3 (blau)
Switch True
Case BitAnd($tDrawItem.ItemState, 0x11) = 0x11
If $iInit > 1 Then ConsoleWrite('+ $idButton_Refresh is pressed... $tDrawItem.ItemState = 0x' & Hex($tDrawItem.ItemState) & ' _GUICtrlButton_GetState = 0x' & Hex(_GUICtrlButton_GetState($idButton_Refresh)) & @CRLF)
$hBrush = $hBrush2
$iFill = 0x0FF0000
$tDrawItem.Left += 5
$tDrawItem.Top += 5
Case BitAnd($tDrawItem.ItemState, 0x10) = 0x10
If $iInit > 1 Then ConsoleWrite('! $idButton_Refresh is released... $tDrawItem.ItemState = 0x' & Hex($tDrawItem.ItemState) & ' _GUICtrlButton_GetState = 0x' & Hex(_GUICtrlButton_GetState($idButton_Refresh)) & @CRLF)
$hBrush = $hBrush1
$iFill = 0x00FF00
Case Else
ConsoleWrite('> Button Focus lost... $tDrawItem.ItemState = 0x' & Hex($tDrawItem.ItemState) & ' _GUICtrlButton_GetState = 0x' & Hex(_GUICtrlButton_GetState($idButton_Refresh)) & @CRLF)
$hBrush = $hBrush3
$iFill = 0x0000FF
EndSwitch
$iInit += 1
Switch _IsChecked($idRadio_FillRect)
Case True
; So funktioniert es!
ConsoleWrite('- _WinAPI_FillRect...' & @CRLF)
$tRECT = _WinAPI_GetClientRect($tDrawItem.hWndItem)
_WinAPI_FillRect($tDrawItem.hDC, $tRECT, $hBrush)
Case Else
; So funktioniert es NICHT!
ConsoleWrite('- _WinAPI_ExtFloodFill...' & @CRLF)
_WinAPI_ExtFloodFill($tDrawItem.hDC, 0, 0, $iFill, $FLOODFILLBORDER)
EndSwitch
_WinAPI_DrawIconEx($tDrawItem.hDC, $tDrawItem.Left, $tDrawItem.Top, $hIcon, $tDrawItem.Right - $tDrawItem.Left, $tDrawItem.Bottom - $tDrawItem.Top)
Return 1
EndSwitch
EndSwitch
$tDrawItem = 0
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_DRAWITEM
Func _IsChecked($idControlID)
Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc ;==>_IsChecked
Alles anzeigen