{"id":788,"date":"2008-05-27T10:17:05","date_gmt":"2008-05-27T10:17:05","guid":{"rendered":"http:\/\/6teen.ru\/?p=642"},"modified":"2008-05-27T10:17:05","modified_gmt":"2008-05-27T10:17:05","slug":"7476","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=788","title":{"rendered":"\u041f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 TListBox"},"content":{"rendered":"<p>\u041f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 TListBox<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>\u041f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 TListBox\n\nunit TransparentListBox;\n\n (*\n  *\n  *  Written by Walter Irion (CIS 114254, 2455) after the THotSpot\n  *  sample component that Arne Sch?pers presented in the German\n  *  c''t magazine (issue 6\/1996, pp. 286 ff.).\n  *\n  *  TTransparentListBox is far from being a universal solution:\n  *  it does not prevent Windows'' scrolling mechanism from\n  *  shifting the background along with scrolled listbox lines.\n  *  Moreover, the scroll bar remains hidden until the keyboard\n  *  is used to change the selection, and the scroll buttons\n  *  become visible only when clicked.\n  *\n  *  To break it short: TTransparentListBox is only suitable\n  *  for non-scrolling lists.\n  *\n  *  In fact it must be possible to write a listbox component\n  *  that handles scrolling correctly. But my essays to intercept\n  *  EM_LINESCROLL messages were fruitles, even though I tried\n  *  subclassing via WndProc.\n  *\n  *  A solution for transparent TEdit and TMemo controls is\n  *  introduced in issue 9\/1996 of the c''t magazine, again\n  *  by Arne Sch?pers. But these are outright monsters with\n  *  wrapper windows to receive notification messages as well\n  *  as so-called pane windows that cover the actual control''s\n  *  client area and display its content.\n  *\n  *  Previous issues of the c''t magazine can be ordered from:\n  *\n  *    c''t-Kopierservice\n  *    Helstorfer Str. 7\n  *    30625 Hannover, Germany\n  *\n  *  They expect a crossed cheque amounting to DM 14,00\n  *  to be included with your order, but I don''t know about\n  *  international orders.\n  *\n  *)\n\n interface\n\n uses\n   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,\n   StdCtrls;\n\n type\n   TTransparentListBox = class(TListBox)\n   private\n     { Private declarations }\n   protected\n     { Protected declarations }\n     procedure CreateParams(var Params: TCreateParams); override;\n     procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;\n     procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);\n       override;\n   public\n     { Public declarations }\n     constructor Create(AOwner: TComponent); override;\n     procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;\n   published\n     { Published declarations }\n     property Style default lbOwnerDrawFixed;\n     property Ctl3D default False;\n     property BorderStyle default bsNone;\n   end;\n\n procedure Register;\n\n implementation\n\n constructor TTransparentListBox.Create(AOwner: TComponent);\n begin\n   inherited Create(AOwner);\n   Ctl3D       := False;\n   BorderStyle := bsNone;\n   Style       := lbOwnerDrawFixed;  \/\/ changing it to lbStandard results\n  \/\/ in loss of transparency\nend;\n\n procedure TTransparentListBox.CreateParams(var Params: TCreateParams);\n begin\n   inherited CreateParams(Params);\n   Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT;\n end;\n\n procedure TTransparentListBox.WMEraseBkgnd(var Msg: TWMEraseBkgnd);\n begin\n   Msg.Result := 1;           \/\/ Prevent background from getting erased\nend;\n\n procedure TTransparentListBox.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);\n var\n   tlbVisible: Boolean;\n begin\n   tlbVisible := (Parent <> nil) and IsWindowVisible(Handle);  \/\/ Check for\n  visibility\n   if tlbVisible then ShowWindow(Handle, SW_HIDE);             \/\/ Hide-Move-Show\n  strategy...inherited SetBounds(ALeft, ATop, AWidth, AHeight);          \/\/ ... to prevent\n  background...if tlbVisible then ShowWindow(Handle, SW_SHOW);             \/\/ ... from\n  getting copied\n end;\n\n procedure TTransparentListBox.DrawItem(Index: Integer; Rect: TRect;\n   State: TOwnerDrawState);\n var\n   FoundStyle: TBrushStyle;\n   R: TRect;\n begin\n   FoundStyle := Canvas.Brush.Style;       \/\/ Remember the brush style\n\n  R := Rect;                                     \/\/ Adapt coordinates of drawing\n  rect...MapWindowPoints(Handle, Parent.Handle, R, 2);  \/\/ ... to parent''s coordinate\n  system\n   InvalidateRect(Parent.Handle, @R, True);   \/\/ Tell parent to redraw the\n  item Position\n   Parent.Update;                             \/\/ Trigger instant redraw\n  (required)\n\n   if not (odSelected in State) then\n   begin  \/\/ If an unselected line is being\n    handled\n     Canvas.Brush.Style := bsClear;  \/\/   use a transparent background\n  end\n   else\n   begin                          \/\/ otherwise, if the line needs to be\n    highlighted,\n     Canvas.Brush.Style := bsSolid;  \/\/   some colour to the brush is\n    essential\n   end;\n\n   inherited DrawItem(Index, Rect, State); \/\/ Do the regular drawing and give\n  component users...\n   \/\/ ... a chance to provide an\n  OnDrawItem handler\n\n   Canvas.Brush.Style := FoundStyle;  \/\/ Boy-scout rule No. 1: leave site as\n  you found it\n end;\n\n procedure Register;\n begin\n   RegisterComponents('Samples', [TTransparentListBox]);\n end;\n\n end.\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 TListBox<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[413,386],"tags":[582,1631],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/788"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=788"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/788\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=788"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}