Hi,

Can anyone figure out why this returns null?

//----------------------------------------------------------------------------
//UIPermission uip = new UIPermission(UIPermissionWindow.AllWindows);
//uip.Assert();

IntPtr pi = new IntPtr(GetDesktopWindow());
Control c = Control.FromChildHandle(pi);
if(c == null) MessageBox.Show("Didn't work");
//-----------------------------------------------------------------------------

I think it may have to do with security permission. I know for a fact the Hwnd to the desktop is correct. If I use this line I can create a control...

Control c = Control.FromChildHandle(this.Handle);

Although, I don't want that particular control; I want the desktop. I have also tried Control.FromHandle, Form.FromHandle, and Form.FromChildHandle without any better luck.

Can anyone please help? Thanks!