找回密码
 加入
搜索
查看: 5221|回复: 8

[AU3基础] 【已解决】ToolTip综合问题肯求高手 !

  [复制链接]
发表于 2010-10-13 08:57:11 | 显示全部楼层 |阅读模式
本帖最后由 touch_xu 于 2010-10-13 11:33 编辑

希望能给个例子同时实现下列功能。
我想用ToolTiP 从读取TXT文件读取要显示的内容,但是如果内容太多影响美观请教大家:
1.如何果分行显示,要自动分行
2.能否设置文字颜色,如何设置。
3.如何提示整点显示,不是指定时间,是每个整点都有提示。
4.如何让做ToolTiP提示从桌面右侧进入,再从右侧退出特效,如何制作。

如果仅是ToolTiP不行,GUI也好。
但是小还不会处理GUI的while 事件和要常驻内存的程序的关系求都一并处理,将十分感谢。
While 1
        Set()
        ;主程序
WEnd

;这个函数要整点运行。
Func Notice()
        ToolTip("这儿要读TXT文件",@DesktopWidth-305,@DesktopHeight-125,"重要提示:",2)
        Sleep(60 * 1000)

EndFunc

评分

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

查看全部评分

发表于 2010-10-13 09:04:21 | 显示全部楼层
不大明白你问题的意思,能描述清楚些或上图描述吗?
 楼主| 发表于 2010-10-13 09:14:08 | 显示全部楼层
不大明白你问题的意思,能描述清楚些或上图描述吗?
水木子 发表于 2010-10-13 09:04



    现在已经写清楚了,求教中,谢谢。
发表于 2010-10-13 09:43:19 | 显示全部楼层
_FileReadToArray  ;用这个函数将文本按行读入数组,操作起来就简单方便了。
 楼主| 发表于 2010-10-13 10:15:40 | 显示全部楼层
我还有好几个相关问题请求帮助,版主能否给个示例,谢谢
发表于 2010-10-13 10:18:04 | 显示全部楼层
本帖最后由 liufenglg 于 2010-10-13 10:19 编辑
#include <array.au3>
#include <file.au3>
$a=_FileCountLines('xs.txt')
Local $aArray[$a+1]
_FileReadToArray('xs.txt',$aArray)
For $i=1 To $aArray[0]
        ToolTip($aArray[$i],@DesktopWidth-$i*10,@DesktopHeight/2)
        Sleep(500)
Next        
试下

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-10-13 10:33:47 | 显示全部楼层
试过了
1.回车后内容就不显示了第二行了
2.如何能指定字数,比如15个字一行。
3.请求能不能同时也帮助解决我别的请求。
我感觉写多个帖不是很有必要,但是不写高手们也不愿帮解答,呵呵
发表于 2010-10-13 12:02:01 | 显示全部楼层
回复 7# touch_xu
试下这个,只实现了很简单的功能。
请自行扩展。
#include <array.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=

Local $String='当字号为18时的单行宽度'&@CRLF&'计算当前标签行高度'
$a=_stringSize($String,18,800,6,'宋体');待测试字符串,字体大小,字体重量(400 =缺省值),字体属性,字体名字
$left_top = @DesktopWidth - $a[2];@DesktopWidth - ($a[2]+5)
$height=(@DesktopHeight-$a[3])/2;(@DesktopHeight-10-$a[3])/2

$form1 = GUICreate("form1",  $a[2],$a[3] ,$left_top, $height,BitOR($WS_POPUP, $WS_EX_TOOLWINDOW,$WS_EX_LAYERED));, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
GUICtrlSetBkColor(-1, 0xff00ff)

GUICtrlCreateLabel($String,0,0,$a[2],$a[3])
GUICtrlSetBkColor(-1,0xff00ff)
GUICtrlSetFont(-1,18,800,6,'宋体');这里参数和_stringsize()参数保持一致

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $pos=WinGetPos($form1)
        If $pos[0]<@DesktopWidth Then 
                WinMove("form1","",$pos[0]+10,$pos[1])
                Sleep(500)
        Else
                ExitLoop
        EndIf
WEnd
GUIDelete($form1)
Exit


#include-once
#cs
;以下代码来自官网
#ce

; #INDEX# ============================================================================================================
; Syntax ........: _StringSize($sText[, $iSize[, $iWeight[, $iAttrib[, $sName[, $iWidth]]]]])
; Parameters ....: $sText   - string to display
;                             要显示的字符串 
;                  $iSize   - [optional] Font size in points - default AutoIt GUI default
;                             [选项]:字体大小 - 默认AutoIt的GUI
;                  $iWeight - [optional] Font weight (400 = normal) - default AutoIt GUI default
;                             [选项]字体重量(400 =缺省值) - 默认AutoIt的GUI 
;                  $iAttrib - [optional] Font attribute (0-Normal, 2-Italic, 4-Underline, 8 strike - default AutoIt
;                             [选项]字体属性(0正常,8粗体,2斜体,4下划线 - 默认AutoIt的)
;                  $sName   - [optional] Font name - default AutoIt GUI default
;                             [选项]字体名称 - 默认AutoIt的GUI
;                  $iWidth  - [optional] Width of rectangle - default is unwrapped width of string
;                             [选项]矩形的宽度
;======================================================================================================================
;                            成功 - 返回对应文本的矩形数组:
;                  |$array[0] = string formatted with @CRLF at required wrap points
;                               @ CRLF的格式化字符串必须的包点
;                  |$array[1] = Height of single line in selected font
;                               单行字体的高度 
;                  |$array[2] = Width of rectangle required to hold formatted string
;                               宽度
;                  |$array[3] = Height of rectangle required to hold formatted string
;                               矩形的高度
;                  Failure - Returns 0 and sets @error:
;                  |1 - Incorrect parameter type (@extended = parameter index)
;                  |2 - Failure to create GUI to test label size
;                  |3 - DLL call error - extended set to indicate which
;                  |4 - Font too large for chosen width - longest word will not fit
; Author ........: Melba23
;=====================================================================================================================
Func _StringSize($sText, $iSize = Default, $iWeight = Default, $iAttrib = Default, $sName = Default, $iWidth = 0)

    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 Number($sName) = -1 Then $sName=""
    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] - 8)/ $asLines[0]
    $avSize_Info[2] = $aiPos[2]
    $avSize_Info[3] = $aiPos[3] - 4

    If $aiPos[2] > $iWidth And $iWidth > 0 Then
        $avSize_Info[0] = ""
        $avSize_Info[2] = $iWidth
        Local $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
                $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) ; $WM_GetFont
                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 $iLine_Width >= $iWidth - Int($iSize / 2) Then ExitLoop
                    Next
                    If $i > StringLen($asLines[$j]) Then
                        $iWrap_Count += 1
                        $avSize_Info[0] &= $sTest_Line & @CRLF
                        ExitLoop
                    Else
                        $iWrap_Count += 1
                        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)
                    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

评分

参与人数 1金钱 +30 收起 理由
afan + 30

查看全部评分

 楼主| 发表于 2010-10-18 10:26:27 | 显示全部楼层
高手真是多啊,学习了.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 20:30 , Processed in 0.107858 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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