0

Using C++ Builder 10.2, VCL & VCL Styles...

I have a TPageControl that has TFrames on each of its TTabsheets. One of these frames contains some TEdit controls that show data read from a device. After the reading is acquired and the frame is updated, the system may create a screenshot of this frame and store it in a jpeg file.

Since the TTabsheet in the TPageControl with the TEdit controls may not be visible when the jpeg is created, the jpeg may not have the text contents of the TEdit controls painted. This has given me fits.

I have found that by using a TStaticText that is styled, the text appears in the jpeg. This seems to be due to the fact that TStaticTextStyleHook.Paint (in VCL.StdCtrls.pas) draws the control itself rather than letting Windows do it.

There are two problems with using TStaticText. Selecting the SystemStyle choice (Windows) causes TStaticTextStyleHook.Paint to skip painting the control itself and delegates to Windows (I think). Also, the appearance of TStaticText isn't exactly what I want, but I may have to live with it.

Is Windows refusing to paint TEdit control contents because the parent is not Visible?

Is there a way to force Windows to paint the TEdit controls in this situation?

UpdateWindow() and RedrawWindow() does not work.

Victoria
  • 7,822
  • 2
  • 21
  • 44
outerlimits
  • 76
  • 1
  • 5
  • Windows does not update controls that are not visible, as it's a waste of CPU cycles to do so. (Why waste time drawing something that can't be seen and therefore has no reason to be drawn?) – Ken White Jun 16 '17 at 14:36
  • As @Ken says. Hence MS came up with the `WM_PRINT` message. It's an explicit request to a window to paint its content to a given canvas even when it's not currently visible. – Victoria Jun 16 '17 at 17:56
  • @Victoria: But it only works if the window handles the message, which not all controls do. I've not looked to see if TEdit does. – Ken White Jun 16 '17 at 17:59
  • @Ken, a friend of mine gave me an access to Delphi 7 source code (have no Delphi by hand) and it seems that `PaintTo` method should do what is needed here (cannot say how much it's been modified since that time or how style hooks act in favor of that method). – Victoria Jun 16 '17 at 22:50
  • Thanks for the responses. I have tried PaintTo(), but it does not paint the contents of TEdit controls on my panel: PnlJpeg->PaintTo(bmp->Canvas, 0, 0); I also tried WM_PRINT and WM_PRINTCLIENT but none of the panel is painted. Still investigating. – outerlimits Jun 17 '17 at 11:58
  • `PaintTo` if not changed since Delphi 7 passes `WM_PAINT` message directly to the window proc (but handling of that message may later eliminate painting because the parent is not visible to the user, but that's what I cannot confirm). `WM_PRINT` is what should be used here, but I'm afraid that VCL doesn't handle it correctly. – Victoria Jun 17 '17 at 13:02

0 Answers0