I am doing a series of window resizing using the DeferWindowPos function. Suppose I already opened the DeferWindowPos handle and called DeferWindowPos several times, and now I want to undo everything: do not call EndDeferWindowPos. I tried CloseHandle (hDWP), but it does not work (crash). If I just return from my function, I assume that this will lead to a handle leak. Is it possible to disable DeferWindowPos without calling EndDeferWindowPos?
// Initialize HDWP hDWP = BeginDeferWindowPos( ... ) for( ... ) { // Calculate new rectangle CRect dcNew; ... // Oh,now I want to return from my function, I want to cancel everything // Accumulate hDWP = DeferWindowPos( hDWP, hWnd, 0, rcNew.left, rcNew.top, rcNew.Width(), rcNew.Height(), SWP_NOZORDER ); } // Finally BOOL bResult = EndDeferWindowPos( hDWP );
If this is not possible, I simply accumulate them in a temporary vector and call Defer things at the end when I'm sure I want to do them all.
source share