473,769 Members | 5,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Window Handle Win32 APIs Under C#

TC
Hey Folks,

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

FindWindow
SetWindowLong
SetForegroundWi ndow
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(t his.Handle, GWL_HwndParent, this.ParentApp. Handle);

// Disable Outlook window for modal functionality
EnableWindow((I ntPtr)this.Pare ntApp.Handle,fa lse);
EnableWindow(th is.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 13724
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**********@y ahoo.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.phx.gbl...
Hey Folks,

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

FindWindow
SetWindowLong
SetForegroundWi ndow
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(t his.Handle, GWL_HwndParent, this.ParentApp. Handle);

// Disable Outlook window for modal functionality
EnableWindow((I ntPtr)this.Pare ntApp.Handle,fa lse);
EnableWindow(th is.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.c om> wrote in message
news:Ok******** *****@TK2MSFTNG P12.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**********@y ahoo.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.phx.gbl...
Hey Folks,

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

FindWindow
SetWindowLong
SetForegroundWi ndow
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(t his.Handle, GWL_HwndParent, this.ParentApp. Handle);

// Disable Outlook window for modal functionality
EnableWindow((I ntPtr)this.Pare ntApp.Handle,fa lse);
EnableWindow(th is.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**********@y ahoo.com> wrote in message
news:OZ******** ******@TK2MSFTN GP14.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.c om> wrote in message
news:Ok******** *****@TK2MSFTNG P12.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**********@y ahoo.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.phx.gbl...
Hey Folks,

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

FindWindow
SetWindowLong
SetForegroundWi ndow
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(t his.Handle, GWL_HwndParent,
this.ParentApp. Handle);

// Disable Outlook window for modal functionality
EnableWindow((I ntPtr)this.Pare ntApp.Handle,fa lse);
EnableWindow(th is.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
4995
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. forkme.pl calls the process creation script (createme.pl) 5. createme.pl creates my notepad.exe process, but no window shows up on my PC. The result on my web browser is:
2
2719
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 suggestions? Thanks Shawn
11
5081
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. Spy++ gives that this window is called _Wwg. How we can get a handle to this window assuming that we do not know beforehand the name of the process,
11
5066
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 SetWindowPos method does not work. If I run the code as it is presented below, app.exe launches in its own window and is displayed at the top left part of the screen. However it isn't repositioned which is what the last piece of code should do. HOWEVER if...
2
596
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 textboxes containing bill's datas. (I already replaced the labels by painting the text instead.) When I click on my filter button, it clears the current usercontrol bills and load the new ones upon the current chosen filters. The bug happens when
1
2720
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 support drag and drop objects from itself to the popup window - wait for user response in popup window and return results back to the parent window (i.e. calling showModalDialog() is preferred)
18
3255
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, and mostly server 2003. Everyone will have Python 2.5.1 on them, and the script would be running locally. Any ideas?
3
3782
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
1931
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 months in Java, I am thinking why Win32 APIs or even .Net documentation not clear on which methods will throw exception or what exceptions can be expected. Jave APIs clearly define exceptions that can be expected and enforces that we handle them. ...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.