tags:

views:

576

answers:

2

Hi, I am using SetWindowPos() to try and send Windows to back/front of the z-order. It seems to work for the most part however I am noticing for certain windows it just won't work although the function will return success.

For example Window Task Manager seems to work perfectly fine but the other windows aren't responding properly to the function call.

Any insights into what may be happening? I know the information is sparse however I am not sure what to include.

+1  A: 

Pretty much seems to work using SetForegroundWindow. From what I could discern it seems that using SetWindowPos and setting a window to HWND_TOP will make it top of the z-order following the foreground window. Meaning that once the foreground window is removed (minimized/closed) it will then be the next one at the TOP.

Setheron
I'd like to add that it wasn't enough to call SetForegroundWindow.Consider the case where the window is the ForegroundWindow however I had manually set the window to the back of the Z-order. Calling ForegroundWindow again does not bring it to the top of the z-order. Therefore two calls must be made1) SetForeGroundWindow (or a check first if the window is foregroundwindow)2) SetWindowPos(new IntPtr(windowID), HWND_TOP, 0, 0, 0, 0, (SWP_NOSIZE | SWP_NOMOVE));
Setheron
A: 

I too have hod problems with this across processes. This from the MS documentation:

To use SetWindowPos to bring a window to the top, the process that owns the window must have SetForegroundWindow permission.

might be the cause?

Elemental