<?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>http://forum.script-coding.com/viewtopic.php?id=12333</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=12333&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: ToolTip по наведению на элемент окна».]]></description>
		<lastBuildDate>Fri, 20 Jan 2017 04:54:40 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: ToolTip по наведению на элемент окна]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=111277#p111277</link>
			<description><![CDATA[<p>Вот без хэндлов, используя A_GuiControl, выходит даже проще:<br /></p><div class="codebox"><pre><code>Gui Add, Text, vCtrl1, % &quot; Move the mouse cursor here   &quot;
Gui Add, ComboBox, vCtrl2 wp, Do not move cursor here!||
Gui Show
Hover({controls: {Ctrl1: &quot;You did it!&quot;, Ctrl2: &quot;You don``t have to do that.&quot;}, delay: 500, duration: 2000})
Return

GuiClose:
   ExitApp

Hover(wp, lp = &quot;&quot;, msg = &quot;&quot;)  {
   static WM_MOUSEMOVE := 0x200, SS_NOTIFY := 0x100, MyPID := DllCall(&quot;GetCurrentProcessId&quot;), prev, opt
   
   fn := A_ThisFunc, GuiCtrl := A_GuiControl
   if (!opt &amp;&amp; opt := wp)  {
      OnMessage(WM_MOUSEMOVE, fn)
      for k in opt.controls  {
         GuiControlGet, %k%, hwnd
         WinGetClass, WinClass, % &quot;ahk_id&quot; %k%
         if (WinClass = &quot;Static&quot;)
            WinSet, Style, +%SS_NOTIFY%, % &quot;ahk_id&quot; %k%
      }
   }
   else if msg  {
      for k, v in opt.controls  {
         if (GuiCtrl = k &amp;&amp; (hover := true) &amp;&amp; GuiCtrl != prev &amp;&amp; prev := GuiCtrl)  {
            %fn%(&quot;hide&quot;)
            opt.timers.Push( timer := Func(fn).Bind(&quot;show&quot;, k) )
            SetTimer, % timer, % &quot;-&quot; . opt.delay
         }
      }
      (!hover &amp;&amp; %fn%(&quot;hide&quot;, true))
   }
   else if (wp = &quot;show&quot;)  {
      ToolTip % opt.controls[lp]
      opt.timers.Push( timer := Func(fn).Bind(&quot;TrackOut&quot;) )
      SetTimer, % timer, 100
      opt.timers.Push( timer := Func(fn).Bind(&quot;hide&quot;) )
      SetTimer, % timer, % &quot;-&quot; opt.duration
   }
   else if (wp = &quot;hide&quot;)  {
      ToolTip
      for key, timer in opt.timers
         SetTimer, % timer, Delete
      opt.timers := [], (lp &amp;&amp; prev := &quot;&quot;)
   }
   else if (wp = &quot;TrackOut&quot;)  {
      MouseGetPos,,, hwnd
      WinGet, PID, PID, ahk_id %hwnd%
      (MyPID != PID &amp;&amp; %fn%(&quot;hide&quot;, true))
   }
}</code></pre></div><div class="quotebox"><cite>stealzy пишет:</cite><blockquote><p>Перенос OnMessage внутрь функции мне не нравится, потому что в основном коде может уже быть OnMessage на WM_MOUSEMOVE, тогда придется изменять код библиотечной</p></blockquote></div><p>Нет, OnMessage в этом случае будут добавляться один за другим, последующий не испортит предыдущий.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 20 Jan 2017 04:54:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=111277#p111277</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: ToolTip по наведению на элемент окна]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=111276#p111276</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, добавил проверку родительского контрола, спасибо.<br />Алгоритм показа взят из браузера, действительно, в Windows другой подход - тултип показывается все время нахождения курсора на контроле, но зато есть ограничение продолжительности показа.<br /><strong>serzh82saratov</strong>, спасибо за код, буду разбираться.<br />Перенос OnMessage внутрь функции мне не нравится, потому что в основном коде может уже быть OnMessage на WM_MOUSEMOVE, тогда придется изменять код библиотечной, чтобы можно было вызвать оба обработчика.</p>]]></description>
			<author><![CDATA[null@example.com (stealzy)]]></author>
			<pubDate>Fri, 20 Jan 2017 03:56:02 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=111276#p111276</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: ToolTip по наведению на элемент окна]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=111273#p111273</link>
			<description><![CDATA[<div class="quotebox"><cite>stealzy пишет:</cite><blockquote><p>Если кто подскажет, как сделать код проще и изящнее буду признателен.</p></blockquote></div><p>На счёт изящнее не знаю, но например OnMessage можно перенести в функцию, не вынуждая пользователя прописывать её. В Duration можно указать продолжительность показа, или опустить ключ.<br /></p><div class="codebox"><pre><code>

#Persistent
#SingleInstance, Force
#NoEnv

Gui Add, Text, HwndCntrl1Hwnd, Move the mouse cursor here
Gui Add, ComboBox, HwndCntrl2Hwnd, Do not move cursor here! 
Gui Show
Hower({Cntrl1Hwnd:&quot;You did it!&quot;, Cntrl2Hwnd:&quot;You don``t have to do that.&quot;, &quot;Delay&quot;:500, &quot;Duration&quot;:2000})
Return

GuiClose:
	ExitApp

Hower(wp, lp = &quot;&quot;, msg = &quot;&quot;, hwnd = &quot;&quot;) {
	Static _ := OnMessage(0x200, Func(&quot;Hower&quot;)), Arr := {}, CBs := {}, Prhwnd
	If IsObject(wp)
	{
		for k, v in wp
		{   
			(%k% + 0) &amp;&amp; Arr[%k%] := v
			WinGetClass, CtrlClass, % &quot;ahk_id&quot; %k%
			If CtrlClass = Static
				Control, Style, +0x100, , % &quot;ahk_id&quot; %k%
			Else If CtrlClass = ComboBox 
				SizeOfCBI := 40 + (A_PtrSize * 3)
				, VarSetCapacity(CBI, SizeOfCBI, 0)
				, NumPut(SizeOfCBI, CBI, 0, &quot;UInt&quot;)
				, DllCall(&quot;GetComboBoxInfo&quot;, &quot;Ptr&quot;, %k%, &quot;Ptr&quot;, &amp;CBI, &quot;Int&quot;)
				, h := NumGet(CBI, 40 + A_PtrSize, &quot;UPtr&quot;)
				, Arr[h] := v, CBs[h] := %k%, CBs[%k%] := h
		} 
		Arr.Delay := !wp.Delay ? 0 : wp.Delay
		Arr.Duration := wp.Duration
	}
	Else If (Arr.HasKey(hwnd) &amp;&amp; (!CBs[hwnd] || CBs[hwnd] != Prhwnd) &amp;&amp; hwnd != Prhwnd &amp;&amp; (Prhwnd := hwnd))
	{ 
		Gosub Hower_ToolTipHide
		SetTimer Hower_CheckMouse, -50
		SetTimer Hower_ToolTipShow, % &quot;-&quot; Arr.Delay
	}
	Else If Prhwnd &amp;&amp; !Arr.HasKey(hwnd) &amp;&amp; !(Prhwnd := &quot;&quot;)
		GoTo Hower_ToolTipHide
	Return
		
	Hower_ToolTipShow:  
		WinGetPos, x, y, w, h, ahk_id %Prhwnd%
		S_CoordModeToolTip := A_CoordModeToolTip
		CoordMode, ToolTip, Screen
		ToolTip, % Arr[Prhwnd], x + w + 2, y + h + 2, 20
		CoordMode, ToolTip, %S_CoordModeToolTip% 
		If Arr.Duration
			SetTimer Hower_ToolTipHide, % &quot;-&quot; Arr.Duration
		Return
		
	Hower_ToolTipHide:
		SetTimer Hower_ToolTipHide, Off
		SetTimer Hower_ToolTipShow, Off
		SetTimer Hower_CheckMouse, Off
		ToolTip, , , , 20
		Return

	Hower_CheckMouse:
		MouseGetPos, , , , CntrlHwnd, 2
		If !Arr.HasKey(CntrlHwnd) &amp;&amp; !(Prhwnd := &quot;&quot;)
			GoTo Hower_ToolTipHide
		SetTimer Hower_CheckMouse, -50
		Return 
}
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Thu, 19 Jan 2017 21:58:18 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=111273#p111273</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: ToolTip по наведению на элемент окна]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=111264#p111264</link>
			<description><![CDATA[<p>Для начала, попробуй это не с текстом, а всё-таки с <a href="http://forum.script-coding.com/viewtopic.php?id=12322">ComboBox</a>.<br /></p><div class="quotebox"><cite>stealzy пишет:</cite><blockquote><p>* При движении по контролу тултип скрывается и не показывается снова, пока курсор не покинет контрол.</p></blockquote></div><p>Конечно, дело вкуса, но по-моему, лучше показывать ToolTip всё время, пока курсор над контролом, только без дёрганья, в одном конкретном месте.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Thu, 19 Jan 2017 19:31:49 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=111264#p111264</guid>
		</item>
		<item>
			<title><![CDATA[AHK: ToolTip по наведению на элемент окна]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=111255#p111255</link>
			<description><![CDATA[<p>Библиотека для показа тултипов по наведению курсора на контролы.<br />* Тултипы показываются с задаваемой задержкой.<br />* Для гарантированного скрытия тултипа на все время его показа создается таймер.<br />* При движении по контролу тултип скрывается и не показывается снова, пока курсор не покинет контрол.<br /></p><div class="codebox"><pre><code>Gui Add, text, HwndCntrl1Hwnd, Move the mouse cursor here
Gui Add, ComboBox, HwndCntrl2Hwnd, Do not move cursor here!
Gui Show ; ↓ Magic
CntrlToolTipArr := Object(Cntrl1Hwnd, &quot;You did it!&quot;, Cntrl2Hwnd, &quot;You don``t have to do that.&quot;), showDelay := 700 ;ms
HowerFn := Func(&quot;Hower&quot;).bind(CntrlToolTipArr, showDelay, false, false)
OnMessage(WM_MOUSEMOVE := 0x200, HowerFn)
Return ; ↑ Magic
GuiClose:
ExitApp

Hower(CntrlsHowerArr, showDelay, showTimer, hideTimer) {
	static OldCntrlHwnd, OldHowerFn_ShowTimer, OldHowerFn_HideTimer, xTT, yTT, ToolTipExist, PreventShowToolTipOnSameCntrl, HideTimerPeriod := 200

	MouseGetPos x, y,, CurrentCntrlHwnd, 2
	if !(CurrentCntrlToolTipText := CntrlsHowerArr[CurrentCntrlHwnd]) {
		parentCntrlHwnd := DllCall(&quot;GetParent&quot;, &quot;UInt&quot;, CurrentCntrlHwnd)
		if CurrentCntrlToolTipText := CntrlsHowerArr[parentCntrlHwnd]
				CurrentCntrlHwnd := parentCntrlHwnd
	}
	if (OldCntrlHwnd != CurrentCntrlHwnd)
		PreventShowToolTipOnSameCntrl:=false
	OldCntrlHwnd := CurrentCntrlHwnd

	if (!hideTimer &amp;&amp; !showTimer) { ; WM_MOUSEMOVE
		If OldHowerFn_ShowTimer {
			SetTimer % OldHowerFn_ShowTimer, Delete
			OldHowerFn_ShowTimer := &quot;&quot;
		}
		if (ToolTipExist &amp;&amp; ((x != xTT) || (y != yTT))) {
			ToolTipExist := false
			ToolTip
			PreventShowToolTipOnSameCntrl := true
		} else if CurrentCntrlToolTipText {
			HowerFn_ShowTimer := Func(&quot;Hower&quot;).bind(CntrlsHowerArr, showDelay, true, false)
			SetTimer % HowerFn_ShowTimer, % -showDelay
			OldHowerFn_ShowTimer := HowerFn_ShowTimer
		}
	} else if showTimer {
		if (!PreventShowToolTipOnSameCntrl &amp;&amp; CurrentCntrlToolTipText) {
			ToolTipExist := true
			ToolTip % CurrentCntrlToolTipText
			xTT:=x, yTT:=y
			HowerFn_HideTimer := Func(&quot;Hower&quot;).bind(CntrlsHowerArr, showDelay, false, true)
			SetTimer % HowerFn_HideTimer, % HideTimerPeriod
			OldHowerFn_HideTimer := HowerFn_HideTimer
		}
	} else if hideTimer {
		if (ToolTipExist &amp;&amp; !CurrentCntrlToolTipText) {
			ToolTipExist := false
			ToolTip
			SetTimer % OldHowerFn_HideTimer, Delete
		}
	}
}</code></pre></div><p>Если кто подскажет, как сделать код проще и изящнее буду признателен.</p>]]></description>
			<author><![CDATA[null@example.com (stealzy)]]></author>
			<pubDate>Thu, 19 Jan 2017 17:13:31 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=111255#p111255</guid>
		</item>
	</channel>
</rss>
