<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Альтернатива стандартному Tooltip]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=18258</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=18258&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Альтернатива стандартному Tooltip».]]></description>
		<lastBuildDate>Sat, 20 Jul 2024 16:55:43 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[AHK: Альтернатива стандартному Tooltip]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=161301#p161301</link>
			<description><![CDATA[<p>Возможности альтернативного Tooltip:<br /></p><ul><li><p>Включение прозрачности, в том числе прозрачность для кликов мышью;</p></li><li><p>Автоматическое пропадание после указанного времени;</p></li><li><p>Пропадание при нажатии;</p></li><li><p>Изменение параметров шрифта;</p></li><li><p>Изменение цвета фона;</p></li><li><p>Уменьшенное мерцание при частом обновлении текста;</p></li><li><p>Работа с несколькими мониторами.</p></li></ul><p><a href="https://forum.script-coding.com/viewtopic.php?id=18259">Тема для обсуждения.</a></p><p>Пример:<br /></p><div class="codebox"><pre><code>SetBatchLines,-1

tooltip1:=new Tool_Tip()
tooltip1.Show(&quot;Это тестовый текст`n`nНажмите F1 чтобы переключить прозрачность&quot;,,,10000)

tooltip2:=new Tool_Tip()
loop
{
  mousegetpos,mX,mY,mW,mC
  text:=&quot;Альтернативный Tooltip`n&quot; a_tickcount &quot;`nmX=&quot; mX &quot;`nmY=&quot; mY &quot;`nmW=&quot; mW &quot;`nmC=&quot; mC
  tooltip2.Show(text,,,,Trans,0x303030,&quot;c00FF00 s12 w600 italic underline&quot;,&quot;Times New Roman&quot;)
;  tooltip2.Show(&quot;Static text`n`n`n`n`nCollision test&quot;,,,2000,Trans)
  sleep,30
}
return

esc::
  exitapp

f1::
  Trans:=!Trans
  mousegetpos,mx,my,mw,mc
  tooltip1.Show(Trans?&quot;Прозрачность включена`nклики проходят насквозь&quot;:&quot;Прозрачность выключена`nнажмите сюда чтобы убрать&quot;,,my-50,10000,Trans)
  return

f2::
  sleep,5000
  return

; Ctrl+Alt+L
^!L::listlines
  return
</code></pre></div><p>Class:<br /></p><div class="codebox"><pre><code>; Метод Show(Text,X,Y,Delay,Transparent,BackColor,Font,FontName)
; Text		- Текст который необходимо отобразить
; X, Y		- Координаты появления относительно экрана
; Delay		- задержка пропадания после вызова в миллисекундах
; Transparent	- Прозрачность в формате AHK Gui (2-255), 0-не прозрачно, 1-прозрачность 180
; BackColor	- Цвет фона
; Font		- Параметры шрифта в формате Gui (цвет, размер, наклон, толщина, подчеркнутый, зачеркнутый)
; FontName	- Название шрифта
;
; Метод Hide() - Скрывает Tooltip
;
class Tool_Tip
{
  static DPICoef:=Tool_Tip.GetDPICoef()
  Pos[]
  {
    get
    {
      wingetpos,X,Y,W,H,% &quot;ahk_id &quot; this.hTool_Tip
      return {&quot;X&quot;:X,&quot;Y&quot;:Y,&quot;W&quot;:W,&quot;H&quot;:H}
    }
    set
    {
      return value
    }
  }
  __Delete()
  {
    obm:=this.obm
    settimer,% obm,Delete
    this.obm:=&quot;&quot;
    if this.hTool_Tip
      Gui,% this.hTool_Tip . &quot;:Destroy&quot;
  }
  __New()
  {
    this.Text:=Text
    this.Font:=&quot;s9&quot;
    this.FontName:=&quot;Arial&quot;
    this.obm:=ObjBindMethod(this,&quot;Hide&quot;)
    SaveDefaultGui:=A_DefaultGui
    Gui,New,+HwndhTool_Tip +ToolWindow -sysmenu -Resize +AlwaysOnTop -Caption +Border +E0x2080000
    Gui,% SaveDefaultGui . &quot;:Default&quot;
    this.hTool_Tip:=hTool_Tip
    Gui,%hTool_Tip%:font,% this.Font,% this.FontName
    Gui,%hTool_Tip%:Color,FFFFFF
    Gui,%hTool_Tip%:Margin,2,2
    Gui,%hTool_Tip%:add,text,+hwndhText
    this.hText:=hText
    obm:=this.obm
    GuiControl,+g,% this.hTool_Tip,% obm
    GuiControl,+g,% this.hText,% obm
  }
  Show(Text=&quot;&quot;,X=&quot;&quot;,Y=&quot;&quot;,Delay=&quot;&quot;,Trans=&quot;&quot;,BackColor=&quot;&quot;,Font=&quot;s9&quot;,FontName=&quot;Arial&quot;)
  {
    SaveCoordMode:=A_CoordModeMouse
    CoordMode,Mouse,Screen
    MouseGetPos,mX,mY,mW,mC,2
    CoordMode,Mouse,% SaveCoordMode
    if (X=&quot;&quot;)
      X:=mX+10
    if (Y=&quot;&quot;)
      Y:=mY+20
    if (Font!=this.Font)
    {
      this.Font:=Font
      hTool_Tip:=this.hTool_Tip
      Gui,%hTool_Tip%:font,% this.Font,% this.FontName
      GuiControl,Font,% this.hText
    }
    if (FontName!=this.FontName)
    {
      this.FontName:=FontName
      hTool_Tip:=this.hTool_Tip
      Gui,%hTool_Tip%:font,,% this.FontName
      GuiControl,Font,% this.hText
    }
    if (Text!=this.Text)
    {
      this.Text:=Text
      Size:=this.Measure(Text)
      GuiControl,move,% this.hText,% &quot;w&quot; Size.W &quot; h&quot; Size.H
      GuiControl,,% this.hText,% Text
      W:=Size.W+8
      H:=Size.H+8
      this.bW:=W
      this.bH:=H
      W/=Tool_Tip.DPICoef
      H/=Tool_Tip.DPICoef
    }
    B:=this.Bound(X,Y,this.bW,this.bH)
    X:=B.X
    Y:=B.Y
    if (X!=this.X or Y!=this.Y or W!=this.W or H!=this.H or BackColor!=this.BackColor or !this.Visible)
    {
      this.X:=X
      this.Y:=Y
      this.W:=W
      this.H:=H
      this.Visible:=true
      hTool_Tip:=this.hTool_Tip
      if (BackColor!=this.BackColor)
      {
        this.BackColor:=BackColor
        Gui,%hTool_Tip%:Color,% BackColor
      }
      o:=(X!=&quot;&quot;?&quot;x&quot; X &quot; &quot;:&quot;&quot;)
       . (Y!=&quot;&quot;?&quot;y&quot; Y &quot; &quot;:&quot;&quot;)
       . (W!=&quot;&quot;?&quot;w&quot; W &quot; &quot;:&quot;&quot;)
       . (H!=&quot;&quot;?&quot;h&quot; H &quot; &quot;:&quot;&quot;)
       . &quot; NoActivate&quot;
      Gui,%hTool_Tip%:show,% o
    }
    if (Trans!=this.OldTrans)
    {
      if Trans
      {
        WinSet,Transparent,% Trans=1?180:Trans,% &quot;ahk_id &quot; this.hTool_Tip
        Winset,ExStyle,+0x20,% &quot;ahk_id &quot; this.hTool_Tip
      }
      else
      {
        WinSet,Transparent,255,% &quot;ahk_id &quot; this.hTool_Tip
        Winset,ExStyle,-0x20,% &quot;ahk_id &quot; this.hTool_Tip
      }
      this.OldTrans:=Trans
    }
    if Delay
    {
      obm:=this.obm
      settimer,% obm,% -abs(Delay)
    }
  }
  Hide()
  {
    if this.hTool_Tip
      Gui,% this.hTool_Tip . &quot;:hide&quot;
    this.Visible:=false
  }
  Measure(Text)
  {
    SaveDefaultGui:=A_DefaultGui
    Gui,New,+HwndhTest_Tip
    Gui,% SaveDefaultGui . &quot;:Default&quot;
    Gui,%hTest_Tip%:font,% this.Font,% this.FontName
    Gui,%hTest_Tip%:add,text,+hwndhTest,% Text
    GuiControlGet,Size,Pos,% hTest
    Gui,%hTest_Tip%:Destroy
    return {&quot;X&quot;:SizeX,&quot;Y&quot;:SizeY,&quot;W&quot;:SizeW*Tool_Tip.DPICoef,&quot;H&quot;:SizeH*Tool_Tip.DPICoef}
  }
  GetDPICoef()
  {
    SaveDefaultGui:=A_DefaultGui
    gui,New:add,text,x0 y0 w1000 h1000 +hwndhTest
    Controlgetpos,Testx,Testy,Testw,Testh,,ahk_id %hTest%
    gui,Destroy
    Gui,% SaveDefaultGui . &quot;:Default&quot;
    return Testw/1000
  }
  Bound(X,Y,W=0,H=0)
  {
    static last:=1
    SysGet,Monitor,MonitorCount
    Loop,% Monitor
    {
      SysGet,B,Monitor,% A_Index
      if (X&gt;=BLeft and X&lt;=BRight and Y&gt;=BTop and Y&lt;=BBottom)
      {
        SysGet,B,MonitorWorkArea,% A_Index
        last:=a_index
        return {&quot;X&quot;:(X+W&gt;BRight?BRight-W:X)
               ,&quot;Y&quot;:(Y+H&gt;BBottom?BBottom-H:Y)
               ,&quot;B&quot;:a_index}
      }
    }
    SysGet,B,MonitorWorkArea,% last
    return {&quot;X&quot;:(X+W&gt;BRight?BRight-W:X&lt;BLeft?BLeft:X)
           ,&quot;Y&quot;:(Y+H&gt;BBottom?BBottom-H:Y&lt;BTop?BTop:Y)
           ,&quot;B&quot;:a_index}
  }
}
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alectric)]]></author>
			<pubDate>Sat, 20 Jul 2024 16:55:43 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=161301#p161301</guid>
		</item>
	</channel>
</rss>
