找回密码
 加入
搜索
查看: 5990|回复: 14

[GUI管理] [已解决]如何显示多行可变宽度的文本

  [复制链接]
发表于 2010-8-19 00:00:08 | 显示全部楼层 |阅读模式
本帖最后由 xyold1 于 2010-8-22 16:43 编辑

我用对话框的形式想显示一段文本,行数可变,宽度可变

用消息框出提示音

用Form+标签控件,SplashText,都不太理想

有什么别的控件,或方法可以解决这个问题么?

Traytip不算

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-8-19 08:24:47 | 显示全部楼层
ToolTip 这个呢
发表于 2010-8-19 09:21:52 | 显示全部楼层
个人认为应该参看此贴:http://www.autoitx.com/thread-17587-1-1.html
 楼主| 发表于 2010-8-19 18:48:49 | 显示全部楼层
回复 3# 3mile


    谢谢提示,正在研究,代码太长了
 楼主| 发表于 2010-8-19 18:51:46 | 显示全部楼层
回复 2# 水木子


    想要一个窗体类的对话框
发表于 2010-8-19 20:56:31 | 显示全部楼层
msgbox() 不行吗?自动换行的
 楼主| 发表于 2010-8-19 23:34:41 | 显示全部楼层
本帖最后由 xyold1 于 2010-8-19 23:41 编辑

回复 6# afan


    我要连续显示可变长度,可变行数的文本

msgbox  不合适
我看了这个贴子  http://www.autoitx.com/thread-17587-1-1.html
发现那个GUI很不错,只不过是动画输出,不能移动窗体

修改了半天也不成功  
注释了DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 1000, "long", $aToast_Data[2])还是动画显示

A版也修改过那个代码,可不可以将那个窗体改成静止显示,可移动的呢

不用屏蔽标题栏

谢谢A版
发表于 2010-8-19 23:39:32 | 显示全部楼层
回复 7# xyold1


    那个代码也不是滚动显示文本吧,它只是界面在滚动
 楼主| 发表于 2010-8-19 23:44:20 | 显示全部楼层
回复 8# afan


    说错了,不是滚动是连续不断
就一块可变大小的黑板,显示了一条信息后再显示另一条

深夜了,A版还没休息哦
发表于 2010-8-20 10:34:10 | 显示全部楼层
$ES_MULTILINE即可解决
发表于 2010-8-20 10:34:24 | 显示全部楼层
$ES_MULTILINE即可解决
 楼主| 发表于 2010-8-20 13:22:03 | 显示全部楼层
回复 11# 23070205


    谢谢提醒,研究一下
 楼主| 发表于 2010-8-22 16:42:02 | 显示全部楼层
用下面的函数获取文本的大小,再用winmove改变窗口大小
Func _StringSize($sText, $iSize = Default, $iWeight = Default, $iAttrib = Default, $sName = Default, $iWidth = 0, $Lang = 1)
        Local $avSize_Info[4], $aRet, $iLine_Width = 0, $iLast_Word, $iWrap_Count
        Local $hLabel_Handle, $hFont, $hDC, $oFont, $tSize = DllStructCreate("int X;int Y")
        If Not IsString($sText) Then Return SetError(1, 1, 0)
        If Not IsNumber($iSize) And $iSize <> Default Then Return SetError(1, 2, 0)
        If Not IsInt($iWeight) And $iWeight <> Default Then Return SetError(1, 3, 0)
        If Not IsInt($iAttrib) And $iAttrib <> Default Then Return SetError(1, 4, 0)
        If Not IsString($sName) And $sName <> Default Then Return SetError(1, 5, 0)
        If Not IsNumber($iWidth) Then Return SetError(1, 6, 0)
        Local $hGUI = GUICreate("", 1200, 500, 10, 10)
        If $hGUI = 0 Then Return SetError(2, 0, 0)
        GUISetFont($iSize, $iWeight, $iAttrib, $sName)
        $avSize_Info[0] = $sText
        If StringInStr($sText, @CRLF) = 0 Then StringRegExpReplace($sText, "[\x0a|\x0d]", @CRLF)
        Local $asLines = StringSplit($sText, @CRLF, 1)
        Local $hText_Label = GUICtrlCreateLabel($sText, 10, 10)
        Local $aiPos = ControlGetPos($hGUI, "", $hText_Label)
