Is it possible to somehow get a modification region (updated region of the specified window) in the descendant of TWinControl in WM_PAINT processing?

I tried to call the GetUpdateRect function, but in TWinControl.PaintHandler by this moment BeginPaint is already called and the modification area is being validated, therefore GetUpdateRect returns an empty rectangle. And the type variable TPaintStruct is local for TWinControl.PaintHandler and there is no access to it.

  • one
    just declare a WM_PAINT handler (with a call to inherited after your manipulations with GetUpdateRect) - kami
  • Thank! I'll try it - Mike
  • Thank! Everything worked out! - Mike

1 answer 1

To enable your handler for any Windows message (other than the “regular” one found in the VCL source), you just need to declare it. For example:

TmyForm = class(TForm) private procedure WMPaint(var Message: TWMPaint); message WM_PAINT; ... 

The main thing - do not forget to call the regular handler through Inherited. In your case, you really need to call the regular after executing your code, since otherwise, you cannot get the updated region:

 procedure TmyForm.WMPaint(var Message: TMessage); message WM_Paint; begin // вызываем GetUpdateRect, проводим дополнительные манипуляции inherited; // штатный обработчик // Здесь тоже можно проводить манипуляции, но GetUpdateRect уже вернет "пусто". end;