Hi,
I'm trying to add "Cascade" windows functionality in a C# SDI application,
using the win32 API call:
WORD CascadeWindows( HWND hwndParent,
UINT wHow,
const RECT *lpRect,
UINT cKids,
const HWND *lpKids
);
I've being trying to use the API in the following way, however it is not
cascading the four windows I am passing to it in the windowArray parameter,
instead it cascades my version of Visual Studio that the Application is
being run from:
[DllImport("user32")] public static extern short CascadeWindows(int
hwndParent,
int wHow, int lpRect, int cKids, ref System.IntPtr[] lpKids);
public void Cascade(Form[] arrangeWindows )
{
int index = 0;
System.IntPtr[] windowArray = new
System.IntPtr[arrangeWindows.Length];
foreach(Form arrangeWindow in arrangeWindows)
{
windowArray[index++] = arrangeWindow.Handle;
}
User32.CascadeWindows(0, 0, 0, windowArray.Length, ref windowArray);
}
Any ideas what I am doing wrong?
Thanks in Advance for any Help :-)-Peter Mc
Robert Jordan - 13 Sep 2004 12:37 GMT
Hi Peter McElroy,
> Hi,
>
[quoted text clipped - 12 lines]
> instead it cascades my version of Visual Studio that the Application is
> being run from:
> [DllImport("user32")] public static extern short CascadeWindows(int
> hwndParent,
> int wHow, int lpRect, int cKids, ref System.IntPtr[] lpKids);
The hwndParent (1st param) must be an IntPtr.
> public void Cascade(Form[] arrangeWindows )
> {
[quoted text clipped - 7 lines]
>
> User32.CascadeWindows(0, 0, 0, windowArray.Length, ref windowArray);
You have to pass the MDI parent form's Handle an the
first argument to CascadeWindow.
bye
Rob
Robert Jordan - 13 Sep 2004 12:39 GMT
>> public void Cascade(Form[] arrangeWindows )
>> {
[quoted text clipped - 10 lines]
> You have to pass the MDI parent form's Handle an the
> first argument to CascadeWindow.
Ahh, it's actually a SDI-apllication ;-)
Then pass the Main form's Handle to CascadeWindows.
bye
Rob
Peter McElroy - 13 Sep 2004 14:11 GMT
Hi Rob,
Thanks for the help, I tried setting the main form so that the code now
looks like this:
[DllImport("user32")] public static extern short
CascadeWindows(System.IntPtr hwndParent,
int wHow, int
lpRect, int cKids, ref System.IntPtr[] lpKids);
public void Cascade(Form[] arrangeWindows )
{
System.IntPtr[] windowArray = new System.IntPtr[arrangeWindows.Length];
foreach(Form arrangeWindow in arrangeWindows)
{
windowArray[index++] = arrangeWindow.Handle;
}
User32.CascadeWindows(this.MainForm.Handle, 0, 0, windowArray.Length,
ref windowArray);
}
Unfortunately it is still not working, I'm wondering if I need to specify
the lpRect and wHow parameters,
and if so how I would do this in c#, any Ideas ?
Thanks again :-)
-Peter Mc
>>> public void Cascade(Form[] arrangeWindows )
>>> {
[quoted text clipped - 16 lines]
> bye
> Rob
Robert Jordan - 13 Sep 2004 14:52 GMT
> Hi Rob,
>
[quoted text clipped - 5 lines]
> int wHow, int
> lpRect, int cKids, ref System.IntPtr[] lpKids);
static extern short CascadeWindows(IntPtr hwndParent, uint wHow,
IntPtr lpRect, uint cKids, IntPtr[] lpKids);
"ref System.IntPtr[] lpKids" is wrong.
> public void Cascade(Form[] arrangeWindows )
> {
[quoted text clipped - 12 lines]
> the lpRect and wHow parameters,
> and if so how I would do this in c#, any Ideas ?
According to the docs, lpRect can be IntPtr.Zero.
bye
Rob
Peter McElroy - 15 Sep 2004 15:13 GMT
Hi Rob,
Thats got it working Thanks! :-)
Cheers
-Peter Mc
>> Hi Rob,
>>
[quoted text clipped - 33 lines]
> bye
> Rob