Click here to Skip to main content
15,067,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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);

Is this because of Vista? What alternative should I use?
Updated 8-May-10 2:18am

Try the SetWindowPos windows api function (you'll need pinvoke for that), and it looks like it takes many of the same parameters.
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.
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.[^][^]

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900