Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Window Handle Win32 APIs Under C#

1 view
Skip to first unread message

TC

unread,
Apr 21, 2005, 2:40:18 PM4/21/05
to
Hey Folks,

I am using the following 4 Win32 APIs with a C# AddIn:

FindWindow
SetWindowLong
SetForegroundWindow
EnableWindow

Within the AddIn, there are some winforms. I use these APIs to set them as
the top window in modeless form but only from within the parent app (i.e.
while in the AddIn's parent app, the winforms are on top and modeless but
when moving to another app, the newly activated app is the top window).

For example, on the 'Load' event, I do the following:

SetWindowLong(this.Handle, GWL_HwndParent, this.ParentApp.Handle);

// Disable Outlook window for modal functionality
EnableWindow((IntPtr)this.ParentApp.Handle,false);
EnableWindow(this.Handle,true);

I know that one can set a winform to be a top window but it does it for the
entire desktop.

Is there a way under the .Net Framework to easily achieve the same behavior
accomplished via the APIs?

Thanks & Regards,

TC

Dmytro Lapshyn [MVP]

unread,
Apr 22, 2005, 2:32:51 AM4/22/05
to
Hi TC,

In an add-in, I assume the host application's main window should be the
parent of all winforms created by the add-in.
If the host application is Visual Studio, you can get the handle of the main
window from the root automation object and then create a very simple
implementation of IWin32Window to return the obtained handle as the parent
window to forms you are creating from your add-in.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


"TC" <getmye...@yahoo.com> wrote in message
news:eP9jVGqR...@TK2MSFTNGP12.phx.gbl...

TC

unread,
Apr 22, 2005, 11:07:32 AM4/22/05
to
Hey Dmytro,

You are correct in that the Office Suite application's main window is the
parent to my addin and I can get a handle to this window.

What I seem to be missing is how to use this handle to set a parent or owner
property to a C# winform. Both the 'Owner' property and the 'ParentForm'
property return 'Form' objects and not handles.

Regards,

TC

"Dmytro Lapshyn [MVP]" <x-c...@no-spam-please.hotpop.com> wrote in message
news:OkumdUw...@TK2MSFTNGP12.phx.gbl...

Dmytro Lapshyn [MVP]

unread,
Apr 22, 2005, 11:28:55 AM4/22/05
to
You are right - this works only for ShowDialog which accepts IWin32Window as
a parent.
For non-modal forms, you can try the SetParent API call.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


"TC" <getmye...@yahoo.com> wrote in message

news:OZyRG00R...@TK2MSFTNGP14.phx.gbl...

0 new messages