Fenster im listview item erstellen

  • Hi
    hier möchte ich euch meine funktion vorstellen

    Beispiel:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Constants.au3>
    #include <GuiListView.au3>
    #include <WinAPI.au3>
    #include <Listview Window.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Form1", 600, 350)
    GUIRegisterMsg($WM_NOTIFY, "_ListView_Notify")
    GUIRegisterMsg($WM_SIZE, "_ListView_Notify")

    [/autoit] [autoit][/autoit] [autoit]

    $ListView = GUICtrlCreateListView("Text|Rating", 0, 0, 600, 350 )
    $hWndListview = GUICtrlGetHandle($ListView)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To 40
    GUICtrlCreateListViewItem('Text', $ListView)

    [/autoit] [autoit][/autoit] [autoit]

    _ListView_CreateRating($hWndListview, $i, 1, @ScriptDir & "\Star_Full.gif", @ScriptDir & "\Star_Half.gif", 4.5)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Do
    $msg = GUIGetMsg()
    Until $msg = -3

    [/autoit]

    und hier die funktion:

    Spoiler anzeigen
    [autoit]

    Global $Listview_Window[1][4] = [['Hwnd', 'hwndFrom', 'Index', 'SubIndex']]

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListView_Notify($hWnd, $Msg, $wParam, $lParam)
    If $Msg = $WM_SIZE Then
    _WinAPI_InvalidateRect($hWnd)
    Return $GUI_RUNDEFMSG
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Local $tNMHEADER, $hWndFrom, $iCode, $i

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
    $hWndFrom = DllStructGetData($tNMHEADER, "hwndFrom")
    $iCode = DllStructGetData($tNMHEADER, "Code")

    [/autoit] [autoit][/autoit] [autoit]

    Switch $iCode
    Case $HDN_ITEMCHANGED, $HDN_ITEMCHANGEDW, $LVN_ENDSCROLL
    If $iCode <> $LVN_ENDSCROLL Then $hWndFrom = _WinAPI_GetParent($hWndFrom)
    For $i = 1 To UBound($Listview_Window) -1
    If $Listview_Window[$i][1] = $hWndFrom Then
    _ListView_MoveWindow($hWndFrom, $Listview_Window[$i][0], $Listview_Window[$i][2], $Listview_Window[$i][3])
    EndIf
    Next
    _WinAPI_InvalidateRect($hWndFrom)
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListView_InsertWindow($hWnd, $Index, $SubItemIndex = 0)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    Local $Rect

    [/autoit] [autoit][/autoit] [autoit]

    If BitAND($Style, $WS_CLIPCHILDREN) <> $WS_CLIPCHILDREN Then
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($Style, $WS_CLIPCHILDREN))
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $SubItemIndex = 0 Then
    $Rect = _GUICtrlListView_GetItemRect($hWnd, $Index, 2)
    Else
    $Rect = _GUICtrlListView_GetSubItemRect($hWnd, $Index, $SubItemIndex)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ReDim $Listview_Window[UBound($Listview_Window) +1][UBound($Listview_Window, 2)]

    [/autoit] [autoit][/autoit] [autoit]

    $Listview_Window[UBound($Listview_Window) -1][0] = GUICreate('', $Rect[2]- $Rect[0], $Rect[3] - $Rect[1], $Rect[0], $Rect[1], $WS_CHILD, -1, $Hwnd)
    $Listview_Window[UBound($Listview_Window) -1][1] = $hWnd
    $Listview_Window[UBound($Listview_Window) -1][2] = $Index
    $Listview_Window[UBound($Listview_Window) -1][3] = $SubItemIndex
    GUISetState(@SW_SHOW, $Listview_Window[UBound($Listview_Window) -1][0])
    Return $Listview_Window[UBound($Listview_Window) -1][0]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListView_MoveWindow($hWndListView, $hWndWindow, $Index, $SubItemIndex)
    Local $Rect

    [/autoit] [autoit][/autoit] [autoit]

    If $SubItemIndex = 0 Then
    $Rect = _GUICtrlListView_GetItemRect($hWndListView, $Index, 2)
    Else
    $Rect = _GUICtrlListView_GetSubItemRect($hWndListView, $Index, $SubItemIndex)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $Rect[1] < 10 Then
    _WinAPI_ShowWindow($hWndWindow, 0)
    ElseIf $Rect[1] >= 10 Then
    _WinAPI_ShowWindow($hWndWindow, 5)
    EndIf
    _WinAPI_MoveWindow($hWndWindow, $Rect[0], $Rect[1], $Rect[2] - $Rect[0], $Rect[3] - $Rect[1], True)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListView_CreateRating($hWndListView, $Index, $SubItemIndex, $pImgFull, $pImgHalf, $Rating)
    Local $CurrentStep, $Half
    $Window = _ListView_InsertWindow($hWndListView, $Index, $SubItemIndex)
    GUISetBkColor(0xFFFFFF, $Window)
    $WindowSize = WinGetClientSize($Window)

    [/autoit] [autoit][/autoit] [autoit]

    $Step = Round($WindowSize[0] / Ceiling($Rating))
    $CurrentStep = 0
    $Half = Mod($Rating, Int($Rating))

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To Int($Rating)
    GUICtrlCreatePic($pImgFull, $CurrentStep, 3, $Step, $WindowSize[1]-6)
    $CurrentStep += $Step
    Next

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If $Half <> 0 Or $Half <> '' Then
    GUICtrlCreatePic($pImgHalf, $CurrentStep, 3, $Step, $WindowSize[1]-6)
    EndIf
    EndFunc

    [/autoit]

    Die funktion "_ListView_CreateRating" soll euch zeigen was man damit alles anstellen kann.
    mit dieser funktion lassen sich so ziemlich alles in einer listview erstellen...

    würde mich über feedback freuen und verbesserung vorschläge ;)

  • Super, kann man bestimmt mal brauchen! :thumbup:

    Aber _ListView_CreateRating passt noch nicht so ganz. Wenn man jetzt unterschiedliche Ratings hat, dann werden die Sterne unterschiedlich auseinandergezogen, anstelle noch graue Sterne hinzuzufügen. Du bräuchtest als noch 2 Parameter, einen für das 3. Bild und einen für die maximale Anzahl der Sterne.

  • Hallo dpjeezy89,

    Wenn du dein Beispiel so abänderst:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Constants.au3>
    #include <GuiListView.au3>
    #include <WinAPI.au3>
    #include <Listview Window.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Form1", 600, 350)
    GUIRegisterMsg($WM_NOTIFY, "_ListView_Notify")
    GUIRegisterMsg($WM_SIZE, "_ListView_Notify")

    [/autoit] [autoit][/autoit] [autoit]

    $ListView = GUICtrlCreateListView("Text|Rating", 0, 0, 600, 350 )
    $hWndListview = GUICtrlGetHandle($ListView)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To 40
    GUICtrlCreateListViewItem('Text', $ListView)
    $rate = random(1,10,1)/2
    ConsoleWrite($rate & @crlf)
    _ListView_CreateRating($hWndListview, $i, 1, @ScriptDir & "\Star_Full.gif", @ScriptDir & "\Star_Half.gif", $rate)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Do
    $msg = GUIGetMsg()
    Until $msg = -3

    [/autoit]

    erkennst du den Effekt, den funkey bereits beschrieben hat. Sieht wirklich nicht schön aus. Wenn man die Sterne nicht auf die Spaltenbreite anpasst wird es etwas besser:

    [autoit]

    Func _ListView_CreateRating($hWndListView, $Index, $SubItemIndex, $pImgFull, $pImgHalf, $Rating)
    Local $CurrentStep, $Half
    $Window = _ListView_InsertWindow($hWndListView, $Index, $SubItemIndex)
    GUISetBkColor(0xFFFFFF, $Window)
    $WindowSize = WinGetClientSize($Window)

    [/autoit][autoit][/autoit][autoit]

    $Step = Round($WindowSize[0] / Ceiling($Rating))
    $CurrentStep = 0
    $Half = Mod($Rating, Int($Rating))

    [/autoit][autoit][/autoit][autoit]

    For $i = 1 To Int($Rating)
    GUICtrlCreatePic($pImgFull, $CurrentStep, 3, 11, 10)
    $CurrentStep += $Step
    Next

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    If $Half <> 0 Or $Half <> '' Then
    GUICtrlCreatePic($pImgHalf, $CurrentStep, 3, 11, 10)
    EndIf
    EndFunc

    [/autoit]

    Sie müssten jetzt nur noch eine fixe Position (left) haben, dann wäre es optimal,

    mfg (Auto)Bert

  • Hi
    erstmal danke für die antworten^^

    ja denn blöden fehler hab ich total vergessen ...

    Hier die neuer version

    Beispiel:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Constants.au3>
    #include <GuiListView.au3>
    #include <WinAPI.au3>
    #include <Listview Window.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Form1", 600, 350)

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "_ListView_Notify")
    GUIRegisterMsg($WM_SIZE, "_ListView_Notify")

    [/autoit] [autoit][/autoit] [autoit]

    $ListView = GUICtrlCreateListView("Text|Rating", 0, 0, 600, 350 )
    $hWndListview = GUICtrlGetHandle($ListView)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To 40
    GUICtrlCreateListViewItem('Text', $ListView)
    _ListView_CreateRating($hWndListview, $i, 1, @ScriptDir & "\Star_Full.gif", @ScriptDir & "\Star_Half.gif", @ScriptDir & "\Star_Clear.gif", 2.5, 5)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Do
    $msg = GUIGetMsg()
    Until $msg = -3

    [/autoit]

    Funktionen:

    Spoiler anzeigen
    [autoit]

    Global $Listview_Window[1][6] = [['Hwnd', 'hwndFrom', 'Index', 'SubIndex', 'Widht', 'Height']]

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListView_Notify($hWnd, $Msg, $wParam, $lParam)
    If $Msg = $WM_SIZE Then
    _WinAPI_InvalidateRect($hWnd)
    Return $GUI_RUNDEFMSG
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Local $tNMHEADER, $hWndFrom, $iCode, $i

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
    $hWndFrom = DllStructGetData($tNMHEADER, "hwndFrom")
    $iCode = DllStructGetData($tNMHEADER, "Code")

    [/autoit] [autoit][/autoit] [autoit]

    Switch $iCode
    Case $HDN_ITEMCHANGED, $HDN_ITEMCHANGEDW, $LVN_ENDSCROLL
    If $iCode <> $LVN_ENDSCROLL Then $hWndFrom = _WinAPI_GetParent($hWndFrom)
    For $i = 1 To UBound($Listview_Window) -1
    If $Listview_Window[$i][1] = $hWndFrom Then
    _ListView_MoveWindow($hWndFrom, $Listview_Window[$i][0], $Listview_Window[$i][2], $Listview_Window[$i][3])
    EndIf
    Next
    _WinAPI_InvalidateRect($hWndFrom)
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListView_InsertWindow($hWnd, $Index, $SubItemIndex = 0)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    Local $Rect, $gWidth, $gHeight, $gLeft, $gTop

    [/autoit] [autoit][/autoit] [autoit]

    If BitAND($Style, $WS_CLIPCHILDREN) <> $WS_CLIPCHILDREN Then
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($Style, $WS_CLIPCHILDREN))
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $SubItemIndex = 0 Then
    $Rect = _GUICtrlListView_GetItemRect($hWnd, $Index, 2)
    Else
    $Rect = _GUICtrlListView_GetSubItemRect($hWnd, $Index, $SubItemIndex)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ReDim $Listview_Window[UBound($Listview_Window) +1][UBound($Listview_Window, 2)]

    [/autoit] [autoit][/autoit] [autoit]

    $Listview_Window[UBound($Listview_Window) -1][0] = GUICreate('', $Rect[2] - $Rect[0], $Rect[3] - $Rect[1], $Rect[0], $Rect[1], $WS_CHILD, -1, $Hwnd)
    $Listview_Window[UBound($Listview_Window) -1][1] = $hWnd
    $Listview_Window[UBound($Listview_Window) -1][2] = $Index
    $Listview_Window[UBound($Listview_Window) -1][3] = $SubItemIndex
    $Listview_Window[UBound($Listview_Window) -1][4] = $Rect[2] - $Rect[0]
    $Listview_Window[UBound($Listview_Window) -1][5] = $Rect[3] - $Rect[1]
    GUISetState(@SW_SHOW, $Listview_Window[UBound($Listview_Window) -1][0])
    Return $Listview_Window[UBound($Listview_Window) -1][0]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListView_MoveWindow($hWndListView, $hWndWindow, $Index, $SubItemIndex)
    Local $Rect, $Details

    [/autoit] [autoit][/autoit] [autoit]

    If $SubItemIndex = 0 Then
    $Rect = _GUICtrlListView_GetItemRect($hWndListView, $Index, 2)
    Else
    $Rect = _GUICtrlListView_GetSubItemRect($hWndListView, $Index, $SubItemIndex)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $Rect[1] < 10 Then
    _WinAPI_ShowWindow($hWndWindow, 0)
    ElseIf $Rect[1] >= 10 Then
    _WinAPI_ShowWindow($hWndWindow, 5)
    EndIf
    $Details = _ArrayGethWndFromDetails($hWndWindow)

    [/autoit] [autoit][/autoit] [autoit]

    If Not @error Then
    _WinAPI_MoveWindow($hWndWindow, $Rect[0], $Rect[1], $Details[0][4], $Details[0][5], True)
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ListView_CreateRating($hWndListView, $Index, $SubItemIndex, $pImgFull, $pImgHalf, $pImgClear, $Rating, $MaxRating)
    Local $CurrentStep
    $wColumn = _GUICtrlListView_GetColumnWidth($hWndListView, $SubItemIndex)
    If $wColumn < 10 * $MaxRating Then _GUICtrlListView_SetColumnWidth($hWndListView, $SubItemIndex, 10 * $MaxRating)

    [/autoit] [autoit][/autoit] [autoit]

    $Window = _ListView_InsertWindow($hWndListView, $Index, $SubItemIndex)
    GUISetBkColor(0xFFFFFF, $Window)

    [/autoit] [autoit][/autoit] [autoit]

    _RatingAddStar($CurrentStep, $pImgFull, Int($Rating))
    _RatingAddStar($CurrentStep, $pImgHalf, Ceiling(Mod($Rating, Int($Rating))))
    _RatingAddStar($CurrentStep, $pImgClear, Int($MaxRating) - Ceiling($Rating))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _RatingAddStar(ByRef $CurrentStep, $Img, $Stars = 1, $Widh = 10, $Heigh = 10, $Top = 2)
    If $Stars <= 0 Then Return SetError(1, @extended, -1)
    Local $fCurrentStep = $CurrentStep
    For $i = 1 To $Stars
    $Pic = GUICtrlCreatePic($Img, $fCurrentStep, $Top, $Widh, $Heigh)
    $fCurrentStep += $Widh
    Next
    $CurrentStep = $fCurrentStep
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ArrayGethWndFromDetails($hWndFrom)
    Local $ret[1][6]

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To UBound($Listview_Window) -1
    If $Listview_Window[$i][0] = $hWndFrom Then
    If UBound($ret, 2) < UBound($Listview_Window, 2) Then ReDim $ret[UBound($ret)][UBound($Listview_Window, 2)]
    For $a = 0 To UBound($Listview_Window, 2) -1
    $ret[0][$a] = $Listview_Window[$i][$a]
    Next
    Return $ret
    EndIf
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Return SetError(1, @extended, -1)
    EndFunc

    [/autoit]

    "_ListView_CreateRating" hab ich überarbeitet
    neue sternchen hinzugefügt
    sternchen werden nicht mehr breiter wenn man am column zieht

    ein neues problemm ist leider dazu gekommen wenn man denn column kleiner macht
    bleibt die bewertung so wie ist...
    wird aber schon ich setze mich heute mittag nochmal hin

    wenn jmd ideen hat oder bugs findet einfach melden