7

I've got a component I created that embeds a hardware-accelerated renderer in a TWinControl so you can place it on a form. It works pretty well in most cases, but if I try to resize the control, everything goes blank until the message loop runs and calls the WndProc for the renderer, which is hosted in an external DLL. This means that I need to call Application.ProcessMessages explicitly after I've resized the control in code, which I know is considered bad practice.

Is there any way to put some logic in the control itself to make it invoke the WndProc in the DLL when I change the control's size, so I won't need to call ProcessMessages to get stuff to render right?

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477

2 Answers2

11

You could call TWinControl.Update instead, which should just SendMessage a WM_PAINT event, so you aren't handling arbitrary messages.

Zoë Peterson
  • 13,094
  • 2
  • 44
  • 64
4

The correct solution is to call InvalidateRect when you resize. Windows will then post you a WM_PAINT message. For reference you should pull Petzold off the shelf and read his chapter on painting.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 2
    What's more, if you system settings are not to re-draw windows whilst resizing then you won't get the WM_PAINT until the re-size operation is complete. – David Heffernan Nov 25 '10 at 21:33