Hi,
ich bin dabei eine Listview farbig einfärben, was auch so weit mit diesem Code klappt:
; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
#include <HeaderConstants.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WinAPISysWin.au3>
#include <GuiListView.au3>
#include <GDIPlus.au3>
#Region Variablen
;Color with 6-digit
Global Const $iColorBK_GUI6 = 0x13161F
Global Const $iColorCtrlActive_GUI6 = 0x353840
Global Const $iColorText_GUI6 = 0xFFFFFF ;Text Color
;Color with 8-digit
Global Const $iColorCtrlActive_GUI8 = 0xFF353840
Global Const $iColorText_GUI8 = 0xFFFFFFFF ;Text Color
;Listview
Global $aListviewColumNames = ["Column 1", "Column 2", "Column 3", ""]
Global Const $tagNMCUSTOMDRAW = "struct;" & $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;endstruct"
#EndRegion Variablen
#Region - hGui
#Region - Create GUI
Global $hGUI = GUICreate("Masetcam Settings Switch", 500, 300);, -1, -1, BitOR($WS_POPUP, $WS_BORDER))
GUISetBkColor($iColorBK_GUI6)
;Fenstergröße bestimmen
Local $aWinPos = WinGetPos($hGUI)
Global $GUI_Width = $aWinPos[2]
Global $GUI_Height = $aWinPos[3]
#EndRegion - Create GUI
#Region - Main Gui
Local $gListviewPoints = _GUICtrlListView_Create($hGUI, "", 10,10, 480, 280, -1, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetBkColor($gListviewPoints, _WinAPI_SwitchColor($iColorCtrlActive_GUI6))
_GUICtrlListView_SetTextColor($gListviewPoints, _WinAPI_SwitchColor($iColorText_GUI6))
_GUICtrlListView_SetTextBkColor($gListviewPoints, _WinAPI_SwitchColor($iColorText_GUI8))
_GUICtrlListView_AddColumn($gListviewPoints, "1Test Header", 100)
_GUICtrlListView_AddColumn($gListviewPoints, "2Test Header", 100)
_GUICtrlListView_AddColumn($gListviewPoints, "3Test Header", 100)
_GUICtrlListView_AddItem($gListviewPoints, "Row 0: Col 0",0)
_GUICtrlListView_AddSubItem($gListviewPoints, 0, "Row 0: Col 1", 1)
_GUICtrlListView_AddSubItem($gListviewPoints, 0, "Row 0: Col 2", 2)
_GUICtrlListView_AddItem($gListviewPoints, "Row 1: Col 0",0)
_GUICtrlListView_AddSubItem($gListviewPoints, 1, "Row 1: Col 1", 1)
_GUICtrlListView_AddSubItem($gListviewPoints, 1, "Row 1: Col 2", 2)
_GUICtrlListView_AddItem($gListviewPoints, "Row 2: Col 0",0)
_GUICtrlListView_AddSubItem($gListviewPoints, 2, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($gListviewPoints, 2, "Row 2: Col 2", 2)
_GUICtrlListView_AddItem($gListviewPoints, "Row 3: Col 0",0)
_GUICtrlListView_AddSubItem($gListviewPoints, 3, "Row 3: Col 1", 1)
_GUICtrlListView_AddSubItem($gListviewPoints, 3, "Row 3: Col 2", 2)
GUISetState(@SW_SHOW, $hGUI)
#EndRegion - Main Gui
#EndRegion - hGui
#Region - Activate Stuff
;GDIPlus starten
_GDIPlus_Startup()
;Listview Header einfärben
Global $hHeader = _GUICtrlListView_GetHeader($gListviewPoints) ;Get Header handle
Global $hHdrFont = Listview_getHeaderFont($hHeader)
;WM_ Funktionen registieren
GUIRegisterMsg($WM_Notify, "WM_NOTIFY")
_GUICtrlListView_SetColumnWidth($gListviewPoints, _GUICtrlListView_AddColumn($gListviewPoints, "", 99), 50)
_GUICtrlListView_BeginUpdate($gListviewPoints)
_GUICtrlListView_EndUpdate($gListviewPoints)
#EndRegion - Activate Stuff
Func Listview_getHeaderFont($hHeader)
Local $hDC = _WinAPI_GetDC($hHeader) ;Get Font of the Header Control
Local $hFont = _SendMessage($hHeader, $WM_GETFONT)
Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
Local $tLogFont = DllStructCreate($tagLOGFONT)
_WinAPI_GetObject($hFont, DllStructGetSize($tLogFont), DllStructGetPtr($tLogFont))
_WinAPI_SelectObject($hDC, $hObject)
_winapi_ReleaseDC($hHeader, $hDC)
Local $iWeight = DllStructGetData($tLogFont, "Weight")
DllStructSetData($tLogFont, "Weight", $iWeight)
$hHdrFont = _WinAPI_CreateFontIndirect($tLogFont)
EndFunc
#Region While
While 1
Switch GUIGetMsg() ;Empfängt alle klicks auf Buttons und verarbeitet diese
Case $GUI_EVENT_CLOSE ;hGui (Main Gui)
GUIDelete($hGUI) ;Gui löschen
Exit
EndSwitch
WEnd
#EndRegion While
#Region Functions
#STOP DBUG
#Region - WM_Notify
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iMsg, $iwParam
Local $hWndFrom, $iCode, $tNMHDR, $tDropFiles, $hDrop, $aFileList, $sFileString
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd($tNMHDR.hWndFrom)
$iCode = $tNMHDR.Code
Switch $hWndFrom
Case $hHeader
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tNMCustomDraw = DllStructCreate($tagNMCUSTOMDRAW, $ilParam)
Local $dwDrawStage = DllStructGetData($tNMCustomDraw,"dwDrawStage") ;Draw stage abrufen
Switch $dwDrawStage
Case $CDDS_PREPAINT ;Stage bevor der Zeichen Prozess beginnt
Return $CDRF_NOTIFYITEMDRAW ;Notify parent window of any item related drawing operations
Case $CDDS_ITEMPREPAINT ;Before an item is drawn: Default painting (frames and background)
Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations
Case $CDDS_ITEMPOSTPAINT ;After an item is drawn: Custom painting (item texts)
Local $iTextOffsetX = 0, $iTextOffsetY = 0, $sFont = "Arial", $iFontSize = 10, $iFontStyle = 0, $iAlign = 0, $iLineAlign = 1
Local $tRECT = DllStructCreate($tagRECT)
Local $iIndex = DllStructGetData($tNMCustomDraw, "dwItemSpec") ;Item index
Local $hDC = DllStructGetData($tNMCustomDraw, "hdc") ;Device context
_WinAPI_SelectObject($hDC, $hHdrFont) ;Set text font
_WinAPI_SetBkMode($hDC, 0xFF00A000) ;Transparent background
_WinAPI_SetTextColor($hDC, _WinAPI_SwitchColor($iColorText_GUI6)) ;Set text colour
;Get header section size
$tRECT.Left = DllStructGetData($tNMCustomDraw, 6); + 1)
$tRECT.Top = DllStructGetData($tNMCustomDraw, 7); + 1)
$tRECT.Right = DllStructGetData($tNMCustomDraw, 8); - 1
$tRECT.Bottom = DllStructGetData($tNMCustomDraw, 9); - 1
;GDI Starten und
;Hintergrund
Local $hDCGrafik = _GDIPlus_GraphicsCreateFromHDC($hDC) ;Zechenfläche
Local $hBrush = _GDIPlus_BrushCreateSolid($iColorCtrlActive_GUI8) ;Rechteck ausfüllen
Local $hPen =_GDIPlus_PenCreate("0xFF" & Hex(_WinAPI_ColorAdjustLuma($iColorCtrlActive_GUI6, 20), 6)) ;Linien
;Text
Local $hBrushTxt = _GDIPlus_BrushCreateSolid($iColorText_GUI8) ;Pinsel
Local $hFormat = _GDIPlus_StringFormatCreate() ;Format
Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) ;Font Family
Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontStyle) ;Font
Local $tLayout = _GDIPlus_RectFCreate($tRECT.Left + $iTextOffsetX, $tRECT.Top+$iTextOffsetY, $tRECT.Right - $tRECT.Left, $tRECT.Bottom - $tRECT.Top) ;Rechteck in dem der String kommt
_GDIPlus_StringFormatSetAlign($hFormat, $iAlign) ;Width Ausrichtung
_GDIPlus_StringFormatSetLineAlign($hFormat, $iLineAlign) ;Hight Ausrichtung
;Hintergurnd zeichnen
_GDIPlus_GraphicsFillRect($hDCGrafik, $tRECT.Left, $tRECT.Top, $tRECT.Right, $tRECT.Bottom, $hBrush)
_GDIPlus_GraphicsDrawLine($hDCGrafik, $tRECT.Left, $tRECT.Bottom-1, $tRECT.Right, $tRECT.Bottom-1, $hPen)
_GDIPlus_GraphicsDrawLine($hDCGrafik, $tRECT.Right-1, $tRECT.Bottom-1, $tRECT.Right-1, $tRECT.Top, $hPen)
;Text schreiben
_GDIPlus_GraphicsDrawStringEx($hDCGrafik, $aListviewColumNames[$iIndex], $hFont, $tLayout, $hFormat, $hBrushTxt) ;Zeichnet den String
;Resoursen frei geben
;Bild
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hDCGrafik)
;Text
_GDIPlus_BrushDispose($hBrushTxt)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
Return $CDRF_NEWFONT ;$CDRF_NEWFONT must be returned after changing font or colors
EndSwitch
Case $HDN_BEGINTRACKW
Local $tNMHeader = DllStructCreate($tagNMHEADER, $ilParam)
Local $iIndex = $tNMHeader.Item
If $iIndex = _GUICtrlListView_GetColumnCount($gListviewPoints)-1 Then
Return True
Else
Return False
EndIf
Case $HDN_ITEMCHANGINGW
_GUICtrlListView_BeginUpdate($gListviewPoints)
Case $HDN_ITEMCHANGEDW
;~ ConsoleWrite(" ")
;Find Chanched-Item
Local $tNMHeader = DllStructCreate($tagNMHEADER, $ilParam)
Local $iIndex = $tNMHeader.Item
;If Chanched-Item is the last one then return
If $iIndex = _GUICtrlListView_GetColumnCount($gListviewPoints)-1 Then
Return $GUI_RUNDEFMSG
EndIf
;Get Positions and Sizes
Local $aPosControl = ControlGetPos($hGUI, "", $gListviewPoints)
Local $aPosLastSubitem = _GUICtrlListView_GetSubItemRect($gListviewPoints, 0, _GUICtrlListView_GetColumnCount($gListviewPoints)-1)
;passt die Größe der letzten Spalte an, damit der Header immer mindestens so groß ist, wie die Listview und kein weißer rand entsteht.
If $aPosControl[2] < $aPosLastSubitem[0] And ($aPosLastSubitem[2] - $aPosLastSubitem[0]) <> 50 Then
;~ ConsoleWrite("1" & @CRLF)
_GUICtrlListView_SetColumnWidth($gListviewPoints, _GUICtrlListView_GetColumnCount($gListviewPoints)-1, 1)
ElseIf $aPosControl[2] <> $aPosLastSubitem[2] Then
;~ ConsoleWrite("2" & @CRLF)
_GUICtrlListView_SetColumnWidth($gListviewPoints, _GUICtrlListView_GetColumnCount($gListviewPoints)-1, $aPosControl[2] - $aPosLastSubitem[0])
EndIf
_GUICtrlListView_EndUpdate($gListviewPoints)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
#EndRegion - WM_Notify
#START DBUG
#EndRegion Functions
Alles anzeigen
Damit der Weiße Bereich oben rechts verschwindet habe ich eine Weiter Spalte eingefügt, Welche man von hand nicht größer oder kleiner machen kann, dafür aber sich dafür aber automatisch bis zum Rechten rand ausdehnt, sobald man eine Spalte in der größe verändert.
Das klappt auch und sieht so weit gut aus, bis die Vorletzte Spalte so groß ist, das eine scroll bar angezeigt wird, dann verschwinden die ganzen farbigen Header Elemente.
Wenn man das erste oder die beiden unteren ";~" entfernt, dann funktioniert es, bis man es Compaliert, da dann scheinbar ConsolWrite nicht mehr ausgeführt wird oder es seine Magische Eigenschaft verliert.
Kann mir da jemand helfen?
Noch alles gut:
Wärend Column 2 Größer gemacht wird und Colum 3 rechts zu groß ist:
Mit freundlichen Grüßen
Florian Etzel