The simplest way for a control to redraw the screen is by invalidating the relevant region with IASForm::Invalidate or IASForm::InvalidateAll. If a control needs more flexible and efficient drawing capability, it must obtain a pointer to an IFMDraw interface from its form. This interface provides access to the device context, along with a number of related methods.
Only a control with its form is in the foreground can create a drawing that appears on the screen. If a form is not in the foreground, any attempt to draw to the screen is ignored and drawing is rendered to a default bitmap associated with the device context. Although the code executes properly, the image does not appear on the screen.
To draw, a control must have a device context. When all or part of a form is repainted, the form obtains the device context. It then passes the device context to a control when it invokes the control’s IASControl::Draw method. A control can obtain a device context directly by obtaining a pointer to an IFMDraw interface and invoking the IFMDraw::GetDC method.
If a control has invoked IFMDraw::GetDC, it should release it when it is finished by invoking IFMDraw::ReleaseDC.
When a control’s IASControl::Draw method is invoked by a form, it should update its screen image. When the DeferDraw property is set to TRUE, no redrawing can take place. When it is set to FALSE, the screen updates immediately. In the case of a form, drawing is deferred for all controls on the form. This permits an application to complete all drawing before updating the screen. This approach is much faster than repeatedly updating the screen as individual elements are redrawn.
The coordinates of an Auto PC control are defined relative to the x- and y-coordinates of its form, not the screen coordinates. A control’s screen size is defined by its Top, Left, Height, and Width properties. A control with its Top and Left properties both set to 0 is drawn in the upper-left corner of the form. The on-screen location of the control depends on the location of the form.
Note Every IFMDraw::GetDC method must be matched by an IFMDraw::ReleaseDC method. If the device context is not released, subsequent calls to IFMDraw::GetDC will fail.
Blitting images to the screen requires an IFMDraw pointer. Drawing is rendered to the system’s off-screen bitmap. To transfer the contents of the bitmap to the screen, a control invokes IFMDraw::Commit. To blit to only a portion of the screen, define a clipping rectangle and invoke IFMDraw::ClipAndCommit. To blit only a portion of the bitmap, use IASCanvas::CommitFrom or IASCanvas::CommitAt.
Note The IFMDraw and IASCanvas methods succeed only if the form has focus. If it does not, no errors are generated, but nothing appears on the screen.