Controlling
the repainting of a Form
In general, you can specify the order of
the repainting of a control if you explicitly handle the WM_PAINT message
sent by Windows. You can handle the WM_PAINT message by augmenting
the virtual Dispatch method via the BEGIN_MESSAGE_MAP, END_MESSAGE_MAP
macros.
KEYWORDS: WM_PAINT
|
//in
header...
public:
void __fastcall OrderedRePaint(TMessage &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_PAINT, TMessage, OrderedRePaint)
END_MESSAGE_MAP(TForm)
|
//---------------------------------------------------------------------------
//in
Form's source...
void __fastcall
TForm1::OrderedRePaint(TMessage &Msg)
{
TForm::Dispatch(&Msg);
//
Let everything else draw first
//
Finally draw your stuff
}
|
There are some caveats in doing this. Most importantly, you don't
want to do anything in the message handler that will cause another WM_PAINT
message to be sent. This will cause a Stack Overflow (recursion).
|