473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Window Handle Win32 APIs Under C#

TC
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

Nov 17 '05 #1
3 13689
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" <ge**********@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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


Nov 17 '05 #2
TC
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-****@no-spam-please.hotpop.com> wrote in message
news:Ok*************@TK2MSFTNGP12.phx.gbl...
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" <ge**********@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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

Nov 17 '05 #3
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" <ge**********@yahoo.com> wrote in message
news:OZ**************@TK2MSFTNGP14.phx.gbl...
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-****@no-spam-please.hotpop.com> wrote in message
news:Ok*************@TK2MSFTNGP12.phx.gbl...
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" <ge**********@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
2
by: Shawn Anderson | last post by:
Anyone know how I can get a Win32 HANDLE from a StreamReader or StreamWriter? I want to work with some I/O using Win32 APIs, but I would like to attach the I/O to a .NET Stream class. Any...
11
by: objectref | last post by:
Hi to all, is there a way to get the window handle of the main window of an application or process ? For example, if someone opens Microsoft Word, he gets a window so he/she can write text....
11
by: garyusenet | last post by:
For this first time today I used the System.Diagnositcs namespace to launch a program from my c# code. The program launches OK but I have something which has completely stumped me. The...
2
by: Jonathan Boivin | last post by:
Hi people, Let me introduce to how I get this error. I have a form which load all my bills representation depending upon filters which each bill is a usercontrol of my own having some...
1
by: elizayiu | last post by:
Hi, I need to write a webpage which does the following: - open up a window and pass parameters into it (i.e. need to call showModalDialog() or showModelessDialog()) - contains jscript to...
18
by: rdahlstrom | last post by:
Does anyone know how to determine the window status (Running or Not Responding)? I've tried various methods with no success... This would be on a variety of Windows systems, but all at least XP,...
3
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
Given the handle of a window, is there a way to make it the foreground window using C# (rather than win32 API)?
9
by: =?Utf-8?B?UmFq?= | last post by:
How do I know which methods will throw exception when I am using FCL or other third party .Net library? I am developer of mostly native Windows applications and now .Net. After working few...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.