.NETGURU
Tiling and Cascading windows
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.interop.

Post a new message to this list...

Peter McElroy
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

Reply to this message...
 
    
Robert Jordan
Hi Peter McElroy,

[Original message clipped]

The hwndParent (1st param) must be an IntPtr.

[Original message clipped]

You have to pass the MDI parent form's Handle an the
first argument to CascadeWindow.

bye
Rob
Reply to this message...
 
    
Robert Jordan
[Original message clipped]

Ahh, it's actually a SDI-apllication ;-)
Then pass the Main form's Handle to CascadeWindows.

bye
Rob
Reply to this message...
 
    
Peter McElroy
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

"Robert Jordan" <Click here to reveal e-mail address> wrote in message
news:ci40tj$dsf$05$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Robert Jordan
Peter McElroy wrote:

[Original message clipped]

static extern short CascadeWindows(IntPtr hwndParent, uint wHow,
IntPtr lpRect, uint cKids, IntPtr[] lpKids);

"ref System.IntPtr[] lpKids" is wrong.

[Original message clipped]

According to the docs, lpRect can be IntPtr.Zero.

bye
Rob
Reply to this message...
 
    
Peter McElroy
Hi Rob,

Thats got it working Thanks! :-)

Cheers
-Peter Mc

"Robert Jordan" <Click here to reveal e-mail address> wrote in message
news:ci48mr$v17$02$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.IntPtr




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification