This example shows how an application can incrementally repaint an asynchronous-paint window one area at a time. While a window is invalid (has a non-null update region), WM_PAINT messages are returned by WinGetMsg. The application uses WinQueryUpdateRegion to obtain a region that requires repainting, and WinValidateRegion to validate the region (reset the update region to null).
#define INCL_WINWINDOWMGR #define INCL_GPIREGIONS #include <OS2.H> HRGN hrgnUpdt, sRgnType; HPS hpsPaint; HWND hwnd; /* Window needs paint */ case WM_PAINT: /* assume we stop any asynchronous drawing. */ /* by posting a message to the asynchronous */ /* drawing thread. */ hrgnUpdt = (HRGN)GpiCreateRegion(hpsPaint, (ULONG)0, (PRECTL)NULL); sRgnType = (HRGN)WinQueryUpdateRegion(hwnd, hrgnUpdt); /* if the region is not null and the call is not in error, */ /* validate the region. */ if ((sRgnType != NULL) && (sRgnType != RGN_ERROR)) { WinValidateRegion(hwnd, hrgnUpdt, FALSE); /* here we would send the update region handle to an asynchronous drawing thread. We have already validated the region, so no more WM_PAINT messages will be sent due to this region. */ } else { GpiDestroyRegion(hpsPaint, hrgnUpdt);}