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)
__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));
void __fastcall TMyMemo::WMKillFocus(TMessage &Msg)
{
// repaint when focus gets lost
Invalidate();
TMemo::Dispatch(&Msg);
void __fastcall TMyMemo::WMSetFocus(TMessage &Msg)
{
// repaint when object gets focus
Invalidate();
TMemo::Dispatch(&Msg);
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TMyMemo* MyMemo = new TMyMemo(this);
MyMemo->HideSelection = false;
MyMemo->Parent = this;