xms77 发表于 2013-11-26 08:50:47

【已解决】如何在Listview的SubItem中多行显示文本?

本帖最后由 xms77 于 2013-11-28 14:44 编辑

RT,使用_GUICtrlListView_AddSubItem($hListView,0,"123" & @CRLF & "456",1),没有成功,显示文本还是连续的。

afan 发表于 2013-11-26 09:49:33

多行一般在 _GUICtrlListView_SetView($hListView, 4) 情况下使用.

xms77 发表于 2013-11-26 10:32:01

回复 2# afan
A大,貌似不行啊!

afan 发表于 2013-11-26 11:32:08

回复 3# xms77


    帮助的例子加个换行符就可以看出区别了#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
        Local $hListView
       
        GUICreate("ListView Set View", 400, 300)
        $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
        GUISetState()

        ; Add columns
        _GUICtrlListView_AddColumn($hListView, "Items", 100)

        ; Add items
        _GUICtrlListView_BeginUpdate($hListView)
        For $iI = 1 To 10
                _GUICtrlListView_AddItem($hListView, "Item " & $iI & @LF & '换行')
        Next
        _GUICtrlListView_EndUpdate($hListView)

        ; Set view
        MsgBox(4160, "Information", "View: " & _GUICtrlListView_GetView($hListView))
        _GUICtrlListView_SetView($hListView, 4)
        MsgBox(4160, "Information", "View: " & _GUICtrlListView_GetView($hListView))

        ; Loop until user exits
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
EndFunc   ;==>_Main

xms77 发表于 2013-11-27 12:33:25

A大,我这里实测还是没有换行显示,只是行距变大了。

afan 发表于 2013-11-27 12:49:28

回复 5# xms77


    那就不清楚了,我的是XP

tubaba 发表于 2013-11-27 12:50:59

回复 5# xms77

用X86版本运行

pusofalse 发表于 2013-11-27 15:08:38

#include <GUIListView.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

_Main()

Func _Main()
        Local $hGUI = GUICreate("test", 400, 300)

        GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM")
        GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")

        GUICtrlCreateListView("", 5, 5, 390, 290, $LVS_REPORT + $LVS_OWNERDRAWFIXED)
        Local $hListView = GUICtrlGetHandle(-1)

        _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES + $LVS_EX_DOUBLEBUFFER + $LVS_EX_FULLROWSELECT)
        _GUICtrlListView_SetBkColor($hListView, 0xC0DBC1)
        _GUICtrlListView_SetTextBkColor($hListView, 0xC0DBC1)
               
        _GUICtrlListView_AddColumn($hListView, "Col 1", 100, 2)
        _GUICtrlListView_AddColumn($hListView, "Col 2", 100, 2)
        _GUICtrlListView_AddColumn($hListView, "Col 3", 100, 2)
       
        _GUICtrlListView_AddItem($hListView, "AnvilHole123")
        _GUICtrlListView_AddItem($hListView, "Hello world")
        _GUICtrlListView_AddItem($hListView, "Hello" & @CRLF & "world")

        _GUICtrlListView_AddSubItem($hListView, 0, "123" & @CRLF & "456", 1)
        _GUICtrlListView_AddSubItem($hListView, 1, "123456", 1)
        _GUICtrlListView_AddSubItem($hListView, 2, "123" & @CRLF & "456", 2)

        GUISetState(@SW_SHOW, $hGUI)

        While GUIGetMsg() <> -3
        WEnd
        GUIDelete($hGUI)
EndFunc        ;==>_Main

Func WM_MEASUREITEM($hWnd, $iMsg, $wParam, $lParam)
        Local Const $ODT_LISTVIEW = 102
        Local Const $tagMEASUREITEMSTRUCT = "UINT CtlType;UINT CtlID;UINT itemID;UINT itemWidth;UINT itemHeight;ULONG_PTR itemData"

        Local $tMeasureItem = DllStructCreate($tagMEASUREITEMSTRUCT, $lParam)

        If DllStructGetData($tMeasureItem, "CtlType") == $ODT_LISTVIEW Then
                DllStructSetData($tMeasureItem, "itemHeight", 40)
                Return 1
        EndIf
