Advertisement
AZJIO

_ToolTip

Mar 7th, 2013
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 7.25 KB | None | 0 0
  1. #include <GUIToolTip.au3>
  2. #include <FontConstants.au3>
  3.  
  4. Global $aInfo[6][2] = [[ _
  5.         'Задание', '1'],[ _
  6.         'Номер ошибки', '2'],[ _
  7.         'Время начала', '3'],[ _
  8.         'Время окончания', '4'],[ _
  9.         'Время выполнения', '5'],[ _
  10.         'Описание ошибки', '6']]
  11.  
  12. $sText = ''
  13. For $i = 0 To 5
  14.     _StringFormat($sText, $aInfo[$i][0], $aInfo[$i][1])
  15. Next
  16. $sText = StringTrimRight($sText, 1)
  17.  
  18. Func _StringFormat(ByRef $sText, $sString1, $sString2)
  19.     $sText &= StringFormat("%-18s: %s\n", $sString1, $sString2)
  20. EndFunc   ;==>_StringFormat
  21. ; MsgBox(0, 'Сообщение', $sText)
  22.  
  23. ; Получает дескриптор иконки
  24. $hIcon = _WinAPI_LoadShell32Icon(15)
  25.  
  26. $hTool = _ToolTip($sText, 500, 300, 'Информация', $hIcon, $TTS_NOPREFIX  + $TTS_BALLOON, 16, 'Consolas', 0x1EBFFF, 0x395A00)
  27. $hFont = @extended
  28. ; _ToolTip($sText, 500, 300)
  29. Sleep(1500)
  30.  
  31. For $i = 1 To StringLen($sText) - 1
  32.     _GUIToolTip_UpdateTipText($hTool, 0, 0, StringTrimRight($sText, $i))
  33.     Sleep(10)
  34. Next
  35. Sleep(500)
  36. _GUIToolTip_UpdateTipText($hTool, 0, 0, $sText)
  37. If $hFont Then _WinAPI_DeleteObject($hFont) ; удаление объекта шрифта (обратите внимание, что шрифт не работает после удаления объекта)
  38.  
  39. For $i = 1 To 5
  40.     ; Устанавливает позицию подсказки
  41.     _GUIToolTip_TrackPosition($hTool, Random(0, @DesktopWidth, 1), Random(0, @DesktopHeight, 1))
  42.     Sleep(400)
  43. Next
  44.  
  45. _GUIToolTip_TrackPosition($hTool, 500, 300)
  46. For $i = 1 To 4
  47.     ; Принудительно показывает подсказку
  48.     _GUIToolTip_TrackActivate($hTool, False)
  49.     Sleep(500)
  50.  
  51.     ; Принудительно показывает подсказку
  52.     _GUIToolTip_TrackActivate($hTool)
  53.     Sleep(500)
  54. Next
  55.  
  56. _GUIToolTip_Destroy($hTool) ; Удалить подсказку
  57.  
  58. ; #FUNCTION# ;=================================================================================
  59. ; Function Name ...: _ToolTip
  60. ; Description ........: ToolTip extended
  61. ; Syntax................: _ToolTip ( $sText[, $iX = 0[, $iY = 0[, $iTitle = ''[, $hIcon = 0[, $iStyle = 0[, $iFontSize = 0[, $iFontFamily = 'Arial'[, $iFontColor = 0[, $iBkColor = 0]]]]]]]]] )
  62. ; Parameters:
  63. ;       $sText - The text of the tooltip
  64. ;       $iX - The x position of the tooltip
  65. ;       $iY - The y position of the tooltip
  66. ;       $iTitle - The title for the tooltip
  67. ;       $hIcon - Pre-defined icon to show next to the title: Requires a title.
  68. ;           0 = No icon, 1 = Info icon, 2 = Warning icon, 3 = Error Icon, Handle to the Icon
  69. ;       $iStyle - ToolTip style (_GUIToolTip_Create)
  70. ;       $iFontSize - height of font.
  71. ;       $iFontFamily - typeface name.
  72. ;       $iFontColor - text color.
  73. ;       $iBkColor - background color.
  74. ; Return values ....: Success - The handle to the Tooltip window, @extended = $hFont
  75. ;                   Failure - 0, @error:
  76. ;                   -1 - $hTool = 0, ToolTip will not be displayed
  77. ;                   1 - error of the font
  78. ;                   2 - error of the title
  79. ;                   3 - error 1 and 2 together
  80. ; Author(s) ..........: AZJIO
  81. ; Remarks ..........: When you no longer need the font, call the _WinAPI_DeleteObject function to delete it
  82. ; ============================================================================================
  83. ; Имя функции ...: _ToolTip
  84. ; Описание ........: Всплывающая подсказка с расширенными установками.
  85. ; Синтаксис.......: _ToolTip ( $sText[, $iX = 0[, $iY = 0[, $iTitle = ''[, $hIcon = 0[, $iStyle = 0[, $iFontSize = 0[, $iFontFamily = 'Arial'[, $iFontColor = 0[, $iBkColor = 0]]]]]]]]] )
  86. ; Параметры:
  87. ;       $sText - Текст всплывающей подсказки
  88. ;       $iX - X-координата всплывающей подсказки
  89. ;       $iY - Y-координата всплывающей подсказки
  90. ;       $iTitle - Заголовок всплывающей подсказки
  91. ;       $hIcon - Иконка, отображаемая рядом с заголовком. Требует указания параметра $iTitle.
  92. ;                   | 0 - Без иконки (по умолчанию)
  93. ;                   | 1 - Иконка "Информация"
  94. ;                   | 2 - Иконка "Предупреждение"
  95. ;                   | 3 - Иконка "Ошибка
  96. ;                   | Дескриптор иконки
  97. ;       $iStyle - Стиль. Значения соответствуют параметрам _GUIToolTip_Create.
  98. ;       $iFontSize - Размер шрифта.
  99. ;       $iFontFamily - Имя шрифта.
  100. ;       $iFontColor - Цвет шрифта.
  101. ;       $iBkColor - Фон всплывающей подсказки.
  102. ; Возвращаемое значение: Успешно - Возвращает дескриптор ToolTip, @extended содержит дескриптор шрифта
  103. ;                   Неудачно - Возвращает 0 и устанавливает @error = 1
  104. ;                   -1 - $hTool не создан, подсказка не будет отображаться
  105. ;                   1 - ошибка установки шрифта
  106. ;                   2 - ошибка устновки заголовка
  107. ;                   3 - ошибка 1 и 2 вместе
  108. ; Автор ..........: AZJIO
  109. ; Примечания ..: После завершения использования _ToolTip удалите объект $hFont
  110. ; ============================================================================================
  111. Func _ToolTip($sText, $iX = 0, $iY = 0, $iTitle = '', $hIcon = 0, $iStyle = 0, $iFontSize = 0, $iFontFamily = 'Arial', $iFontColor = 0, $iBkColor = 0)
  112.     ; If BitAND($iStyle, 1) Then $iStyle += $TTS_BALLOON
  113.  
  114.     ; Создаёт ToolTip
  115.     Local $hFont = 0, $iError = 0
  116.     Local $hTool = _GUIToolTip_Create(0, $iStyle)
  117.     If Not $hTool Then Return SetError(-1, 0, 0)
  118.  
  119.     ; Устанавливает ширину ToolTip
  120.     _GUIToolTip_SetMaxTipWidth($hTool, @DesktopWidth)
  121.     ; Кроме того это позволяет отображать текст с переносом строки. Иначе @CRLF не будет иметь эффекта.
  122.  
  123.     ; Устанавливает шрифт для ToolTip
  124.     If $iFontSize Then
  125.         $hFont = _WinAPI_CreateFont($iFontSize, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, $iFontFamily)
  126.         If $hFont Then
  127.             _WinAPI_SetFont($hTool, $hFont)
  128.         Else
  129.             $iError += 1
  130.         EndIf
  131.     EndIf
  132.  
  133.     ; Устанавливает цвет
  134.     If $iFontColor Then _GUIToolTip_SetTipTextColor($hTool, $iFontColor) ; Цвет текста (BGR) всплывающей подсказки
  135.     If $iBkColor Then _GUIToolTip_SetTipBkColor($hTool, $iBkColor) ; Цвет фона (BGR) всплывающей подсказки
  136.  
  137.     ; Назначает подсказку элементу и стиль с координатами
  138.     If Not _GUIToolTip_AddTool($hTool, 0, $sText, 0, 0, 0, 0, 0, 2 + 16) Then Return SetError(1, 0, 0)
  139.  
  140.     ; Устанавливает заголовок подсказки
  141.     If $iTitle And Not _GUIToolTip_SetTitle($hTool, $iTitle, $hIcon) Then $iError += 2
  142.  
  143.     ; Устанавливает позицию подсказки
  144.     _GUIToolTip_TrackPosition($hTool, $iX, $iY)
  145.  
  146.     ; Принудительно показывает подсказку
  147.     _GUIToolTip_TrackActivate($hTool)
  148.     Return SetError($iError, $hFont, $hTool)
  149. EndFunc   ;==>_ToolTip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement