找回密码
 加入
搜索
查看: 10059|回复: 18

[GUI管理] 【已解决】如何在Listview的SubItem中多行显示文本?

 火.. [复制链接]
发表于 2013-11-26 08:50:47 | 显示全部楼层 |阅读模式
本帖最后由 xms77 于 2013-11-28 14:44 编辑

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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2013-11-26 09:49:33 | 显示全部楼层
多行一般在 _GUICtrlListView_SetView($hListView, 4) 情况下使用.
 楼主| 发表于 2013-11-26 10:32:01 | 显示全部楼层
回复 2# afan
A大,貌似不行啊!
发表于 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

评分

参与人数 1金钱 +30 收起 理由
xms77 + 30 感谢A大

查看全部评分

 楼主| 发表于 2013-11-27 12:33:25 | 显示全部楼层
A大,我这里实测还是没有换行显示,只是行距变大了。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2013-11-27 12:49:28 | 显示全部楼层
回复 5# xms77


    那就不清楚了,我的是XP

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2013-11-27 12:50:59 | 显示全部楼层
回复 5# xms77

用X86版本运行
发表于 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中测试效果如下,不知在其他系统中如何。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 2金钱 +40 收起 理由
chenronting + 10 P版一出手,就知有没有啊
xms77 + 30 感谢P大帮忙~

查看全部评分

发表于 2013-11-27 18:22:01 | 显示全部楼层
在x86 XP中测试效果如下

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2013-11-27 20:59:12 | 显示全部楼层
哈哈!!
发表于 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[5];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 [esp+14], 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
发表于 2013-11-28 09:20:59 | 显示全部楼层
回复 11# pusofalse
没有:#include "Thread.au3"文件
发表于 2013-11-28 09:35:00 | 显示全部楼层
回复 11# pusofalse

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 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 完成:[CODE]:1
难道是要XP 吗,为什么你WIN7可以, 我这里是WIN8.1 ,AU3是3.3.9.4
发表于 2013-11-29 21:57:59 | 显示全部楼层
If DllStructGetData($tMeasureItem, "CtlType") == $ODT_LISTVIEW Then
                DllStructSetData($tMeasureItem, "itemHeight", 40)
                Return 1
        EndIf
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-26 11:52 , Processed in 0.304505 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表