<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: ToolTip использующий специфичный шрифт]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=6425&amp;type=atom" />
	<updated>2013-04-09T20:58:40Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=6425</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71246#p71246" />
			<content type="html"><![CDATA[<p>Ок. Работает.<br />А в Аэро это совсем невозможно? Или просто того нестоит.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-04-09T20:58:40Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71246#p71246</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71245#p71245" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>#Persistent
hTooltip := TrackToolTip(&quot;Текст&quot;, &quot;&quot;, &quot;&quot;, &quot;Заголовок&quot;, 1, 1, 0x004488, 0xFFFFFF)
return

TrackToolTip( sText
            , x = &quot;&quot;   ; если не указаны, то вблизи курсора
            , y = &quot;&quot;
            , sTitle = &quot;&quot;
            , h_icon = 0   ; h_icon — 0: None, 1:Info, 2: Warning, 3: Error, n &gt; 3: предполагается hIcon
            , CloseButton = 0
            , nColorBack = 0xFFFFE1
            , nColorText = 0
            , BallonTip = 0   ; BalloonTip — это ToolTip с хвостиком
            , w = 400)  ; максимальная ширина
{
   TTS_NOPREFIX := 2, TTS_ALWAYSTIP := 1, TTS_BALLOON := 0x40, TTS_CLOSE := 0x80

   hWnd := DllCall(&quot;CreateWindowEx&quot;, UInt, WS_EX_TOPMOST := 8
                                   , Str, &quot;tooltips_class32&quot;, Str, &quot;&quot;
                                   , UInt, TTS_NOPREFIX|TTS_ALWAYSTIP|(CloseButton ? TTS_CLOSE : 0)|(BallonTip ? TTS_BALLOON : 0)
                                   , Int, 0, Int, 0, Int, 0, Int, 0
                                   , Ptr, 0, Ptr, 0, Ptr, 0, Ptr, 0)

   if (x = &quot;&quot; || y = &quot;&quot;)
   {
      CoordMode, Mouse
      MouseGetPos, xtt, ytt
      xtt := x = &quot;&quot; ? xtt + 10 : x
      ytt := y = &quot;&quot; ? ytt + 10 : y
   }
   Else
      xtt := x, ytt := y

   NumPut(VarSetCapacity(TOOLINFO, A_PtrSize = 4 ? 48 : 72, 0), TOOLINFO, &quot;UInt&quot;)
   NumPut(0x20, TOOLINFO, 4, &quot;UInt&quot;)      ; TTF_TRACK = 0x20
   NumPut(&amp;sText, TOOLINFO, A_PtrSize = 4 ? 36 : 48, &quot;UInt&quot;)

   DHW := A_DetectHiddenWindows
   DetectHiddenWindows, On
   WinWait, ahk_id %hWnd%

   WM_USER := 0x400
   SendMessage, WM_USER + 24,, w         ; TTM_SETMAXTIPWIDTH
   SendMessage, WM_USER + (A_IsUnicode ? 50 : 4),, &amp;TOOLINFO   ; TTM_ADDTOOL
   SendMessage, WM_USER + 19, RGB_to_BGR(nColorBack)   ; TTM_SETTIPBKCOLOR
   SendMessage, WM_USER + 20, RGB_to_BGR(nColorText)   ; TTM_SETTIPTEXTCOLOR
   SendMessage, WM_USER + (A_IsUnicode ? 33 : 32), h_icon, &amp;sTitle      ; TTM_SETTITLEA и TTM_SETTITLEW
   SendMessage, WM_USER + (A_IsUnicode ? 57 : 12),, &amp;TOOLINFO     ; TTM_UPDATETIPTEXTA и TTM_UPDATETIPTEXTW
   SendMessage, WM_USER + 18,, xtt|(ytt&lt;&lt;16)   ; TTM_TRACKPOSITION
   SendMessage, WM_USER + 17, 1, &amp;TOOLINFO ; TTM_TRACKACTIVATE

   if BallonTip
      xMax := A_ScreenWidth, yMax := A_ScreenHeight
   else
   {
      WinGetPos,,, W, H
      xMax := A_ScreenWidth - W - 10
      yMax := A_ScreenHeight - H - 10
   }
   
   if (xtt &gt; xMax || ytt &gt; yMax)
   {
      WinHide
      xtt := xtt &gt; xMax ? xMax : xtt
      ytt := ytt &gt; yMax ? yMax : ytt
      SendMessage, 1042,, xtt|(ytt&lt;&lt;16)   ; TTM_TRACKPOSITION
      WinShow
   }

   DetectHiddenWindows, % DHW
   Return hWnd
}

RGB_to_BGR(RGB)
{
   CurrentFormat := A_FormatInteger
   SetFormat, IntegerFast, H
   C := SubStr(&quot;0x000000&quot;, 1, -(StrLen(RGB+0) - 2)) . SubStr(RGB+0, 3)
   BGR := RegExReplace(C, &quot;0x(..)(..)(..)&quot;, &quot;0x$3$2$1&quot;)
   SetFormat, IntegerFast, %CurrentFormat%
   Return BGR
}</code></pre></div><p>У меня изменение цветов работает только в теме &quot;Классика&quot;.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2013-04-09T20:45:36Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71245#p71245</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71243#p71243" />
			<content type="html"><![CDATA[<p>Ну и замечательно. А как?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-04-09T20:33:31Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71243#p71243</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71242#p71242" />
			<content type="html"><![CDATA[<p>Можно, но не в теме Аэро.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2013-04-09T20:31:31Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71242#p71242</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71239#p71239" />
			<content type="html"><![CDATA[<p>Возможно-ли в ToolTip&quot;е изменить цвет фона и цвет шрифта?<br />Например: синий фон и белый текст.</p><p>Взят за основу 3 пример <strong>kirtech</strong> из 16 поста. </p><div class="codebox"><pre><code>

#SingleInstance force   

Text =
(
Многострочный
        текст

  Hello,World!
    AHK forever!
)

Space::
    Gui, Color, Blue
    Gui, Font, s20 bold italic cWhite, Times New Roman
    DllCall(&quot;DestroyWindow&quot;, &quot;Ptr&quot;, hStatic) 
    Gui, Add,Text, HwndhStatic,% Text
    SendMessage,0x31,,,,ahk_id %hStatic%
    hFont:=ErrorLevel
    ToolTip, % Text
    WinGet,httip,ID,% Text 
    SendMessage,0x30,hFont,1,,ahk_id %httip%
    Return

Esc::
    GuiClose:
    ExitApp

</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-04-09T19:19:55Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71239#p71239</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=53701#p53701" />
			<content type="html"><![CDATA[<p><strong>kirtech</strong>, отличные примеры! Только надо было указать в коде:<br /></p><div class="codebox"><pre><code>WM_GETFONT := 0x31
WM_SETFONT := 0x30</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-11-20T10:01:45Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=53701#p53701</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=53697#p53697" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>creature.ws пишет:</cite><blockquote><p>А возможно ли определить id tooltip&#039;а иным способом?</p></blockquote></div><p>Возможно:<br /></p><div class="codebox"><pre><code>CoordMode, ToolTip, Screen
Gui, Test:New, Hwndhgui
Text:=&quot;1.Окно подсказки не разрушается если вызвать его c новым текстом его ID не изменится.`n   ID   до добавления текста    httip0 = &quot;
ToolTip,% Text,500,600
WinGet,httip0,ID,% Text
Gui, Show, w320 h240
Text .=httip0+0 &quot;`n2.Использовать GetWindow с параметром GW_HWNDFIRST, после вызыова ToolTip&#039;a`n   ID после добавления текста httip1 = &quot;
ToolTip,% Text ,500,600
httip1:=DllCall(&quot;GetWindow&quot;,&quot;uint&quot;,hgui,&quot;uint&quot;,GW_HWNDFIRST:=0)
ToolTip,% Text httip1,500,600
ToolTip, _,500,680,2
httip2:=DllCall(&quot;GetWindow&quot;,&quot;uint&quot;,hgui,&quot;uint&quot;,0)
ToolTip, % &quot;Второй ToolTip и его ID &quot; httip2,500,680,2
MsgBox % &quot;hgui = &quot; hgui+0 &quot;`nhttip1 = &quot; httip1 &quot;`nhttip2 = &quot; httip2</code></pre></div>]]></content>
			<author>
				<name><![CDATA[kirtech]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26525</uri>
			</author>
			<updated>2011-11-19T22:08:09Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=53697#p53697</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=53694#p53694" />
			<content type="html"><![CDATA[<p><em>ToolTip и WM_SETFONT пример 2</em>&nbsp; впечатлил.<br />А возможно ли определить id tooltip&#039;а иным способом? <br />Если в text присутствует &quot;ahk_class&quot;&nbsp; определение id работает не так как задумано.</p>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2011-11-19T20:08:45Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=53694#p53694</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=53689#p53689" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Спасибо! В итоге вот такое получилось:</p></blockquote></div><p>Спасибо аналогично, немного изменений и примеров:</p><p>1. Замена GetTextExtentPoint32 на DrawText<br /></p><div class="codebox"><pre><code>String =
(
Многострочный
текст
 
Hello, World!
AHK forever!
)
 
if pResult := GetTextSize(String, &quot;Arial&quot;, &quot;s24 italic&quot;)
{
   w := NumGet(pResult+8)
   h := NumGet(pResult+12)
   MsgBox, % &quot;Ширина &quot; . w . &quot;`nВысота &quot; . h
}
Return
 
GetTextSize(String, FontName, Options)
{
   static SIZE
   coding := A_IsUnicode ? &quot;W&quot; : &quot;A&quot;
   LOGPIXELSY := 90
   FW_NORMAL := 400, FW_BOLD := 700
   DEFAULT_CHARSET := 1
   DEFAULT_QUALITY := OUT_DEFAULT_PRECIS := CLIP_DEFAULT_PRECIS := 0
 
   if !RegExMatch(Options, &quot;i).*s(\d+).*&quot;, Found)
   {
      MsgBox, Не задан размер шрифта!
      Return
   }
   s := Found1
 
   if !InStr(Options, &quot;bold&quot;)
   {
      if !RegExMatch(Options, &quot;i).*w(\d+).*&quot;, Found)
         w := FW_NORMAL
      Else
         w := Found1
   }
   Else
      w := FW_BOLD
   if w not Between 1 and 1000
   {
      MsgBox, Неверно задан параметр w.`nДолжен быть в пределах от 1 до 1000
      Return
   }
 
   italic    := InStr(Options, &quot;italic&quot;) &gt; 0
   underline := InStr(Options, &quot;underline&quot;) &gt; 0
   strike    := InStr(Options, &quot;strike&quot;) &gt; 0
 
   hDC := DllCall(&quot;GetDC&quot;, UInt, 0)
 
   nHeight := -DllCall(&quot;MulDiv&quot;, Int, s
                  , Int, DllCall(&quot;GetDeviceCaps&quot;, UInt, hDC, Int, LOGPIXELSY), Int, 72)
   hFont := DllCall(&quot;CreateFont&quot; . coding
                                , Int, nHeight, Int, 0
                                , Int, 0, Int, 0, Int, w
                                , UInt, italic, UInt, underline, UInt, strike
                                , UInt, DEFAULT_CHARSET, UInt, OUT_DEFAULT_PRECIS
                                , UInt, CLIP_DEFAULT_PRECIS, UInt, DEFAULT_QUALITY
                                , UInt, 0, Str, FontName)
 
   hPrevObj := DllCall(&quot;SelectObject&quot;, UInt, hDC, UInt, hFont)
 
   VarSetCapacity(Buf, 40)
   DllCall(&quot;GetTextFace&quot; . coding, UInt, hDC, Int, 40, Str, Buf)
   if (Buf != FontName)
   {
      FreeMemory(hPrevObj, hDC, hFont)
      MsgBox, Указанный шрифт не поддерживается системой!
      Return
   }
	
	VarSetCapacity(TextRect,16,0)
	DllCall(&quot;DrawText&quot; . coding, UInt, hDC, Str, String, Int, StrLen(String), Ptr, &amp;TextRect, UInt, DT_CALCRECT:=0x400)
	
    FreeMemory(hPrevObj, hDC, hFont)
	Return &amp;TextRect
}
 
FreeMemory(hPrevObj, hDC, hFont)
{
   DllCall(&quot;SelectObject&quot;, UInt, hDC, UInt, hPrevObj)
   DllCall(&quot;ReleaseDC&quot;, UInt, 0, UInt, hDC)
   DllCall(&quot;DeleteObject&quot;, UInt, hFont)
}</code></pre></div><p>2. ToolTip и WM_SETFONT пример 1<br /></p><div class="codebox"><pre><code>Text =
(
Многострочный
        текст
				
  Hello,World!
     AHK forever!
)

ToolTip,% Text
WinGet,httip,ID,% Text
; WinSet, Style,+0x40000,ahk_id %httip% ; добавим рамку изменения размера
if hFont:=CreateToolTipFont(&quot;Times New Roman&quot;,&quot;s20 bold italic&quot;)
SendMessage,0x30,hFont,1,,ahk_id %httip%
Return

Esc::
GuiClose:
DllCall(&quot;DeleteObject&quot;, UInt, hFont)
ExitApp

/*
WM_SETFONT = 0x30
WM_GETFONT = 0x31
*/

CreateToolTipFont(FontName,Options)
{
   coding := A_IsUnicode ? &quot;W&quot; : &quot;A&quot;   
   LOGPIXELSY := 90
   FW_NORMAL := 400, FW_BOLD := 700
   DEFAULT_CHARSET := 1
   DEFAULT_QUALITY := OUT_DEFAULT_PRECIS := CLIP_DEFAULT_PRECIS := 0
   
   if !RegExMatch(Options, &quot;i).*s(\d+).*&quot;, Found)
   {
      MsgBox, Не задан размер шрифта!
      Return
   }
   s := Found1
 
   if !InStr(Options, &quot;bold&quot;)
   {
      if !RegExMatch(Options, &quot;i).*w(\d+).*&quot;, Found)
         w := FW_NORMAL
      Else
         w := Found1
   }
   Else
      w := FW_BOLD

   if w not Between 1 and 1000
   {
      MsgBox, Неверно задан параметр w.`nДолжен быть в пределах от 1 до 1000
      Return
   }

   italic    := InStr(Options, &quot;italic&quot;) &gt; 0
   underline := InStr(Options, &quot;underline&quot;) &gt; 0
   strike    := InStr(Options, &quot;strike&quot;) &gt; 0

   hDC := DllCall(&quot;GetDC&quot;, UInt, 0)

   nHeight := -DllCall(&quot;MulDiv&quot;, Int, s, Int, DllCall(&quot;GetDeviceCaps&quot;, UInt, hDC, Int, LOGPIXELSY), Int, 72)
   
   hFont := DllCall(&quot;CreateFont&quot; . coding
                                , Int, nHeight, Int, 0
                                , Int, 0, Int, 0, Int, w
                                , UInt, italic, UInt, underline, UInt, strike
                                , UInt, DEFAULT_CHARSET, UInt, OUT_DEFAULT_PRECIS
                                , UInt, CLIP_DEFAULT_PRECIS, UInt, DEFAULT_QUALITY
                                , UInt, 0, Str, FontName)
 
   hPrevObj := DllCall(&quot;SelectObject&quot;, UInt, hDC, UInt, hFont)
	 
   VarSetCapacity(Buf, 40)
   DllCall(&quot;GetTextFace&quot; . coding, UInt, hDC, Int, 40, Str, Buf)
   DllCall(&quot;SelectObject&quot;, UInt, hDC, UInt, hPrevObj)
   DllCall(&quot;ReleaseDC&quot;, UInt, 0, UInt, hDC)
   if (Buf != FontName)
   {
      MsgBox, Указанный шрифт не поддерживается системой!  
      DllCall(&quot;DeleteObject&quot;, UInt, hFont)
      Return
   }
   Return hFont
}</code></pre></div><p>3. ToolTip и WM_SETFONT пример 2<br /></p><div class="codebox"><pre><code>Text =
(
Многострочный
        текст

  Hello,World!
    AHK forever!
)

Gui, Font, s20 bold italic, Times New Roman
Gui, Add,Text, HwndhStatic,% Text
SendMessage,0x31,,,,ahk_id %hStatic%
hFont:=ErrorLevel
ToolTip, % Text
WinGet,httip,ID,% Text
; WinSet, Style,+0x40000,ahk_id %httip% ; добавим рамку изменения размера
SendMessage,0x30,hFont,1,,ahk_id %httip%
Return

Esc::
GuiClose:
ExitApp</code></pre></div><p>4.<br /></p><div class="codebox"><pre><code>string:=&quot;меняем размер контрола Static (Text) и наблюдаем за поведением текста&quot;
Gui, + Lastfound +Resize -Caption
hgui:=WinExist()
Gui, Margin,0,0
Gui, Color, 0xFFFFE1
Gui, Font, s20 italic, Times New Roman
Gui, Add, Text, vText1 hwndhStatic, % string
Gui, Show
OnMessage(0x05,&quot;WndProc&quot;)
OnMessage(0x47,&quot;WndProc&quot;)
Return

WndProc(wParam,lParam,Msg,hWnd)
{
	global hgui,hStatic,hFont,wx,wy,ww,wh
	if (Msg=0x05)
	{
		hrgn:=DllCall(&quot;CreateRoundRectRgn&quot;,&quot;int&quot;,2,&quot;int&quot;,2,&quot;int&quot;,ww-1,&quot;int&quot;,wh-1,&quot;int&quot;,20,&quot;int&quot;,20)
		DllCall(&quot;SetWindowRgn&quot;,&quot;uint&quot;,hgui,&quot;uint&quot;,hrgn,&quot;int&quot;,1)
	}
	else if (Msg=0x47)
	{
		wx:=NumGet(lParam+8),wy:=NumGet(lParam+12)
		ww:=NumGet(lParam+16),wh:=NumGet(lParam+20)
; 		ToolTip, % &quot;ww &quot; . ww . &quot;wh &quot; . wh
; 		GuiControl, Move, Text1, % &quot;w&quot; . ww-6 . &quot; h&quot; . wh-6
		DllCall(&quot;SetWindowPos&quot;,&quot;uint&quot;,hStatic,&quot;uint&quot;,0,&quot;int&quot;,0,&quot;int&quot;,0,&quot;int&quot;,ww-6,&quot;int&quot;,wh-6,&quot;uint&quot;,0x2|0x4|0x10|0x40)
		DllCall(&quot;InvalidateRect&quot;,&quot;uint&quot;,hStatic,&quot;uint&quot;,0,&quot;int&quot;,1)
	}
}

Esc::
GuiClose:
ExitApp

/*
WM_WINDOWPOSCHANGED = 0x47
WM_SIZE = 0x05

SWP_NOSIZE          0x0001
SWP_NOMOVE          0x0002
SWP_NOZORDER        0x0004
SWP_NOREDRAW        0x0008
SWP_NOACTIVATE      0x0010
SWP_FRAMECHANGED    0x0020  /* The frame changed: send WM_NCCALCSIZE */
SWP_SHOWWINDOW      0x0040
SWP_HIDEWINDOW      0x0080
SWP_NOCOPYBITS      0x0100
SWP_NOOWNERZORDER   0x0200  /* Don&#039;t do owner Z ordering */
SWP_NOSENDCHANGING  0x0400  /* Don&#039;t send WM_WINDOWPOSCHANGING */

HWND_TOP        ((HWND)0)
HWND_BOTTOM     ((HWND)1)
HWND_TOPMOST    ((HWND)-1)
HWND_NOTOPMOST  ((HWND)-2)
*/</code></pre></div>]]></content>
			<author>
				<name><![CDATA[kirtech]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26525</uri>
			</author>
			<updated>2011-11-19T17:31:37Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=53689#p53689</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=53476#p53476" />
			<content type="html"><![CDATA[<p>Спасибо! В итоге вот такое получилось:<br /></p><div class="codebox"><pre><code>String =
(
Многострочный
текст

Hello, World!
AHK forever!
)

if pResult := GetTextSize(String, &quot;Arial&quot;, &quot;s24 italic&quot;)
{
   w := NumGet(pResult+0, 0, &quot;UInt&quot;)
   h := NumGet(pResult+0, 4, &quot;UInt&quot;)
   MsgBox, % &quot;Ширина &quot; . w . &quot;`nВысота &quot; . h
}
Return

GetTextSize(String, FontName, Options)
{
   static SIZE
   coding := A_IsUnicode ? &quot;W&quot; : &quot;A&quot;
   LOGPIXELSY := 90
   FW_NORMAL := 400, FW_BOLD := 700
   DEFAULT_CHARSET := 1
   DEFAULT_QUALITY := OUT_DEFAULT_PRECIS := CLIP_DEFAULT_PRECIS := 0

   if !RegExMatch(Options, &quot;i).*s(\d+).*&quot;, Found)
   {
      MsgBox, Не задан размер шрифта!
      Return
   }
   s := Found1

   if !InStr(Options, &quot;bold&quot;)
   {
      if !RegExMatch(Options, &quot;i).*w(\d+).*&quot;, Found)
         w := FW_NORMAL
      Else
         w := Found1
   }
   Else
      w := FW_BOLD
   if w not Between 1 and 1000
   {
      MsgBox, Неверно задан параметр w.`nДолжен быть в пределах от 1 до 1000
      Return
   }

   italic    := InStr(Options, &quot;italic&quot;) &gt; 0
   underline := InStr(Options, &quot;underline&quot;) &gt; 0
   strike    := InStr(Options, &quot;strike&quot;) &gt; 0

   hDC := DllCall(&quot;GetDC&quot;, UInt, 0)

   nHeight := -DllCall(&quot;MulDiv&quot;, Int, s
                  , Int, DllCall(&quot;GetDeviceCaps&quot;, UInt, hDC, Int, LOGPIXELSY), Int, 72)
   hFont := DllCall(&quot;CreateFont&quot; . coding
                                , Int, nHeight, Int, 0
                                , Int, 0, Int, 0, Int, w
                                , UInt, italic, UInt, underline, UInt, strike
                                , UInt, DEFAULT_CHARSET, UInt, OUT_DEFAULT_PRECIS
                                , UInt, CLIP_DEFAULT_PRECIS, UInt, DEFAULT_QUALITY
                                , UInt, 0, Str, FontName)

   hPrevObj := DllCall(&quot;SelectObject&quot;, UInt, hDC, UInt, hFont)

   VarSetCapacity(Buf, 40)
   DllCall(&quot;GetTextFace&quot; . coding, UInt, hDC, Int, 40, Str, Buf)
   if (Buf != FontName)
   {
      FreeMemory(hPrevObj, hDC, hFont)
      MsgBox, Указанный шрифт не поддерживается системой!
      Return
   }

   VarSetCapacity(SIZE, 8)
   width = 0
   Loop, parse, String, `n, `r
   {
      DllCall(&quot;GetTextExtentPoint32&quot; . coding
         , UInt, hDC, Str, A_LoopField, Int, StrLen(A_LoopField), Ptr, &amp;SIZE)
      width := (r := NumGet(SIZE, 0, &quot;UInt&quot;)) &gt; width ? r : width
      n := A_Index
   }
   h := NumGet(SIZE, 4, &quot;UInt&quot;)
   NumPut(width, SIZE, &quot;UInt&quot;), NumPut(h*n, SIZE, 4, &quot;UInt&quot;)
   FreeMemory(hPrevObj, hDC, hFont)
   Return &amp;SIZE
}

FreeMemory(hPrevObj, hDC, hFont)
{
   DllCall(&quot;SelectObject&quot;, UInt, hDC, UInt, hPrevObj)
   DllCall(&quot;ReleaseDC&quot;, UInt, 0, UInt, hDC)
   DllCall(&quot;DeleteObject&quot;, UInt, hFont)
}</code></pre></div><p>Проверяем:<br /></p><div class="codebox"><pre><code>Text =
(
Многострочный
текст

Hello, World!
AHK forever!
)

Gui, ToolTipWindow:New, -Caption +ToolWindow +LastFound
Gui, ToolTipWindow:Default
Gui, Font, s24 italic cBlue, Arial
Gui, Margin, 0, 0
Gui, Color, 0xFFFFE1
Gui, Add, Text,, % Text
Gui, Show, y100

WinGetPos,,, W, H
MsgBox, % &quot;Ширина окна &quot; W &quot;`nВысота окна &quot; H
ExitApp</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-11-13T16:18:41Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=53476#p53476</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=53463#p53463" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Нет, для &quot;Comic Sans MS&quot; — 71, для &quot;Verdana&quot; — 39, но и для &quot;123&quot; тоже 39.</p></blockquote></div><p>Наверно при некорректном названии функция ведёт себя как и при передаче нулевого адреса- выбирает шрифт подходящий под другие параметры. Проверить можно вызвав GetTextFace.<br />upd:<br /></p><div class="codebox"><pre><code>hFont := DllCall(&quot;CreateFont&quot; . (A_IsUnicode ? &quot;W&quot; : &quot;A&quot;)
                             , Int, nHeight, Int, 0
                             , Int, 0, Int, 0, Int, FW_NORMAL := 400
                             , Uint, 0, UInt, 0, UInt, 0, UInt, DEFAULT_CHARSET := 1
                             , UInt, OUT_DEFAULT_PRECIS := 0, UInt, CLIP_DEFAULT_PRECIS := 0
                             , UInt, DEFAULT_QUALITY := 0, UInt, 0, Str, &quot;123&quot;)

hPrevObj := DllCall(&quot;SelectObject&quot;, UInt, hDC, UInt, hFont)

VarSetCapacity(FontName, 256)
DllCall(&quot;GetTextFace&quot;,&quot;uint&quot;,hDC,&quot;uint&quot;,256,&quot;uint&quot;,&amp;FontName)
msgbox % StrGet(&amp;FontName) ;%</code></pre></div><p>У меня Arial выбирается. Собственно тут и вариантов-то было всего два- или функция вернёт 0, или выберет какой-то другой шрифт <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" />.</p>]]></content>
			<author>
				<name><![CDATA[Александр_]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24888</uri>
			</author>
			<updated>2011-11-12T21:49:27Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=53463#p53463</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=53462#p53462" />
			<content type="html"><![CDATA[<p>Нет, для &quot;Comic Sans MS&quot; — 71, для &quot;Verdana&quot; — 39, но и для &quot;123&quot; тоже 39.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-11-12T21:31:32Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=53462#p53462</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=53460#p53460" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Хм, теперь элемент <em>tmPitchAndFamily</em> структуры <em>TEXTMETRIC</em> возвращает всё время одно и то же число, независимо от того, какой текст указан в <em>lpszFace</em> <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /></p></blockquote></div><p>Т.е. для &quot;Comic Sans MS&quot; и &quot;Verdana&quot; одно и то же?</p>]]></content>
			<author>
				<name><![CDATA[Александр_]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24888</uri>
			</author>
			<updated>2011-11-12T18:34:23Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=53460#p53460</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=53457#p53457" />
			<content type="html"><![CDATA[<p>Хм, теперь элемент <em>tmPitchAndFamily</em> структуры <em>TEXTMETRIC</em> возвращает всё время одно и то же число, независимо от того, какой текст указан в <em>lpszFace</em> <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-11-12T17:00:47Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=53457#p53457</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ToolTip использующий специфичный шрифт]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=53455#p53455" />
			<content type="html"><![CDATA[<p>А-а-а! Точно, спасибо. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Правильный код такой:<br /></p><div class="codebox"><pre><code>String = многострочный

hDC := DllCall(&quot;GetDC&quot;, UInt, 0)

; Создаём шрифт Verdana s24
nHeight := -DllCall(&quot;MulDiv&quot;, Int, 24, Int
               , DllCall(&quot;GetDeviceCaps&quot;, Uint, hDC, Int, LOGPIXELSY := 90), Int, 72)
hFont := DllCall(&quot;CreateFont&quot; . (A_IsUnicode ? &quot;W&quot; : &quot;A&quot;)
                             , Int, nHeight, Int, 0
                             , Int, 0, Int, 0, Int, FW_NORMAL := 400
                             , Uint, 0, UInt, 0, UInt, 0, UInt, DEFAULT_CHARSET := 1
                             , UInt, OUT_DEFAULT_PRECIS := 0, UInt, CLIP_DEFAULT_PRECIS := 0
                             , UInt, DEFAULT_QUALITY := 0, UInt, 0, Str, &quot;Verdana&quot;)

hPrevObj := DllCall(&quot;SelectObject&quot;, UInt, hDC, UInt, hFont)

VarSetCapacity(TEXTMETRIC, A_IsUnicode ? 57 : 53)
DllCall(&quot;GetTextMetrics&quot; . (A_IsUnicode ? &quot;W&quot; : &quot;A&quot;), UInt, hDC, Ptr, &amp;TEXTMETRIC)
if ! (NumGet(TEXTMETRIC, A_IsUnicode ? 55 : 51, &quot;UChar&quot;)&gt;&gt;5)&amp;1
{
   MsgBox, Шрифт не поддерживается системой
   Gosub, FreeMemory
   Return
}

VarSetCapacity(SIZE, 8)
DllCall(&quot;GetTextExtentPoint32&quot; . (A_IsUnicode ? &quot;W&quot; : &quot;A&quot;), UInt, hDC, Str, String, Int, StrLen(String), Ptr, &amp;SIZE)

MsgBox, % &quot;Ширина &quot; . NumGet(SIZE, 0, &quot;UInt&quot;) . &quot;`nВысота &quot; . NumGet(SIZE, 4, &quot;UInt&quot;)

FreeMemory:
   DllCall(&quot;SelectObject&quot;, UInt, hDC, UInt, hPrevObj)
   DllCall(&quot;ReleaseDC&quot;, UInt, 0, UInt, hDC)
   DllCall(&quot;DeleteObject&quot;, UInt, hFont)
   Return</code></pre></div><p>Теперь для многострочного попробую!</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-11-12T16:32:37Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=53455#p53455</id>
		</entry>
</feed>