EndFunc        ;==>WM_MEASUREITEM

Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam)
        Local Const $ODT_LISTVIEW = 102

        Local $tDrawItem = DllStructCreate("UINT CtlType;UINT CtlID", $lParam)

        If DllStructGetData($tDrawItem , "CtlType") == $ODT_LISTVIEW Then
                Local $hListView = _WinAPI_GetDlgItem($hWnd, DllStructGetData($tDrawItem, "CtlID"))

                Local $iStyle = _WinAPI_GetWindowLong($hListView, $GWL_STYLE)
                $iStyle = BitAND($iStyle, BitNOT($LVS_OWNERDRAWFIXED))

                _WinAPI_SetWindowLong($hListView, $GWL_STYLE, $iStyle)
                _WinAPI_InvalidateRect($hListView)
        EndIf

        Return 1
EndFunc        ;==>WM_DRAWITEM在x64 Windows 7中测试效果如下,不知在其他系统中如何。

chzj589 发表于 2013-11-27 18:22:01

在x86 XP中测试效果如下

joyran 发表于 2013-11-27 20:59:12

哈哈!!{:face (396):}

pusofalse 发表于 2013-11-27 22:39:22

回复 9# chzj589


    这样呢?#AutoIt3Wrapper_UseX64=n

#include <GUIListView.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

#include "Thread.au3"

_Main()

Func _Main()
      Local $hGUI = GUICreate("test", 400, 300)

      GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM")
      GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")

      GUICtrlCreateListView("", 5, 5, 390, 290, $LVS_REPORT + $LVS_OWNERDRAWFIXED)
      Local $hListView = GUICtrlGetHandle(-1)

      _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES + $LVS_EX_DOUBLEBUFFER + $LVS_EX_FULLROWSELECT)
      _GUICtrlListView_SetBkColor($hListView, 0xC0DBC1)
      _GUICtrlListView_SetTextBkColor($hListView, 0xC0DBC1)

      _GUICtrlListView_AddColumn($hListView, "Col 1", 100, 2)
      _GUICtrlListView_AddColumn($hListView, "Col 2", 100, 2)
      _GUICtrlListView_AddColumn($hListView, "Col 3", 100, 2)

      _GUICtrlListView_AddItem($hListView, "AnvilHole123")
      _GUICtrlListView_AddItem($hListView, "Hello world")
      _GUICtrlListView_AddItem($hListView, "Hello" & @CRLF & "world")

      _GUICtrlListView_AddSubItem($hListView, 0, "123" & @CRLF & "456", 1)
      _GUICtrlListView_AddSubItem($hListView, 1, "123456", 1)
      _GUICtrlListView_AddSubItem($hListView, 2, "123" & @CRLF & "456", 2)

      SetHook()
      GUISetState(@SW_SHOW, $hGUI)

      While GUIGetMsg() <> -3
      WEnd
      GUIDelete($hGUI)
EndFunc      ;==>_Main

Func SetHook()
        Local $pProcedure = _RTGetProcAddress("User32.dll", "DrawTextExW")
        Local $pRedirect= _RTVirtualAlloc(4096)

        _RTVirtualProtect($pProcedure, 8)

        If @AutoItX64 Then
                ; TODO: set x64 hook...
        Else
                Local $tSetJump= DllStructCreate("align 1;UBYTE jmp_long;DWORD offset;WORD jmp_short", $pProcedure - 5)
                Local $tRedirect = DllStructCreate("align 1;UBYTE code;UBYTE jmp_long;DWORD offset", $pRedirect)

                DllStructSetData($tSetJump, "jmp_long", 0xE9)
                DllStructSetData($tSetJump, "offset", $pRedirect - $pProcedure)
                DllStructSetData($tSetJump, "jmp_short", 0xF9EB)

                DllStructSetData($tRedirect, "code", Binary("0x83642414DF")) ; and dword ptr , not DT_SINGLELINE
                DllStructSetData($tRedirect, "jmp_long", 0xE9)
                DllStructSetData($tRedirect, "offset", $pProcedure + 2 - ($pRedirect + 10))

        EndIf
