Solved

Problem with Transparent TMemo

Posted on 2010-11-11
1
594 Views
Last Modified: 2016-08-27
I'm having trouble with this component, it won't let me change its Font.Color and when I write some lines to it, it will look ugly, like in the picture I attached, how can I avoid this ?


unit TrMemo;

{$R-}

interface

uses Messages,
     Controls,
     StdCtrls,
     Classes;

const
  TMWM__SpecialInvalidate = WM_USER + 1111;

type
  TTransparentMemo = class(TMemo)
  private
    procedure SpecialInvalidate(var Message: TMessage); message TMWM__SpecialInvalidate;
    procedure WMHScroll(var Message: TWMHScroll); message WM_HSCROLL;
    procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
    procedure WMSetText(var Message: TWMSetText); message WM_SETTEXT;
    procedure CNCTLCOLOREDIT(var Message: TWMCTLCOLOREDIT); message CN_CTLCOLOREDIT;
    procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
    procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  public
    constructor Create(AOwner: TComponent); override;
  end;

procedure Register;

implementation

uses Windows;

{ TTransparentMemo }

procedure TTransparentMemo.WMHScroll(var Message: TWMHScroll);
begin
  inherited;
  PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTransparentMemo.WMVScroll(var Message: TWMVScroll);
begin
  SendMessage(Handle,TMWM__SpecialInvalidate, 0, 0);
  inherited;
  PostMessage(Handle,TMWM__SpecialInvalidate, 0, 0);
end;

procedure TTransparentMemo.CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT);
begin
  with Message do
    begin
      SetBkMode(ChildDC,TRANSPARENT);
      Result:=GetStockObject(HOLLOW_BRUSH)
    end
end;

procedure TTransparentMemo.WMSetText(var Message:TWMSetText);
begin
  inherited;
  if not (csDesigning in ComponentState) then
    PostMessage(Handle, TMWM__SpecialInvalidate, 0, 0)
end;

procedure TTransparentMemo.SpecialInvalidate(var Message: TMessage);
var
  r : TRect;
begin
  if Parent <> nil then
    begin
      r := ClientRect;
      r.TopLeft := Parent.ScreenToClient(ClientToScreen(r.TopLeft));
      r.BottomRight := Parent.ScreenToClient(ClientToScreen(r.BottomRight));
      InvalidateRect(Parent.Handle, @r, true);
      RedrawWindow(Handle, nil, 0, RDW_FRAME + RDW_INVALIDATE)
    end;
end;

procedure TTransparentMemo.WMKeyDown(var Message: TWMKeyDown);
begin
  SendMessage(Handle,TMWM__SpecialInvalidate,0,0);
  inherited;
  PostMessage(Handle,TMWM__SpecialInvalidate,0,0);
end;

procedure TTransparentMemo.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  Message.Result := 1;
end;

constructor TTransparentMemo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csCaptureMouse, csDesignInteractive,
                 csClickEvents, csSetCaption, csOpaque,
                 csDoubleClicks, csReplicatable, csNoStdEvents];
end;

procedure TTransparentMemo.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
  begin
    ExStyle :=
    ExStyle or WS_EX_TRANSPARENT
       and not WS_EX_STATICEDGE
       and not WS_EX_DLGMODALFRAME
       and not WS_EX_WINDOWEDGE
       and not WS_EX_CLIENTEDGE;
  end;
end;

procedure Register;
begin
  RegisterComponents('Custom', [tTransparentMemo]);
end;

end.

Open in new window

Untitled.png
0
Comment
Question by:rotem156
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 34110609
An alternative (if not better it is the same) you can use TRichEdit and put the following at the Form OnCreate:

Richedit1.Brush.Style:=BsClear;
SetWindowLong(Form1.Richedit1.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT);


From:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20885497.html
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question