function BeginScene(AClipRects: PClipRects = nil; AContextHandle: THandle = 0): Boolean;
bool __fastcall BeginScene(PClipRects AClipRects = (PClipRects)(0x0), NativeUInt AContextHandle = (NativeUInt)(0x0));
Notifies the TCanvas object that the drawing can begin.
To end the drawing session, call EndScene.
if Canvas.BeginScene then try Canvas.xxx //drawing image operations ... finally Canvas.EndScene; end;
Each time the TCanvas object calls BeginScene and BeginScene returns True, the value of the BeginSceneCount property is increased by one. Each time the TCanvas object calls EndScene, the value of the BeginSceneCount property is decreased by one. BeginScene uses BeginSceneCount to guaranty that the TCanvas object has no more than one initialized drawing at any moment.
- Tip: Notice that calling BeginScene in the OnPaint event handlers has no effect, because BeginScene is called before the OnPaint event handler runs. This guarantees that painting always occurs in OnPaint without requiring extra and probably unexpected code to allow drawing to have an effect.
TCanvasand all subclasses have support for multi-threaded environments, but does not support simultaneous execution of Canvas instances. This means that when a Canvas calls
BeginScene, the execution of the code inside this
BeginScene...EndScenesection blocks any other thread that attempts to process drawing, including drawing on other canvases. Write
BeginScene...EndSceneblocks as short as possible to avoid blocking other threads.