EndFunc        ;==>SetHook

Func WM_MEASUREITEM($hWnd, $iMsg, $wParam, $lParam)
      Local Const $ODT_LISTVIEW = 102
      Local Const $tagMEASUREITEMSTRUCT = "UINT CtlType;UINT CtlID;UINT itemID;UINT itemWidth;UINT itemHeight;ULONG_PTR itemData"

      Local $tMeasureItem = DllStructCreate($tagMEASUREITEMSTRUCT, $lParam)

      If DllStructGetData($tMeasureItem, "CtlType") == $ODT_LISTVIEW Then
                DllStructSetData($tMeasureItem, "itemHeight", 40)
                Return 1
      EndIf
EndFunc      ;==>WM_MEASUREITEM

Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam)
      Local Const $ODT_LISTVIEW = 102

      Local $tDrawItem = DllStructCreate("UINT CtlType;UINT CtlID", $lParam)

      If DllStructGetData($tDrawItem , "CtlType") == $ODT_LISTVIEW Then
                Local $hListView = _WinAPI_GetDlgItem($hWnd, DllStructGetData($tDrawItem, "CtlID"))

                Local $iStyle = _WinAPI_GetWindowLong($hListView, $GWL_STYLE)
                $iStyle = BitAND($iStyle, BitNOT($LVS_OWNERDRAWFIXED))

                _WinAPI_SetWindowLong($hListView, $GWL_STYLE, $iStyle)
                _WinAPI_InvalidateRect($hListView)

      EndIf

      Return 1
EndFunc      ;==>WM_DRAWITEM

chzj589 发表于 2013-11-28 09:20:59

回复 11# pusofalse
没有:#include "Thread.au3"文件

chzj589 发表于 2013-11-28 09:35:00

回复 11# pusofalse

chenronting 发表于 2013-11-29 21:00:41

回复 8# pusofalse Global Const $tagREBARBANDINFO = "uint cbSize;uint fMask;uint fStyle;dword clrFore;dword clrBack;ptr lpText;uint cch;" & "int iImage;hwnd hwndChild;uint cxMinChild;uint cyMinChild;uint cx;handle hbmBack;uint wID;uint cyChild;uint cyMaxChild;" & "uint cyIntegral;uint cxIdeal;lparam lParam;uint cxHeader" & ((@OSVersion = "WIN_XP") ? "" : ";" & $tagRECT & ";uint uChevronState")
Global Const $tagREBARBANDINFO = "uint cbSize;uint fMask;uint fStyle;dword clrFore;dword clrBack;ptr lpText;uint cch;" & "int iImage;hwnd hwndChild;uint cxMinChild;uint cyMinChild;uint cx;handle hbmBack;uint wID;uint cyChild;uint cyMaxChild;" & "uint cyIntegral;uint cxIdeal;lparam lParam;uint cxHeader" & ((@OSVersion = "WIN_XP") ^ ERROR
->21:01:58 AutoIT3.exe 完成::1难道是要XP 吗,为什么你WIN7可以, 我这里是WIN8.1 ,AU3是3.3.9.4

yanghust 发表于 2013-11-29 21:57:59

If DllStructGetData($tMeasureItem, "CtlType") == $ODT_LISTVIEW Then
                DllStructSetData($tMeasureItem, "itemHeight", 40)
                Return 1
      EndIf
页: [1] 2
查看完整版本: 【已解决】如何在Listview的SubItem中多行显示文本?