<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2875227</guid>
        <pubDate>Wed, 13 Apr 2011 14:23:27 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2875227</link>
        <description><![CDATA[POP: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=225259&view=findpost&p=2875185'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>SourceUser &#064; <time class="tag-quote__quoted-time" datetime="2011-04-13T17:09:43+04:00">13.04.11, 13:09</time></span><div class='quote '>В первом случае видать буфер маленький, юзай LB_GETTEXTLEN, а во втором случае у тебя же строка пустая.</div></div><br>
<br>
Да я в итоге просто сам динамический массив Array of Char сделал и выделал под него память с использованием LB_GETTEXTLEN.<br>
<br>
По-идее под строки Delphi сама память автоматом все выделяет, самому не надо ничего делать.. ан не работает в этом случае.<br>
<br>
<br>
PS.<br>
Дак почему CalcHintRect(1000,Text,nil) не работает?<br>
<br>
В описании написано, что по достижении 1000 пикселов, Хинт должен переноситься на новую строку, но ничего не переноситься.]]></description>
        <author>POP</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2875185</guid>
        <pubDate>Wed, 13 Apr 2011 13:09:43 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2875185</link>
        <description><![CDATA[SourceUser: В первом случае видать буфер маленький, юзай LB_GETTEXTLEN, а во втором случае у тебя же строка пустая.<br>
Делай как то так.<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Buf: PChar;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;GetMem(Buf, SendMessage(Wnd, LB_GETTEXTLEN, 0,0));</div><div class="code_line">&nbsp;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Buf: String;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;SetLength(Buf, SendMessage(Wnd, LB_GETTEXTLEN, 0,0))</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script>]]></description>
        <author>SourceUser</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2875126</guid>
        <pubDate>Wed, 13 Apr 2011 12:41:54 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2875126</link>
        <description><![CDATA[POP: Не могу справиться с одной проблемой:<br>
<br>
Если указать статический буфер для Хинта, то будет AccessViolation если Хинт вылезет за пределы статического массива, если указать много, то зря память расходоваться будет. Хочу массив заменить обычной строкой (она же типа динамический массив). Почему не работает вот так:<br>
<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">procedure TComboBoxPatch.AdjustHint(Wnd: HWND; Point: TPoint);</div><div class="code_line">var</div><div class="code_line">HintPt: TPoint;</div><div class="code_line">ItemRect: TRect;</div><div class="code_line">Item, TextWidth: Integer;</div><div class="code_line">// buf: array[0..127] of Char; &nbsp;- Было.</div><div class="code_line">buf: string; &nbsp; // Стало</div><div class="code_line">&nbsp;</div><div class="code_line">begin</div><div class="code_line">&nbsp;Windows.ScreenToClient(Wnd,Point);</div><div class="code_line">&nbsp;Item:=SendMessage(Wnd,LB_ITEMFROMPOINT,0,lParam(PointToSmallPoint(Point)));</div><div class="code_line">&nbsp;if (Item and {text}010000 &#60;&#62; {text}010000) and (Item &#60;&#62; FHintIndex) then</div><div class="code_line">&nbsp;begin</div><div class="code_line">&nbsp;&nbsp;FHintIndex:=Item;</div><div class="code_line">// &nbsp;SendMessage(Wnd,LB_GETTEXT,Item,Integer(@buf)); &nbsp; - Было</div><div class="code_line">&nbsp;&nbsp;SendMessage(Wnd,LB_GETTEXT,Item,Integer(PChar(buf))); &nbsp;// Стало</div><div class="code_line">&nbsp;&nbsp;SendMessage(Wnd,LB_GETITEMRECT,Item,Integer(@ItemRect));</div><div class="code_line">&nbsp;&nbsp;FCanvas.Handle:=GetDC(Wnd);</div><div class="code_line">&nbsp;&nbsp;TextWidth:=FCanvas.TextWidth(buf);</div><div class="code_line">&nbsp;&nbsp;ReleaseDC(Wnd,FCanvas.Handle);</div><div class="code_line">&nbsp;&nbsp;FCanvas.Handle:=0;</div><div class="code_line">&nbsp;&nbsp;if FAlwaysShowHint or ((not FAlwaysShowHint) and (ItemRect.Right &#60; TextWidth)) then</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; HintPt:=ItemRect.TopLeft;</div><div class="code_line">&nbsp;&nbsp; Windows.ClientToScreen(Wnd,HintPt);</div><div class="code_line">&nbsp;&nbsp; ShowHint(HintPt,buf);</div><div class="code_line">&nbsp;&nbsp;end</div><div class="code_line">&nbsp;&nbsp;else</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; HideHint;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;end</div><div class="code_line">&nbsp;else</div><div class="code_line">&nbsp;begin</div><div class="code_line">&nbsp;&nbsp;if Item &#60; 0 then HideHint;</div><div class="code_line">&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div><br>
<br>
<br>
<br>
Пометил как Было и как Стало, две строчки заменил.<br>
<br>
Виснет при показе Хинта.]]></description>
        <author>POP</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2874737</guid>
        <pubDate>Wed, 13 Apr 2011 06:53:04 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2874737</link>
        <description><![CDATA[POP: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=225259&view=findpost&p=2874563'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>SourceUser &#064; <time class="tag-quote__quoted-time" datetime="2011-04-12T19:47:16+00:00">12.04.11, 19:47</time></span><div class='quote '>А эта строчка просто ложит нашу подсказку над системным ComboLBox, ибо он иногда побеждает и вылазин наверх.</div></div><br>
<br>
Я знаю.. значит она просто не портит то что делается в ActivateHint, как это происходит в компоненте <strong class='tag-b'>Шевченко</strong> и <strong class='tag-b'>--Ins--</strong>]]></description>
        <author>POP</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2874563</guid>
        <pubDate>Tue, 12 Apr 2011 19:47:16 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2874563</link>
        <description><![CDATA[SourceUser: <strong class='tag-b'>POP</strong> - Неа. <br>
Глянь в исходниках метод<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">procedure THintWindow.ActivateHint(Rect: TRect; const AHint: string);</div></ol></div></div></div></div><br>
всё выравнивание делается там.<br>
<br>
А эта строчка просто ложит нашу подсказку над системным ComboLBox, ибо он иногда побеждает и вылазин наверх.]]></description>
        <author>SourceUser</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2874552</guid>
        <pubDate>Tue, 12 Apr 2011 19:36:16 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2874552</link>
        <description><![CDATA[POP: <strong class='tag-b'>SourceUser</strong><br>
<br>
Вот эта строка SetWindowPos(FHint.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); , и есть решение проблемы с вырваниванием Хинта, если он вылез за пределы экрана.]]></description>
        <author>POP</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2874444</guid>
        <pubDate>Tue, 12 Apr 2011 16:14:09 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2874444</link>
        <description><![CDATA[SourceUser: Ну и я до кучи выложу вариант, что делал когдато. Очень компактный.<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;TComboBox = class(StdCtrls.TComboBox)</div><div class="code_line">&nbsp;&nbsp;private</div><div class="code_line">&nbsp;&nbsp; &nbsp;FListIndex: Integer;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FHint: THintWindow;</div><div class="code_line">&nbsp;&nbsp;public</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer); override;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;TForm1 = class(TForm)</div><div class="code_line">&nbsp;&nbsp; &nbsp;ComboBox1: TComboBox;</div><div class="code_line">&nbsp;&nbsp; &nbsp;XPManifest1: TXPManifest;</div><div class="code_line">&nbsp;&nbsp;private</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Private declarations }</div><div class="code_line">&nbsp;&nbsp;public</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Form1: TForm1;</div><div class="code_line">&nbsp;</div><div class="code_line">implementation</div><div class="code_line">&nbsp;</div><div class="code_line">{$R *.dfm}</div><div class="code_line">&nbsp;</div><div class="code_line">{ TComboBox }</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TComboBox.CNCommand(var Message: TWMCommand);</div><div class="code_line">var Info: TComboBoxInfo;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;inherited;</div><div class="code_line">&nbsp;&nbsp;case Message.NotifyCode of</div><div class="code_line">&nbsp;&nbsp; &nbsp;CBN_DROPDOWN:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (Style &#60;&#62; csSimple) then begin // хукаем список, предок хукает его только при стиле csSimple</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Info.cbSize := SizeOf(Info);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if GetComboBoxInfo(Self.Handle, &nbsp;Info) and (Info.hwndList &#60;&#62; 0) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FListHandle := Info.hwndList;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FDefListProc := Pointer(GetWindowLong(FListHandle, GWL_WNDPROC));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetWindowLong(FListHandle, GWL_WNDPROC, Longint(FListInstance));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FListIndex := -1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FHint := nil;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;CBN_CLOSEUP: &nbsp;// убираем хук</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (Style &#60;&#62; csSimple) and (FListHandle &#60;&#62; 0) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;SetWindowLong(FListHandle, GWL_WNDPROC, Longint(FDefListProc));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;FreeAndNil(FHint);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TComboBox.ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer);</div><div class="code_line">var J, NewIndex: Integer;</div><div class="code_line">&nbsp;&nbsp; &nbsp;ItemRect, R: TRect;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Pt: TPoint;</div><div class="code_line">&nbsp;&nbsp; &nbsp;DC: HDC;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Size: TSize;</div><div class="code_line">&nbsp;&nbsp; &nbsp;OldFont: HFont;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;inherited;</div><div class="code_line">&nbsp;&nbsp;if ComboWnd = FListHandle then</div><div class="code_line">&nbsp;&nbsp;with Message do</div><div class="code_line">&nbsp;&nbsp; &nbsp;case Msg of</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;WM_MOUSEMOVE:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NewIndex := -1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// получаем текущий индекс под мышкой</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for J := 0 to SendMessage(FListHandle, LB_GETCOUNT , 0, 0)-1 do begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(FListHandle, LB_GETITEMRECT, J, Cardinal(@ItemRect));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Pt := Mouse.CursorPos;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MapWindowPoints(0, FListHandle, Pt, 1);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if PtInRect(ItemRect, Pt) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NewIndex := J;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if NewIndex &#60; 0 then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FreeAndNil(FHint);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FListIndex := -1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; // если индекс поменялся</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if J &#60;&#62; FListIndex then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FreeAndNil(FHint);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FListIndex := NewIndex;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// проверяем вмещается ли текст</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DC := GetDC(FListHandle);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OldFont := SelectObject(DC, Screen.HintFont.Handle);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetTextExtentPoint32(DC, PChar(Items[J]), Length(Items[J]), Size);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SelectObject(DC, OldFont);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ReleaseDC(FListHandle, DC);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // показываем подсказку</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Size.cx &#62; (ItemRect.Right-ItemRect.Left) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FreeAndNil(FHint);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FHint := THintWindow.Create(Self);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R := FHint.CalcHintRect(Screen.Width, Items[J], nil);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MapWindowPoints(FListHandle, 0, ItemRect, 2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ItemRect.Right := ItemRect.Left + (R.Right-R.Left);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ItemRect.Bottom := ItemRect.Top + (R.Bottom-R.Top);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FHint.ActivateHint(ItemRect, Items[J]);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetWindowPos(FHint.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end; // WM_MOUSEMOVE</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div>]]></description>
        <author>SourceUser</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2873642</guid>
        <pubDate>Mon, 11 Apr 2011 19:17:52 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2873642</link>
        <description><![CDATA[POP: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=225259&view=findpost&p=1882581'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>&#045;&#045;Ins&#045;&#045; &#064; <time class="tag-quote__quoted-time" datetime="2008-02-27T14:29:51+00:00">27.02.08, 14:29</time></span><div class='quote '>Для кучи, выложу свое решение, написанное некогда давно, также под влиянием кода Игоря Шевченко. Идея только несколько отличается - вместо потомка TComboBox - неоконный компонент, который нужно просто бросить на любую форму, и все ComboBox-ы начнут показывать Hint</div></div><br>
<br>
Хотелось бы доработать этот компонент, исправить баги и разобраться в одной фишке. Хороший ведь компонент, полезный:<br>
<br>
Во-первых, чтобы он реально не позволял себя многократно использовать и сек все попытки наложить больше одного компонента на форму, нужно удалить из Деструктора строку &quot;GlobalPatch:=nil;&quot;<br>
<br>
Во-вторых он поддерживает только Хинты не более чем в 128 символов, а иначе валится нафиг в AccessViolation. Но это поправимо.<br>
<br>
Самое главное, что в функции ShowHint вызовом SetWindowPos мочиться наглухо способность ActivateHint выравнивать влево длинные Хинты, если они вылазят за пределы экрана (правую часть). Если SetWindowPos не использовать, тогда первый всплывающий Хинт оказывается под списком (что собственно SetWindowPos и фиксит). Короче замкнтуый круг. В компоненте Шевченко, все тоже самое.<br>
<br>
Предложения по фиксу принимаются. Хочется всего сразу.<br>
<br>
<br>
PS.<br>
И попутно вопрос: в той же функции ShowHint есть вызов CalcHintRect(1000,Text,nil), где &quot;1000&quot; это количество пикселей, и якобы если текст хинта в эти пиксели не влезает, он будет перенесен на вторую строку. Но на практике этого не происходит, почему?]]></description>
        <author>POP</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2259565</guid>
        <pubDate>Wed, 06 May 2009 20:26:09 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=2259565</link>
        <description><![CDATA[TanoCariddi: Компонент очень хороший&#33; Спасибо за него Игорю Шевченко.<br>
<br>
Глюк, когда при первом наведении мышью на элемент list&#39;а hint уходит на задний план, можно исправить, добавив (выделено жирным)<br>
<br>
if NOT HideToolTip then<br>
{ Если двигаться мышью в горизонтальном направлении на элементе, для которого<br>
  должен показываться Hint, то ActivateHint не стоит вызывать, если Hint уже<br>
  уже на экране }<br>
            if NOT (IsWindow(FListBoxTip.Handle) and<br>
                    IsWindowVisible(FListBoxTip.Handle) and<br>
                   (StrComp(PChar(FListBoxTip.Caption),PChar(ItemText)) = 0)) then begin<br>
              AdjustHintRect (ItemRect, ItemText);<br>
              FListBoxTip.ActivateHint(ItemRect, ItemText);<br>
<strong class='tag-b'>              SetWindowPos(FListBoxTip.Handle,HWND_TOPMOST,ItemRect.Left,ItemRect.Top,FListBoxTip.Width,<br>
                FListBoxTip.Height,SWP_NOACTIVATE);<br>
</strong>            end;<br>
<br>
Более того, данный компонент можно сделать визуальным, добавив (выделено жирным)<br>
<br>
       write SetHorizontalExtent default -1;<br>
{/16.04.2002}<br>
  end;<br>
<br>
<strong class='tag-b'>procedure Register;  </strong><br>
  <br>
implementation<br>
uses SysUtils;<br>
<br>
<strong class='tag-b'>procedure Register;<br>
begin<br>
  RegisterComponents(&#39;Samples&#39;,[THSHintComboBox]);<br>
end;</strong><br>
<br>
function RectWidth(R : TRect) : Integer;<br>
begin<br>
  Result := R.Right - R.Left;<br>
end;<br>
<br>
<br>
Текст компонента полностью будет выглядеть так:<br>
<br>
<table class='post_table tag-table'><tr><td><br>
{<br>
  Наследник TComboBox, показывающий Hint для строки в ListBox&#39;овой части,<br>
  не видимой целиком.<br>
<br>
  Автор: Игорь Шевченко<br>
  Дата создания: 13.04.2002<br>
<br>
  Ограничения:<br>
  Компонент проверялся при работе с значением Style: csDropDown, csDropDownList.<br>
  при остальных значениях работа не гарантируется :-)<br>
  Компонент не тестировался в режиме design-time.<br>
<br>
  История изменений:<br>
  16.04.2002 Исправлено поведение при закрытии, когда показан hint и ComboBox<br>
             закрывается по клавише Enter, Escape или F4. Теперь hint убирается.<br>
             Добавлено свойство HorizontalExtent, позволяющее устанавливать<br>
             горизонтальный Scrollbar в списке ComboBox&#39;a. По умолчанию свойство<br>
             имеет значение -1, что запрещает установку горизонтального<br>
             ScrollBar&#39;а.<br>
}<br>
unit HSHintComboBox;<br>
<br>
interface<br>
uses<br>
  Windows, Messages, Classes, Graphics, Controls, Forms, StdCtrls, AppEvnts;<br>
<br>
type<br>
  TListBoxTip = class(THintWindow)<br>
  end;<br>
<br>
  TShowComboToolTipEvent = procedure (Sender : TObject;<br>
                                     const ToolTipText : String;<br>
                                     var HideToolTip : Boolean) of object;<br>
<br>
  THSHintComboBox = class(TComboBox)<br>
//  THSHintComboBox = class(TComponent)<br>
  private<br>
    FListBoxTip : TListBoxTip;<br>
    FListHandle : HWND;<br>
    FListWndProcInstance : TFarProc;<br>
    FOldListWndProc : TFarProc;<br>
    FOnListMouseMove: TMouseMoveEvent;<br>
    FOnShowComboToolTip: TShowComboToolTipEvent;<br>
    FShowToolTips: Boolean;<br>
    FHorizontalExtent: Integer;<br>
    procedure ListWndProc (var Message : TMessage);<br>
    function ListBoxItemAtPos (I : Integer) : String;<br>
    function ListBoxItemRectAtPos (I : Integer; AText : String) : TRect;<br>
    procedure SetShowToolTips(const Value: Boolean);<br>
    procedure SetHorizontalExtent(const Value: Integer);<br>
  protected<br>
    procedure DoListMouseMove (Shift: TShiftState; X, Y: Integer); dynamic;<br>
    procedure DoShowComboToolTip (const ToolTipText : String;<br>
                                 var HideToolTip : Boolean); dynamic;<br>
    procedure WndProc (var Message: TMessage); override;<br>
{16.04.2002}<br>
    procedure CreateParams (var Params : TCreateParams); override;<br>
    procedure CreateWnd; override;<br>
{/16.04.2002}<br>
  public<br>
    constructor Create (AOwner : TComponent); override;<br>
    destructor Destroy; override;<br>
    { Handle окна ListBox&#39;а, являющегося частью ComboBox&#39;a }<br>
    property HSListHandle : HWND read FListHandle;<br>
    { Показывать ли Hint для строк, не видимых целиком в ListBox&#39;е }<br>
    property ShowToolTips : Boolean read FShowToolTips<br>
                         write SetShowToolTips default true;<br>
    { Событие при движении мыши по ListBox&#39;у. Так как ListBox захватывает<br>
      (Captured) мышь, то координаты курсора в этом событии могут быть за<br>
      пределами клентской части ListBox&#39;а }<br>
    property OnListMouseMove : TMouseMoveEvent read FOnListMouseMove<br>
        write FOnListMouseMove;<br>
    { Событие при показе Hint&#39;а для ListBox&#39;а. Установив HideHint в True,<br>
      можно запретить показ конкретного Hint&#39;а }<br>
    property OnShowComboToolTip : TShowComboToolTipEvent<br>
        read FOnShowComboToolTip write FOnShowComboToolTip;<br>
{16.04.2002}<br>
    property HorizontalExtent : Integer read FHorizontalExtent<br>
       write SetHorizontalExtent default -1;<br>
{/16.04.2002}<br>
  end;<br>
<br>
procedure Register;  <br>
  <br>
implementation<br>
uses SysUtils;<br>
<br>
procedure Register;<br>
begin<br>
  RegisterComponents(&#39;Samples&#39;,[THSHintComboBox]);<br>
end;<br>
<br>
function RectWidth(R : TRect) : Integer;<br>
begin<br>
  Result := R.Right - R.Left;<br>
end;<br>
<br>
function RectHeight(R : TRect) : Integer;<br>
begin<br>
  Result := R.Bottom - R.Top;<br>
end;<br>
<br>
{ THSHintComboBox }<br>
<br>
constructor THSHintComboBox.Create(AOwner: TComponent);<br>
begin<br>
  inherited;<br>
  FListBoxTip := TListBoxTip.Create(Self);<br>
  FListBoxTip.Color := clInfoBk;<br>
  FListWndProcInstance := MakeObjectInstance(ListWndProc);<br>
  FShowToolTips := true;<br>
  FHorizontalExtent := -1;<br>
end;<br>
<br>
destructor THSHintComboBox.Destroy;<br>
begin<br>
  if (FListHandle &lt;&gt; 0) AND IsWindow(FListHandle) then<br>
    SetWindowLong(FListHandle, GWL_WNDPROC, LongInt(FOldListWndProc));<br>
  FreeObjectInstance(FListWndProcInstance);<br>
  inherited;<br>
end;<br>
<br>
procedure THSHintComboBox.DoShowComboToolTip(const ToolTipText: String;<br>
                                             var HideToolTip : Boolean);<br>
begin<br>
  if Assigned(FOnShowComboToolTip) then<br>
    FOnShowComboToolTip (Self, ToolTipText, HideToolTip);<br>
end;<br>
<br>
procedure THSHintComboBox.DoListMouseMove(Shift: TShiftState; X,<br>
  Y: Integer);<br>
<br>
  procedure AdjustHintRect (var R : TRect; const AHintStr : String);<br>
  var<br>
    DC : HDC;<br>
    OldFont : HFONT;<br>
    TextSize : SIZE;<br>
  begin<br>
    DC := GetDC (HWND_DESKTOP);<br>
    try<br>
      OldFont := SelectObject(DC, Screen.HintFont.Handle);<br>
      try<br>
        if (NOT GetTextExtentPoint32(DC, PChar(AHintStr), StrLen(PChar(AHintStr)), TextSize)) then<br>
          RaiseLastWin32Error;<br>
        Inc(TextSize.cx, 6);<br>
        Inc(TextSize.cy, 2);<br>
		    R.Left := R.Left + 20;<br>
		    R.Top := R.Top + 15;<br>
<br>
        if RectWidth&reg; &lt; TextSize.cx then<br>
          R.Right := R.Left + TextSize.cx;<br>
        if RectHeight&reg; &lt; TextSize.cy then<br>
          R.Bottom := R.Top + TextSize.cy;<br>
	  finally<br>
        SelectObject(DC, OldFont);<br>
      end;<br>
    finally<br>
      ReleaseDC (HWND_DESKTOP, DC);<br>
    end;<br>
  end;<br>
<br>
var R, ItemRect : TRect;<br>
    I : Integer;<br>
    ItemText : String;<br>
    HideToolTip : Boolean;<br>
begin<br>
  HideToolTip := True; { По умолчанию выключать Hint }<br>
  if FShowToolTips then begin<br>
    Windows.GetClientRect(FListHandle, R);<br>
    { X и Y являются координатами клиента (в данном случае, ListBox }<br>
    if PtInRect(R, Point(X,Y)) AND (Shift = []) then begin<br>
      { Определим, помещается ли текущая строка целиком в область ListBox }<br>
      I := SendMessage(FListHandle, LB_ITEMFROMPOINT, 0, MakeLParam(X,Y));<br>
      if HiWord(I) &lt;&gt; 0 then<br>
        I := -1;<br>
      if I &lt;&gt; -1 then begin<br>
        ItemText := ListBoxItemAtPos(I);<br>
        ItemRect := ListBoxItemRectAtPos(I, ItemText);<br>
        if RectWidth(ItemRect) &gt; RectWidth&reg; then begin<br>
          { Надо показывать Hint, так как строка не помещается целиком<br>
            в клиентскую область ListBox }<br>
          Windows.ClientToScreen(FListHandle, ItemRect.TopLeft);<br>
          Windows.ClientToScreen(FListHandle, ItemRect.BottomRight);<br>
          Dec(ItemRect.Left, 3);<br>
          Inc(ItemRect.Right, 6);<br>
          HideToolTip := false; { Не надо гасить hint }<br>
          DoShowComboToolTip (ItemText, HideToolTip); { Для возможности<br>
                                         отображения строки Hint дополнительно<br>
                                         в другом месте или запрета<br>
                                         конкретного Hint&#39;а}<br>
{16.04.2002}<br>
          if NOT HideToolTip then<br>
{ Если двигаться мышью в горизонтальном направлении на элементе, для которого<br>
  должен показываться Hint, то ActivateHint не стоит вызывать, если Hint уже<br>
  уже на экране }<br>
            if NOT (IsWindow(FListBoxTip.Handle) and<br>
                    IsWindowVisible(FListBoxTip.Handle) and<br>
                   (StrComp(PChar(FListBoxTip.Caption),PChar(ItemText)) = 0)) then begin<br>
              AdjustHintRect (ItemRect, ItemText);<br>
              FListBoxTip.ActivateHint(ItemRect, ItemText);<br>
              SetWindowPos(FListBoxTip.Handle,HWND_TOPMOST,ItemRect.Left,ItemRect.Top,FListBoxTip.Width,<br>
                FListBoxTip.Height,SWP_NOACTIVATE);<br>
            end;<br>
{/16.04.2002}<br>
        end;<br>
      end;<br>
    end;<br>
  end;<br>
  if HideToolTip then<br>
    FListBoxTip.ReleaseHandle; { Не надо показывать Hint, если мышь за пределами<br>
                                 ListBox или строка видна целиком }<br>
  { Если кому-то вздумается следить за перемещениями мыши в области ListBox.<br>
    Я при отладке использовал это событие для отображения координат мыши }<br>
  if Assigned(FOnListMouseMove) then<br>
    FOnListMouseMove(Self, Shift, X, Y);<br>
end;<br>
<br>
function THSHintComboBox.ListBoxItemAtPos(I: Integer): String;<br>
var<br>
  L : Integer;<br>
begin<br>
  if I &lt;&gt; -1 then begin<br>
    L := SendMessage(FListHandle, LB_GETTEXTLEN, I, 0);<br>
    SetLength(Result, L+1); { +1 на нулевой символ в конце строки }<br>
    SendMessage(FListHandle, LB_GETTEXT, I, Integer(PChar(Result)));<br>
  end else<br>
    Result := &#39;&#39;;<br>
end;<br>
<br>
function THSHintComboBox.ListBoxItemRectAtPos(I: Integer;<br>
  AText: String): TRect;<br>
var<br>
  DC : HDC;<br>
  OldFont : HFONT;<br>
begin<br>
  Result := Rect(0, 0, 0, 0);<br>
  if (I &lt;&gt; -1) AND (SendMessage(FListHandle, LB_GETITEMRECT, I,<br>
                    Integer(@Result)) &lt;&gt; LB_ERR) then begin<br>
    DC := GetDC(FListHandle);<br>
    try<br>
      OldFont := SelectObject(DC, Font.Handle);<br>
      try<br>
        DrawText(DC, PChar(AText), -1, Result, DT_CALCRECT);<br>
      finally<br>
        SelectObject(DC, OldFont);<br>
      end;<br>
    finally<br>
      ReleaseDC(FListHandle, DC);<br>
    end;<br>
  end;<br>
end;<br>
<br>
procedure THSHintComboBox.ListWndProc(var Message: TMessage);<br>
begin<br>
  case Message.Msg of<br>
  WM_MOUSEMOVE:<br>
    with TWMMouseMove(Message) do<br>
      DoListMouseMove(KeysToShiftState(Keys), XPos, YPos);<br>
{16.04.2002}<br>
{ Как выяснилось, при нажатии Esc или Enter на выбранном элементе, который<br>
  показывает Hint, ComboBox закрывается, а Hint остается. :-(<br>
  Сообщение SHOWWINDOW с WPARAM=0 гарантировано выдается, когда закрывается<br>
  окно, так что это место можно использовать для гашения Hint&#39;a }<br>
  WM_SHOWWINDOW:<br>
    if Message.WParam = 0 then<br>
      FListBoxTip.ReleaseHandle();<br>
{/16.04.2002}<br>
  end;<br>
  with Message do<br>
    Result := CallWindowProc(FOldListWndProc, FListHandle, Msg, WParam, LParam);<br>
end;<br>
<br>
procedure THSHintComboBox.SetShowToolTips(const Value: Boolean);<br>
begin<br>
  FShowToolTips := Value;<br>
end;<br>
<br>
procedure THSHintComboBox.WndProc(var Message: TMessage);<br>
begin<br>
  if (Message.Msg = WM_CTLCOLORLISTBOX) AND (FListHandle = 0) then begin<br>
    FListHandle := HWND(Message.LParam);<br>
    FOldListWndProc := Pointer(GetWindowLong(FListHandle, GWL_WNDPROC));<br>
    SetWindowLong(FListHandle,<br>
                  GWL_WNDPROC, LongInt(FListWndProcInstance));<br>
  end;<br>
  inherited;<br>
end;<br>
<br>
{16.04.2002}<br>
procedure THSHintComboBox.CreateParams(var Params: TCreateParams);<br>
begin<br>
  inherited;<br>
  if FHorizontalExtent &lt;&gt; -1 then<br>
    with Params do<br>
      Style := Style OR WS_HSCROLL;<br>
end;<br>
<br>
procedure THSHintComboBox.SetHorizontalExtent(const Value: Integer);<br>
begin<br>
  if (FHorizontalExtent &lt;&gt; Value) then begin<br>
    FHorizontalExtent := Value;<br>
    if NOT (csLoading in ComponentState) then<br>
      RecreateWnd();<br>
  end;<br>
end;<br>
<br>
procedure THSHintComboBox.CreateWnd;<br>
begin<br>
  inherited;<br>
  if FHorizontalExtent &lt;&gt; -1 then<br>
    Perform(CB_SETHORIZONTALEXTENT, FHorizontalExtent, 0);<br>
end;<br>
{/16.04.2002}<br>
<br>
end.<br>
<br>
</td></tr></table>]]></description>
        <author>TanoCariddi</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=1882581</guid>
        <pubDate>Wed, 27 Feb 2008 14:29:51 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=1882581</link>
        <description><![CDATA[--Ins--: Для кучи, выложу свое решение, написанное некогда давно, также под влиянием кода Игоря Шевченко. Идея только несколько отличается - вместо потомка TComboBox - неоконный компонент, который нужно просто бросить на любую форму, и все ComboBox-ы начнут показывать Hint<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">unit ComboBoxPatch;</div><div class="code_line">&nbsp;</div><div class="code_line">interface</div><div class="code_line">&nbsp;</div><div class="code_line">uses Windows, Messages, SysUtils, Classes, Controls, Graphics, AppEvnts;</div><div class="code_line">&nbsp;</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;EComboBoxPatchException = class(Exception);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;TComboBoxPatch = class(TComponent)</div><div class="code_line">&nbsp;&nbsp;private</div><div class="code_line">&nbsp;&nbsp; &nbsp;FHintWnd: THintWindow;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FCanvas: TCanvas;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FAppEvnts: TApplicationEvents;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FHintIndex: Integer;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FActive: Boolean;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FAlwaysShowHint: Boolean;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure AdjustHint(Wnd: HWND; Point: TPoint);</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure DoIdle(Sender: TObject; var Done: Boolean);</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure ShowHint(Origin: TPoint; Text: String);</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure HideHint;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure SetActive(const Value: Boolean);</div><div class="code_line">&nbsp;&nbsp;public</div><div class="code_line">&nbsp;&nbsp; &nbsp;constructor Create(AOwner: TComponent); override;</div><div class="code_line">&nbsp;&nbsp; &nbsp;destructor Destroy; override;</div><div class="code_line">&nbsp;&nbsp;published</div><div class="code_line">&nbsp;&nbsp; &nbsp;property Active: Boolean read FActive write SetActive default true;</div><div class="code_line">&nbsp;&nbsp; &nbsp;property AlwaysShowHint: Boolean read FAlwaysShowHint write FAlwaysShowHint default false;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">const</div><div class="code_line">&nbsp;&nbsp;RSOnlyOneComboBoxPatch = &#39;Only one TComboBoxPatch can exist per application.&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;GlobalPatch: TComboBoxPatch = nil;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure Register;</div><div class="code_line">&nbsp;</div><div class="code_line">implementation</div><div class="code_line">&nbsp;</div><div class="code_line">uses Forms;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure Register;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;RegisterComponents(&#39;Samples&#39;,[TComboBoxPatch]);</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">{ TComboBoxPatch }</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TComboBoxPatch.AdjustHint(Wnd: HWND; Point: TPoint);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;HintPt: TPoint;</div><div class="code_line">&nbsp;&nbsp;ItemRect: TRect;</div><div class="code_line">&nbsp;&nbsp;Item, TextWidth: Integer;</div><div class="code_line">&nbsp;&nbsp;buf: array[0..127] of Char;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Windows.ScreenToClient(Wnd,Point);</div><div class="code_line">&nbsp;&nbsp;Item:=SendMessage(Wnd,LB_ITEMFROMPOINT,0,lParam(PointToSmallPoint(Point)));</div><div class="code_line">&nbsp;&nbsp;if (Item and {text}010000 &#60;&#62; {text}010000) and (Item &#60;&#62; FHintIndex) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;FHintIndex:=Item;</div><div class="code_line">&nbsp;&nbsp; &nbsp;SendMessage(Wnd,LB_GETTEXT,Item,Integer(@buf));</div><div class="code_line">&nbsp;&nbsp; &nbsp;SendMessage(Wnd,LB_GETITEMRECT,Item,Integer(@ItemRect));</div><div class="code_line">&nbsp;&nbsp; &nbsp;FCanvas.Handle:=GetDC(Wnd);</div><div class="code_line">&nbsp;&nbsp; &nbsp;TextWidth:=FCanvas.TextWidth(buf);</div><div class="code_line">&nbsp;&nbsp; &nbsp;ReleaseDC(Wnd,FCanvas.Handle);</div><div class="code_line">&nbsp;&nbsp; &nbsp;FCanvas.Handle:=0;</div><div class="code_line">&nbsp;&nbsp; &nbsp;if FAlwaysShowHint or ((not FAlwaysShowHint) and (ItemRect.Right &#60; TextWidth)) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;HintPt:=ItemRect.TopLeft;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Windows.ClientToScreen(Wnd,HintPt);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ShowHint(HintPt,buf);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end</div><div class="code_line">&nbsp;&nbsp; &nbsp;else begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;HideHint;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end</div><div class="code_line">&nbsp;&nbsp;else begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Item &#60; 0 then HideHint;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">constructor TComboBoxPatch.Create(AOwner: TComponent);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;inherited Create(AOwner);</div><div class="code_line">&nbsp;&nbsp;if Assigned(GlobalPatch) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;raise EComboBoxPatchException.Create(RSOnlyOneComboBoxPatch);</div><div class="code_line">&nbsp;&nbsp;end</div><div class="code_line">&nbsp;&nbsp;else begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;GlobalPatch:=Self;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;FHintIndex:=-1;</div><div class="code_line">&nbsp;&nbsp;FHintWnd:=THintWindow.Create(Self);</div><div class="code_line">&nbsp;&nbsp;FHintWnd.Color:=Application.HintColor;</div><div class="code_line">&nbsp;&nbsp;FCanvas:=TCanvas.Create;</div><div class="code_line">&nbsp;&nbsp;FAppEvnts:=TApplicationEvents.Create(Self);</div><div class="code_line">&nbsp;&nbsp;FAlwaysShowHint:=false;</div><div class="code_line">&nbsp;&nbsp;Active:=true;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">destructor TComboBoxPatch.Destroy;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;GlobalPatch:=nil;</div><div class="code_line">&nbsp;&nbsp;FCanvas.Free;</div><div class="code_line">&nbsp;&nbsp;FAppEvnts.Free;</div><div class="code_line">&nbsp;&nbsp;FHintWnd.Free;</div><div class="code_line">&nbsp;&nbsp;inherited Destroy;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TComboBoxPatch.DoIdle(Sender: TObject; var Done: Boolean);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Pt: TPoint;</div><div class="code_line">&nbsp;&nbsp;buf: array[0..127] of Char;</div><div class="code_line">&nbsp;&nbsp;Wnd: HWND;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;GetCursorPos(Pt);</div><div class="code_line">&nbsp;&nbsp;Wnd:=WindowFromPoint(Pt);</div><div class="code_line">&nbsp;&nbsp;if Wnd &#60;&#62; 0 then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;GetClassName(Wnd,buf,SizeOf(buf));</div><div class="code_line">&nbsp;&nbsp; &nbsp;if buf = &#39;ComboLBox&#39; then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;AdjustHint(Wnd,Pt);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end</div><div class="code_line">&nbsp;&nbsp; &nbsp;else begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;HideHint;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TComboBoxPatch.HideHint;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;FHintWnd.ReleaseHandle;</div><div class="code_line">&nbsp;&nbsp;FHintIndex:=-1;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TComboBoxPatch.SetActive(const Value: Boolean);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;if Value &#60;&#62; FActive then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;FActive:=Value;</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Value then FAppEvnts.OnIdle:=DoIdle else FAppEvnts.OnIdle:=nil;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TComboBoxPatch.ShowHint(Origin: TPoint; Text: String);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;R: TRect;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Application.CancelHint;</div><div class="code_line">&nbsp;&nbsp;R:=FHintWnd.CalcHintRect(1000,Text,nil);</div><div class="code_line">&nbsp;&nbsp;OffsetRect(R,Origin.X,Origin.Y);</div><div class="code_line">&nbsp;&nbsp;FHintWnd.ActivateHint(R,Text);</div><div class="code_line">&nbsp;&nbsp;SetWindowPos(FHintWnd.Handle,HWND_TOPMOST,R.Left,R.Top,FHintWnd.Width,</div><div class="code_line">&nbsp;&nbsp; &nbsp;FHintWnd.Height,SWP_NOACTIVATE);</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">end.</div></ol></div></div></div></div>]]></description>
        <author>--Ins--</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=1882572</guid>
        <pubDate>Wed, 27 Feb 2008 14:22:59 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=1882572</link>
        <description><![CDATA[Megatron: <strong class='tag-b'>Savek</strong> У меня тоже есть этот пример вот только, он почему то глючит когда наводишь курсор на первую длинную строку, то Hint выскакивает за выпадающимся меню  ComboBox, а потом все нормально работает и этот пример работает только с Style: csDropDown, csDropDownList. :(]]></description>
        <author>Megatron</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=1882362</guid>
        <pubDate>Wed, 27 Feb 2008 12:09:58 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=1882362</link>
        <description><![CDATA[Rulikkk: <strong class='tag-b'>Savek</strong>, мне кажется правильнее было бы указать на сайт Delphikingdom, потому что впервые этот класс появился, кажется, там.]]></description>
        <author>Rulikkk</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=1882330</guid>
        <pubDate>Wed, 27 Feb 2008 11:53:23 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=1882330</link>
        <description><![CDATA[Savek: Посмотри в DW5000, там есть готовый проект <br>
<br>
<span class="tag-color tag-color-named" data-value="gray" style="color: gray"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2008-02-27T11:56:41+00:00">27.02.08, 11:56</time></span></span><br>
Собственно вот он:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp;Наследник TComboBox, показывающий Hint для строки в ListBox&#39;овой части,</div><div class="code_line">&nbsp;&nbsp;не видимой целиком.</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;Автор: Игорь Шевченко</div><div class="code_line">&nbsp;&nbsp;Дата создания: 13.04.2002</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;Ограничения:</div><div class="code_line">&nbsp;&nbsp;Компонент проверялся при работе с значением Style: csDropDown, csDropDownList.</div><div class="code_line">&nbsp;&nbsp;при остальных значениях работа не гарантируется :-)</div><div class="code_line">&nbsp;&nbsp;Компонент не тестировался в режиме design-time.</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;История изменений:</div><div class="code_line">&nbsp;&nbsp;16.04.2002 Исправлено поведение при закрытии, когда показан hint и ComboBox</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; закрывается по клавише Enter, Escape или F4. Теперь hint убирается.</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Добавлено свойство HorizontalExtent, позволяющее устанавливать</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; горизонтальный Scrollbar в списке ComboBox&#39;a. По умолчанию свойство</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; имеет значение -1, что запрещает установку горизонтального</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScrollBar&#39;а.</div><div class="code_line">}</div><div class="code_line">unit HSHintComboBox;</div><div class="code_line">&nbsp;</div><div class="code_line">interface</div><div class="code_line">uses</div><div class="code_line">&nbsp;&nbsp;Windows, Messages, Classes, Graphics, Controls, Forms, StdCtrls;</div><div class="code_line">&nbsp;</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;TListBoxTip = class(THintWindow)</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;TShowComboToolTipEvent = procedure (Sender : TObject;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const ToolTipText : String;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var HideToolTip : Boolean) of object;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;THSHintComboBox = class(TComboBox)</div><div class="code_line">&nbsp;&nbsp;private</div><div class="code_line">&nbsp;&nbsp; &nbsp;FListBoxTip : TListBoxTip;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FListHandle : HWND;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FListWndProcInstance : TFarProc;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FOldListWndProc : TFarProc;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FOnListMouseMove: TMouseMoveEvent;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FOnShowComboToolTip: TShowComboToolTipEvent;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FShowToolTips: Boolean;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FHorizontalExtent: Integer;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure ListWndProc (var Message : TMessage);</div><div class="code_line">&nbsp;&nbsp; &nbsp;function ListBoxItemAtPos (I : Integer) : String;</div><div class="code_line">&nbsp;&nbsp; &nbsp;function ListBoxItemRectAtPos (I : Integer; AText : String) : TRect;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure SetShowToolTips(const Value: Boolean);</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure SetHorizontalExtent(const Value: Integer);</div><div class="code_line">&nbsp;&nbsp;protected</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure DoListMouseMove (Shift: TShiftState; X, Y: Integer); dynamic;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure DoShowComboToolTip (const ToolTipText : String;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var HideToolTip : Boolean); dynamic;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure WndProc (var Message: TMessage); override;</div><div class="code_line">{16.04.2002}</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure CreateParams (var Params : TCreateParams); override;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure CreateWnd; override;</div><div class="code_line">{/16.04.2002}</div><div class="code_line">&nbsp;&nbsp;public</div><div class="code_line">&nbsp;&nbsp; &nbsp;constructor Create (AOwner : TComponent); override;</div><div class="code_line">&nbsp;&nbsp; &nbsp;destructor Destroy; override;</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Handle окна ListBox&#39;а, являющегося частью ComboBox&#39;a }</div><div class="code_line">&nbsp;&nbsp; &nbsp;property HSListHandle : HWND read FListHandle;</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Показывать ли Hint для строк, не видимых целиком в ListBox&#39;е }</div><div class="code_line">&nbsp;&nbsp; &nbsp;property ShowToolTips : Boolean read FShowToolTips</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; write SetShowToolTips default true;</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Событие при движении мыши по ListBox&#39;у. Так как ListBox захватывает</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;(Captured) мышь, то координаты курсора в этом событии могут быть за</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;пределами клентской части ListBox&#39;а }</div><div class="code_line">&nbsp;&nbsp; &nbsp;property OnListMouseMove : TMouseMoveEvent read FOnListMouseMove</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;write FOnListMouseMove;</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Событие при показе Hint&#39;а для ListBox&#39;а. Установив HideHint в True,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;можно запретить показ конкретного Hint&#39;а }</div><div class="code_line">&nbsp;&nbsp; &nbsp;property OnShowComboToolTip : TShowComboToolTipEvent</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;read FOnShowComboToolTip write FOnShowComboToolTip;</div><div class="code_line">{16.04.2002}</div><div class="code_line">&nbsp;&nbsp; &nbsp;property HorizontalExtent : Integer read FHorizontalExtent</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; write SetHorizontalExtent default -1;</div><div class="code_line">{/16.04.2002}</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">implementation</div><div class="code_line">uses SysUtils;</div><div class="code_line">&nbsp;</div><div class="code_line">function RectWidth(R : TRect) : Integer;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := R.Right - R.Left;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">function RectHeight(R : TRect) : Integer;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := R.Bottom - R.Top;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">{ THSHintComboBox }</div><div class="code_line">&nbsp;</div><div class="code_line">constructor THSHintComboBox.Create(AOwner: TComponent);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;inherited;</div><div class="code_line">&nbsp;&nbsp;FListBoxTip := TListBoxTip.Create(Self);</div><div class="code_line">&nbsp;&nbsp;FListBoxTip.Color := clInfoBk;</div><div class="code_line">&nbsp;&nbsp;FListWndProcInstance := MakeObjectInstance(ListWndProc);</div><div class="code_line">&nbsp;&nbsp;FShowToolTips := true;</div><div class="code_line">&nbsp;&nbsp;FHorizontalExtent := -1;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">destructor THSHintComboBox.Destroy;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;if (FListHandle &#60;&#62; 0) AND IsWindow(FListHandle) then</div><div class="code_line">&nbsp;&nbsp; &nbsp;SetWindowLong(FListHandle, GWL_WNDPROC, LongInt(FOldListWndProc));</div><div class="code_line">&nbsp;&nbsp;FreeObjectInstance(FListWndProcInstance);</div><div class="code_line">&nbsp;&nbsp;inherited;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure THSHintComboBox.DoShowComboToolTip(const ToolTipText: String;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var HideToolTip : Boolean);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;if Assigned(FOnShowComboToolTip) then</div><div class="code_line">&nbsp;&nbsp; &nbsp;FOnShowComboToolTip (Self, ToolTipText, HideToolTip);</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure THSHintComboBox.DoListMouseMove(Shift: TShiftState; X,</div><div class="code_line">&nbsp;&nbsp;Y: Integer);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;procedure AdjustHintRect (var R : TRect; const AHintStr : String);</div><div class="code_line">&nbsp;&nbsp;var</div><div class="code_line">&nbsp;&nbsp; &nbsp;DC : HDC;</div><div class="code_line">&nbsp;&nbsp; &nbsp;OldFont : HFONT;</div><div class="code_line">&nbsp;&nbsp; &nbsp;TextSize : SIZE;</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;DC := GetDC (HWND_DESKTOP);</div><div class="code_line">&nbsp;&nbsp; &nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;OldFont := SelectObject(DC, Screen.HintFont.Handle);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (NOT GetTextExtentPoint32(DC, PChar(AHintStr), StrLen(PChar(AHintStr)), TextSize)) then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RaiseLastWin32Error;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Inc(TextSize.cx, 6);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Inc(TextSize.cy, 2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if RectWidth(R) &#60; TextSize.cx then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;R.Right := R.Left + TextSize.cx;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if RectHeight(R) &#60; TextSize.cy then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;R.Bottom := R.Top + TextSize.cy;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;finally</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;SelectObject(DC, OldFont);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;finally</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ReleaseDC (HWND_DESKTOP, DC);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">var R, ItemRect : TRect;</div><div class="code_line">&nbsp;&nbsp; &nbsp;I : Integer;</div><div class="code_line">&nbsp;&nbsp; &nbsp;ItemText : String;</div><div class="code_line">&nbsp;&nbsp; &nbsp;HideToolTip : Boolean;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;HideToolTip := True; { По умолчанию выключать Hint }</div><div class="code_line">&nbsp;&nbsp;if FShowToolTips then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;Windows.GetClientRect(FListHandle, R);</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ X и Y являются координатами клиента (в данном случае, ListBox }</div><div class="code_line">&nbsp;&nbsp; &nbsp;if PtInRect(R, Point(X,Y)) AND (Shift = []) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{ Определим, помещается ли текущая строка целиком в область ListBox }</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;I := SendMessage(FListHandle, LB_ITEMFROMPOINT, 0, MakeLParam(X,Y));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if HiWord(I) &#60;&#62; 0 then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;I := -1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if I &#60;&#62; -1 then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ItemText := ListBoxItemAtPos(I);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ItemRect := ListBoxItemRectAtPos(I, ItemText);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if RectWidth(ItemRect) &#62; RectWidth(R) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ Надо показывать Hint, так как строка не помещается целиком</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;в клиентскую область ListBox }</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Windows.ClientToScreen(FListHandle, ItemRect.TopLeft);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Windows.ClientToScreen(FListHandle, ItemRect.BottomRight);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dec(ItemRect.Left, 3);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Inc(ItemRect.Right, 6);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HideToolTip := false; { Не надо гасить hint }</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DoShowComboToolTip (ItemText, HideToolTip); { Для возможности</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; отображения строки Hint дополнительно</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; в другом месте или запрета</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; конкретного Hint&#39;а}</div><div class="code_line">{16.04.2002}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if NOT HideToolTip then</div><div class="code_line">{ Если двигаться мышью в горизонтальном направлении на элементе, для которого</div><div class="code_line">&nbsp;&nbsp;должен показываться Hint, то ActivateHint не стоит вызывать, если Hint уже</div><div class="code_line">&nbsp;&nbsp;уже на экране }</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if NOT (IsWindow(FListBoxTip.Handle) and</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IsWindowVisible(FListBoxTip.Handle) and</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (StrComp(PChar(FListBoxTip.Caption),PChar(ItemText)) = 0)) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AdjustHintRect (ItemRect, ItemText);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FListBoxTip.ActivateHint(ItemRect, ItemText);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">{/16.04.2002}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;if HideToolTip then</div><div class="code_line">&nbsp;&nbsp; &nbsp;FListBoxTip.ReleaseHandle; { Не надо показывать Hint, если мышь за пределами</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListBox или строка видна целиком }</div><div class="code_line">&nbsp;&nbsp;{ Если кому-то вздумается следить за перемещениями мыши в области ListBox.</div><div class="code_line">&nbsp;&nbsp; &nbsp;Я при отладке использовал это событие для отображения координат мыши }</div><div class="code_line">&nbsp;&nbsp;if Assigned(FOnListMouseMove) then</div><div class="code_line">&nbsp;&nbsp; &nbsp;FOnListMouseMove(Self, Shift, X, Y);</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">function THSHintComboBox.ListBoxItemAtPos(I: Integer): String;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;L : Integer;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;if I &#60;&#62; -1 then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;L := SendMessage(FListHandle, LB_GETTEXTLEN, I, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp;SetLength(Result, L+1); { +1 на нулевой символ в конце строки }</div><div class="code_line">&nbsp;&nbsp; &nbsp;SendMessage(FListHandle, LB_GETTEXT, I, Integer(PChar(Result)));</div><div class="code_line">&nbsp;&nbsp;end else</div><div class="code_line">&nbsp;&nbsp; &nbsp;Result := &#39;&#39;;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">function THSHintComboBox.ListBoxItemRectAtPos(I: Integer;</div><div class="code_line">&nbsp;&nbsp;AText: String): TRect;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;DC : HDC;</div><div class="code_line">&nbsp;&nbsp;OldFont : HFONT;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := Rect(0, 0, 0, 0);</div><div class="code_line">&nbsp;&nbsp;if (I &#60;&#62; -1) AND (SendMessage(FListHandle, LB_GETITEMRECT, I,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Integer(@Result)) &#60;&#62; LB_ERR) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;DC := GetDC(FListHandle);</div><div class="code_line">&nbsp;&nbsp; &nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;OldFont := SelectObject(DC, Font.Handle);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;DrawText(DC, PChar(AText), -1, Result, DT_CALCRECT);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;finally</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;SelectObject(DC, OldFont);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;finally</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ReleaseDC(FListHandle, DC);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure THSHintComboBox.ListWndProc(var Message: TMessage);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;case Message.Msg of</div><div class="code_line">&nbsp;&nbsp;WM_MOUSEMOVE:</div><div class="code_line">&nbsp;&nbsp; &nbsp;with TWMMouseMove(Message) do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;DoListMouseMove(KeysToShiftState(Keys), XPos, YPos);</div><div class="code_line">{16.04.2002}</div><div class="code_line">{ Как выяснилось, при нажатии Esc или Enter на выбранном элементе, который</div><div class="code_line">&nbsp;&nbsp;показывает Hint, ComboBox закрывается, а Hint остается. :-(</div><div class="code_line">&nbsp;&nbsp;Сообщение SHOWWINDOW с WPARAM=0 гарантировано выдается, когда закрывается</div><div class="code_line">&nbsp;&nbsp;окно, так что это место можно использовать для гашения Hint&#39;a }</div><div class="code_line">&nbsp;&nbsp;WM_SHOWWINDOW:</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Message.WParam = 0 then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;FListBoxTip.ReleaseHandle();</div><div class="code_line">{/16.04.2002}</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;with Message do</div><div class="code_line">&nbsp;&nbsp; &nbsp;Result := CallWindowProc(FOldListWndProc, FListHandle, Msg, WParam, LParam);</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure THSHintComboBox.SetShowToolTips(const Value: Boolean);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;FShowToolTips := Value;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure THSHintComboBox.WndProc(var Message: TMessage);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;if (Message.Msg = WM_CTLCOLORLISTBOX) AND (FListHandle = 0) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;FListHandle := HWND(Message.LParam);</div><div class="code_line">&nbsp;&nbsp; &nbsp;FOldListWndProc := Pointer(GetWindowLong(FListHandle, GWL_WNDPROC));</div><div class="code_line">&nbsp;&nbsp; &nbsp;SetWindowLong(FListHandle,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GWL_WNDPROC, LongInt(FListWndProcInstance));</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;inherited;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">{16.04.2002}</div><div class="code_line">procedure THSHintComboBox.CreateParams(var Params: TCreateParams);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;inherited;</div><div class="code_line">&nbsp;&nbsp;if FHorizontalExtent &#60;&#62; -1 then</div><div class="code_line">&nbsp;&nbsp; &nbsp;with Params do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Style := Style OR WS_HSCROLL;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure THSHintComboBox.SetHorizontalExtent(const Value: Integer);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;if (FHorizontalExtent &#60;&#62; Value) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;FHorizontalExtent := Value;</div><div class="code_line">&nbsp;&nbsp; &nbsp;if NOT (csLoading in ComponentState) then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;RecreateWnd();</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure THSHintComboBox.CreateWnd;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;inherited;</div><div class="code_line">&nbsp;&nbsp;if FHorizontalExtent &#60;&#62; -1 then</div><div class="code_line">&nbsp;&nbsp; &nbsp;Perform(CB_SETHORIZONTALEXTENT, FHorizontalExtent, 0);</div><div class="code_line">end;</div><div class="code_line">{/16.04.2002}</div><div class="code_line">&nbsp;</div><div class="code_line">end.</div></ol></div></div></div></div>]]></description>
        <author>Savek</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=1881550</guid>
        <pubDate>Tue, 26 Feb 2008 17:31:42 +0000</pubDate>
        <title>Hint в ComboBox</title>
        <link>https://forum.sources.ru/index.php?showtopic=225259&amp;view=findpost&amp;p=1881550</link>
        <description><![CDATA[Megatron: Вот вчера столкнулся с проблемой вывода подсказок для ComboBox если в него строка не влазит.<br>
Почитав советы по Delphi понял что ничего непонял :no:  Попробовал написать как описано ничего не получилось плюнул на все и забил.<br>
Но всеже... вот пример с этих советов:<br>
<br>
В своем компоненте объявите FTipHint:<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">type</div><div class="code_line">TVSComboBox = class(TCustomComboBox)</div><div class="code_line">…</div><div class="code_line">private</div><div class="code_line">FHint: THintWindow;</div><div class="code_line">…</div><div class="code_line">protected</div><div class="code_line">procedure WMCTLCOLORLISTBOX(var Message: TMessage); message WM_CTLCOLORLISTBOX;</div></ol></div></div></div></div> <br>
<br>
и не забудьте выполнить инициализацию в конструкторе вашего компонента:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">begin</div><div class="code_line">inherited Create(AOwner);</div><div class="code_line">FHint := THintWindow.Create(Self);</div></ol></div></div></div></div>    <br>
<br>
Чтобы получить информацию об активной строке в выпадающем списке ComboBox перехватите сообщение WM_CTLCOLORLISTBOX. В процедуре сообщения анализируйте - если длина строки больше ширины выпадающего списка – передайте &quot;длинную&quot; строку в ваш Hint и активируйте его:<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">FHint.ActivateHint(TextRC, Items[ItemIndex]);</div></ol></div></div></div></div>     <br>
<br>
где<br>
TextRC – прямоугольник для строки подсказки<br>
Items[ItemIndex] – &quot;длинная&quot; строка из выпадающего списка<br>
<br>
Если активная строка в выпадающем списке &quot;короткая&quot; – спрячьте Hint:<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">FHint.ReleaseHandle;</div></ol></div></div></div></div>    <br>
<br>
Если знаете то приведите пожалуйста небольшой пример как это все воплотить и как его правильно написать, а то я немогу въехать в слова автора  &quot;В своем компоненте объявите FTipHint:&quot; а про компонент FTipHint: ни слова и вообще накидано по кусках а разобраться и сложить все в кучу не получается :wall: <br>
<br>
Заранее спасибо.]]></description>
        <author>Megatron</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      </channel>
      </rss>
	