Board index » cppbuilder » TPaintBox Help Needed

TPaintBox Help Needed

Does a TPaintBox get WM_ERASEBKGND messages?
I have subclassed the windows procedure of one in my form
and set a breakpoint for it, but I can't seem to do anything
to generate a WM_ERASEBKGND.  I know my subclassing
is working though because I can break on the default WndProc.

Thanks,

Jim Wheeler

 

Re:TPaintBox Help Needed


Hi James,

Quote
> Does a TPaintBox get WM_ERASEBKGND messages?
> I have subclassed the windows procedure of one in my form
> and set a breakpoint for it, but I can't seem to do anything
> to generate a WM_ERASEBKGND.  I know my subclassing
> is working though because I can break on the default WndProc.

You can subclass any TControl descendant, but unless it derives from TWinControl
or is explicitly sent a WM_* message by the Perform() method, it will not
receive Windows messages, only CM_* / CN_* component messages.  What you need to
do is subclass the Parent of the PaintBox.  For example, if the PaintBox is
placed in a TScrollBox, then you'd do the following...

//in header...
    Controls::TWndMethod OldScrollBoxWP;
    void __fastcall NewScrollBoxWP(TMessage &Msg);

//in source...
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    OldScrollBoxWP = ScrollBox1->WindowProc;
    ScrollBox1->WindowProc = NewScrollBoxWP;

Quote
}

void __fastcall TForm1::NewScrollBoxWP(TMessage &Msg)
{
    if (Msg.Msg == WM_ERASEBKGND)
    {
        Msg.Result = 0;
        return;
    }
    OldScrollBoxWP(Msg);

Quote
}

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
    ScrollBox1->WindowProc = OldScrollBoxWP;

Quote
}

Hope this helps!

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>

Other Threads