;~        GUISetState();@SW_HIDE
        GUICtrlDelete($hText_Label)
        $avSize_Info[1] = (($aiPos[3]) / $asLines[0])
        If Not $Lang Then $avSize_Info[1] = ($aiPos[3] - 8) / $asLines[0]
        $avSize_Info[2] = $aiPos[2]
        $avSize_Info[3] = $aiPos[3] - 2
        If $aiPos[2] > $iWidth And $iWidth > 0 Then
                $avSize_Info[0] = ""
                $avSize_Info[2] = $iWidth
                Local $iLine_Count = $asLines[0]
                If Not $Lang Then $iLine_Count = 0
                For $j = 1 To $asLines[0]
                        $hText_Label = GUICtrlCreateLabel($asLines[$j], 10, 10)
                        $aiPos = ControlGetPos($hGUI, "", $hText_Label)
                        GUICtrlDelete($hText_Label)
                        If $aiPos[2] < $iWidth Then
                                If Not $Lang Then $iLine_Count += 1
                                $avSize_Info[0] &= $asLines[$j] & @CRLF
                        Else
                                $hText_Label = GUICtrlCreateLabel("", 0, 0)
                                $hLabel_Handle = ControlGetHandle($hGUI, "", $hText_Label)
                                $aRet = DllCall("User32.dll", "hwnd", "GetDC", "hwnd", $hLabel_Handle)
                                If @error Then _StringSize_Error(3, 1, $hLabel_Handle, 0, $hGUI)
                                $hDC = $aRet[0]
                                $aRet = DllCall("user32.dll", "lparam", "SendMessage", "hwnd", $hLabel_Handle, "int", 0x0031, "wparam", 0, "lparam", 0)
                                If @error Then _StringSize_Error(3, 2, $hLabel_Handle, $hDC, $hGUI)
                                $hFont = $aRet[0]
                                $aRet = DllCall("GDI32.dll", "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hFont)
                                If @error Then _StringSize_Error(3, 3, $hLabel_Handle, $hDC, $hGUI)
                                $oFont = $aRet[0]
                                If $oFont = 0 Then _StringSize_Error(3, 4, $hLabel_Handle, $hDC, $hGUI)
                                $iWrap_Count = 0
                                While 1
                                        $iLine_Width = 0
                                        $iLast_Word = 0
                                        For $i = 1 To StringLen($asLines[$j])
                                                If StringMid($asLines[$j], $i, 1) = " " Then $iLast_Word = $i - 1
                                                Local $sTest_Line = StringMid($asLines[$j], 1, $i)
                                                GUICtrlSetData($hText_Label, $sTest_Line)
                                                $iSize = StringLen($sTest_Line)
                                                DllCall("GDI32.dll", "int", "GetTextExtentPoint32", "hwnd", $hDC, "str", $sTest_Line, "int", $iSize, "ptr", DllStructGetPtr($tSize))
                                                If @error Then _StringSize_Error(3, 5, $hLabel_Handle, $hDC, $hGUI)
                                                $iLine_Width = DllStructGetData($tSize, "X")
                                                If Not IsDeclared('w_tmp') Then Local $w_tmp = $iLine_Width
                                                $hzsl = StringRegExp($sTest_Line, '[^\x00-\xff]', 3)
                                                If Not @error Then
                                                        If $w_tmp < 12 Then $iLine_Width += ($w_tmp - 3) * UBound($hzsl)
                                                        If $w_tmp >= 12 Then $iLine_Width += $w_tmp * UBound($hzsl)
                                                EndIf
                                                If $Lang And ($iLine_Width + $w_tmp + 4 >= $iWidth) Then ExitLoop
                                                If Not $Lang And ($iLine_Width >= $iWidth - Int($iSize / 2)) Then ExitLoop
                                        Next
                                        If $i > StringLen($asLines[$j]) Then
                                                If Not $Lang Then $iWrap_Count += 1
                                                $avSize_Info[0] &= $sTest_Line & @CRLF
                                                ExitLoop
                                        Else
                                                $iWrap_Count += 1
                                                If Not $Lang Then
                                                        If $iLast_Word = 0 Then
                                                                _StringSize_Error(4, 0, $hLabel_Handle, $hDC, $hGUI)
                                                        EndIf
                                                        $avSize_Info[0] &= StringLeft($sTest_Line, $iLast_Word) & @CRLF
                                                        $asLines[$j] = StringTrimLeft($asLines[$j], $iLast_Word)
                                                        $asLines[$j] = StringStripWS($asLines[$j], 1)
                                                Else
                                                        $avSize_Info[0] &= StringLeft($sTest_Line, $i) & @CRLF
                                                        $asLines[$j] = StringTrimLeft($asLines[$j], $i)
                                                EndIf
                                        EndIf
                                WEnd
                                $iLine_Count += $iWrap_Count
                                DllCall("User32.dll", "int", "ReleaseDC", "hwnd", $hLabel_Handle, "hwnd", $hDC)
                                If @error Then _StringSize_Error(3, 6, $hLabel_Handle, $hDC, $hGUI)
                                GUICtrlDelete($hText_Label)
                        EndIf
                Next
                $avSize_Info[3] = ($iLine_Count * $avSize_Info[1]) + 4
        EndIf
        GUIDelete($hGUI)
        Return $avSize_Info
EndFunc   ;==>_StringSize

Func _StringSize_Error($iError, $iExtended, $hLabel_Handle, $hDC, $hGUI)
        DllCall("User32.dll", "int", "ReleaseDC", "hwnd", $hLabel_Handle, "hwnd", $hDC)
        GUIDelete($hGUI)
        Return SetError($iError, $iExtended, 0)
EndFunc   ;==>_StringSize_Error
发表于 2010-9-9 09:56:07 | 显示全部楼层
初学AU3。学习一下这个问题
发表于 2011-3-14 18:59:33 | 显示全部楼层
lable可以多行显示吗?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-12 19:07 , Processed in 0.091020 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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