Cancel DeferWindowPos

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.

+4
source share
2 answers

The only link to any abort function that I see is this:

If any of the windows in the structure with several windows have SWP_HIDEWINDOW or the SWP_SHOWWINDOW flag is set, none of the windows are moved.

It comes from here .

0
source

"If this is not possible, I simply accumulate them in a temporary vector and call in Defer at the end when I'm sure I want to do them all."

That would be the right decision. . What is your argument for indecision regarding which windows will move between BeginDeferWindowPos , DeferWindowPos and EndDeferWindowPos ? This seems to be more related to the problem of streaming, which you can solve using the appropriate lock.

Arkadiy's answer does not cancel anything. As far as I understand the Win32 documentation , you simply cannot combine show / hide operations with repositioning operations. In other words, you do not cancel the operation , show / hide operations simply take precedence, and those that will be executed.

I encapsulated showing / hiding and moving in a managed library: Extension of the Framework Extension Library .

The specific RepositionWindows() function is located in Whathecode.System.Windows.WindowManager , and it takes care to show / hide and move.

 /// <summary> /// Reposition a set of windows in one operation. /// TODO: Handle any scenarios where repositioning windows fails. /// </summary> /// <param name="toPosition">The windows to reposition.</param> /// <param name="changeZOrder"> /// When true, the windows Z orders are changed to reflect the order of the toPosition list. /// The first item in the list will appear at the top, while the last item will appear at the bottom. /// </param> public static void RepositionWindows( List<RepositionWindowInfo> toPosition, bool changeZOrder = false ) { bool changeVisibility = toPosition.Any( w => w.HasVisibilityChanged() ); if ( changeVisibility ) { RepositionWindows( toPosition, false, true ); } RepositionWindows( toPosition, changeZOrder, false ); } 
0
source

All Articles