Board index » cppbuilder » Gray Selection in a TMemo ???

Gray Selection in a TMemo ???

Hi there

Is it in any way possible to make the selection in
a TMemo get gray when the TMemo loose the focus,
like the behaviour of a TListView and TTreeView.

Thanks in advance
Asger

 

Re:Gray Selection in a TMemo ???


Like TListView and TTreeView, TMemo also has a HideSelection property for
that.  Just set it to false.

Gambit

Quote
"Asger J?rgensen" <Asger.Pnott...@AJ-World.dk> wrote in message

news:MPG.18218eb414193995989693@newsgroups.borland.com...
Quote
> Is it in any way possible to make the selection in
> a TMemo get gray when the TMemo loose the focus,
> like the behaviour of a TListView and TTreeView.

Re:Gray Selection in a TMemo ???


Hi "Remy

  In article <3db774c...@newsgroups.borland.com>,  "Remy Lebeau \(TeamB\)"
<gambi...@yahoo.com> says :

Quote
> Like TListView and TTreeView, TMemo also has a HideSelection property for
> that.  Just set it to false.

Thanks!
Yea that hide the selection alright, but that's not what i asked
for if You check the TListView and TTreeView it will make a
gray selection when HideSelection = false and it looses focus.
In other word it is possible to see that the control dont have
the focus and it is also possible to see what is selected.

Anny other suggestions ??

Thanks in advance
Asger

Re:Gray Selection in a TMemo ???


Quote
Asger J?rgensen <Asger.Pnott...@AJ-World.dk> wrote:
>Yea that hide the selection alright, but that's not what i
>asked for if You check the TListView and TTreeView it will
>make a gray selection when HideSelection = false and it looses
>focus. In other word it is possible to see that the control
>dont have the focus and it is also possible to see what is
>selected.

>Anny other suggestions ??

TMemo doesn't provide this functionality. You can however write
a derived class doing that. Here is the code. Enjoy.

class TMyMemo : public TMemo
{
public:
__fastcall TMyMemo(TComponent *AOwner);
void __fastcall WMPaint(TMessage &Msg);
void __fastcall WMSetFocus(TMessage &Msg);
void __fastcall WMKillFocus(TMessage &Msg);
BEGIN_MESSAGE_MAP
    MESSAGE_HANDLER(WM_PAINT, TMessage, WMPaint)
    MESSAGE_HANDLER(WM_SETFOCUS, TMessage, WMSetFocus)
    MESSAGE_HANDLER(WM_KILLFOCUS, TMessage, WMKillFocus)
END_MESSAGE_MAP(TMemo)

Quote
};

__fastcall TMyMemo::TMyMemo(TComponent *AOwner):
TMemo(AOwner)
    {
    }

void __fastcall TMyMemo::WMPaint(TMessage &Msg)
{
// first let the original painting be done
TMemo::Dispatch(&Msg);

// then replace the selection color
HDC dc = GetDC(this->Handle);
for(int x = 0 ; x < Width - Left; x++)
  for(int y = 0 ; y < Height - Top; y++)
    if(GetFocus() == Handle)
      {
      if(GetPixel(dc, x, y) == GetSysColor(COLOR_GRAYTEXT))
        SetPixel(dc, x, y, GetSysColor(COLOR_HIGHLIGHT));
      }
    else
      if(GetPixel(dc, x, y) == GetSysColor(COLOR_HIGHLIGHT))
        SetPixel(dc, x, y, GetSysColor(COLOR_GRAYTEXT));

Quote
}

void __fastcall TMyMemo::WMKillFocus(TMessage &Msg)
{
// repaint when focus gets lost
Invalidate();
TMemo::Dispatch(&Msg);

Quote
}

void __fastcall TMyMemo::WMSetFocus(TMessage &Msg)
{
// repaint when object gets focus
Invalidate();
TMemo::Dispatch(&Msg);

Quote
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TMyMemo* MyMemo = new TMyMemo(this);
MyMemo->HideSelection = false;
MyMemo->Parent = this;
Quote
}

Other Threads