tags:

views:

106

answers:

1

I want to tile C# winforms but it seems that the .Net framework does not support this. So I used the Win32 function TileWindows. Here's the code:

            GCHandle gcHandle = GCHandle.Alloc(handles, GCHandleType.Pinned);
            IntPtr arrayHandle = gcHandle.AddrOfPinnedObject();
            TileWindows(IntPtr.Zero,
                        (uint)(Tile.Vertical | Tile.SkipDisabled),
                        IntPtr.Zero,
                        (uint)handles.Length, ref arrayHandle);
            gcHandle.Free();

handles is the array of winforms handles and Tile is just an enum of uints. The problem is after calling this function all of the open windows on my dekstop is affected instead of the passed array handles. Any suggestions?

A: 

What is handles? I assume it's an array of window handles

How is TileWindows defined (signature) ?

I have tried your code, and it actually worked after removing the keyword ref from the last parameter.

        GCHandle gcHandle = GCHandle.Alloc(handles, GCHandleType.Pinned);
        IntPtr arrayHandle = gcHandle.AddrOfPinnedObject();
        TileWindows(IntPtr.Zero,
                    (uint)(Tile.Vertical | Tile.SkipDisabled),
                    IntPtr.Zero,
                    (uint)handles.Length, arrayHandle);
        gcHandle.Free();

with the function signature:

     [DllImport("user32.dll")]
    static extern ushort TileWindows(IntPtr hwndParent, uint wHow, IntPtr lpRect,
       uint cKids, IntPtr lpKids);
Aziz
mmm.. i have not tried it.
John