Click here to Skip to main content
14,325,352 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello! I have an application on Vista which loops through all processes and finds associated main windows in order to move and resize them.

The problem is that some windows get moved and resized and some don't. Also it even seems that moved and resized windows aren't moved and resized according to the MoveWindow function call because they are resized to title bar and all of them are on the same line (same y coordinate).

Here's the sample code:

IntPtr handle;
Process[] processList = Process.GetProcesses();

int i = 0;
foreach (Process process in processList)
{
     handle = process.MainWindowHandle;

     if (handle != IntPtr.Zero)
     {
          MoveWindow(handle, i * 50, i * 50, 500, 500, true);
          i++;
     }
}

Is this because of Vista? What alternative should I use?
Posted
Updated 8-May-10 2:18am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try the SetWindowPos windows api function (you'll need pinvoke for that), and it looks like it takes many of the same parameters.
   
Comments
dex.ilic 11-May-10 10:20am
   
I have added this line of code instead of MoveWindow:
SetWindowPos(this.Handle, HWND_TOPMOST, 400, 400, 800, 800, SWP_SHOWWINDOW);
This command made my application top most but did not resize it to 800x800pixels, nor did put it on x=400, y=400 location, but x=400, y=0 (no matter what I put y is always zero). Needless to say that this line of code didn't work for other applications but only for the process owner. Please help! I am running this code on Vista.
Rate this:
Please Sign up or sign in to vote.

Solution 2

It seems that MoveWindow function doesn't have any effect on the minimized windows. So, before MoveWindow I used ShowWindow:

ShowWindow(handle, 3); //ShowMaximized = 3

This helped!

I used SetWindowPos function but MSDN documentation about this function says that in Vista "hwnd and window manager operations are only effective inside a session and cross-session attempts to manipulate the hwnd will fail" and that statement indicated that problem is because of Vista.

http://msdn.microsoft.com/en-us/library/ms633545%28v=VS.85%29.aspx[^]

http://msdn.microsoft.com/en-us/library/aa480152.aspx[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100