473,789 Members | 2,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

finding opened window based on its handle ( C# )

Hi! When I create a new form programatically , I can save its handle in a collection of some type
Later, I need to find that form based on a handle I saved and call one of its functions. The newly create
form can be a child of an MDI form but it very well may not be, so I can not use MDIChildren

I am wandering how it can be done in C#, please

Thank you in advance

Dany
Nov 16 '05 #1
3 9029
Use Control.FromHan dle.

Niki

"Daniel H." <an*******@disc ussions.microso ft.com> wrote in
news:4C******** *************** ***********@mic rosoft.com...
Hi! When I create a new form programatically , I can save its handle in a collection of some type. Later, I need to find that form based on a handle I saved and call one of its functions. The newly created form can be a child of an MDI form but it very well may not be, so I can not use MDIChildren.
I am wandering how it can be done in C#, please?

Thank you in advance,

Dany

Nov 16 '05 #2
Hi! Thank you for answering my question.
I am having difficulty using this method though and docs+internet do no
provide any examples

I have a collection FormHash and I add page name and form handle

if (!AppConfig.For mHash.Contains( this.m_pageName )) AppConfig.FormH ash.Add(this.m_ pageName,this.H andle)

Ideally this should work

IntPtr myPtr = (System.IntPtr) AppConfig.FormH ash[this.m_pageName]
MainForm newForm2 =(MainForm) Control.FromHan dle(myPtr)
newForm2.Activa te()

However, the call bombs with the invalid cast error on MainForm newForm2 =(MainForm) Control.FromHan dle(myPtr)

What am I doing wrong? -- must be really stupid

Any help is greatly appreciated

Dan

----- Niki Estner wrote: ----

Use Control.FromHan dle

Nik

"Daniel H." <an*******@disc ussions.microso ft.com> wrote i
news:4C******** *************** ***********@mic rosoft.com..
Hi! When I create a new form programatically , I can save its handle in collection of some type Later, I need to find that form based on a handle I saved and call one o its functions. The newly create form can be a child of an MDI form but it very well may not be, so I ca

not use MDIChildren
I am wandering how it can be done in C#, please
Thank you in advance
Dan


Nov 16 '05 #3
Don't know; Use the debugger and see if the handle is really the same, look
what control is returned by "FromHandle ".

BTW: Why do you store a handle (and not a reference to the main form) in the
first place?

Niki

"Daniel H." <an*******@disc ussions.microso ft.com> wrote in
news:BE******** *************** ***********@mic rosoft.com...
Hi! Thank you for answering my question.
I am having difficulty using this method though and docs+internet do not
provide any examples.

I have a collection FormHash and I add page name and form handle:

if (!AppConfig.For mHash.Contains( this.m_pageName )) AppConfig.FormH ash.Add(this.m_ pageName,this.H andle);
Ideally this should work:

IntPtr myPtr = (System.IntPtr) AppConfig.FormH ash[this.m_pageName];
MainForm newForm2 =(MainForm) Control.FromHan dle(myPtr);
newForm2.Activa te();

However, the call bombs with the invalid cast error on MainForm newForm2 =(MainForm) Control.FromHan dle(myPtr);
What am I doing wrong? -- must be really stupid.

Any help is greatly appreciated.

Dany

----- Niki Estner wrote: -----

Use Control.FromHan dle.

Niki

"Daniel H." <an*******@disc ussions.microso ft.com> wrote in
news:4C******** *************** ***********@mic rosoft.com...
> Hi! When I create a new form programatically , I can save its handle in a
collection of some type.
> Later, I need to find that form based on a handle I saved and call
one of its functions. The newly created
> form can be a child of an MDI form but it very well may not be, so
I can not use MDIChildren. >> I am wandering how it can be done in C#, please?
>> Thank you in advance,
>> Dany


Nov 16 '05 #4

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

Similar topics

1
1471
by: joao | last post by:
Hi, I'm looking for a way to iterate over all existing top level windows, from inside javascript. I know that if I have a window's name, I can access it, retrieve a handle to it with window.open, etc. What I want here is, when there are one or more windows open, and I *don't* know their names, how can I find them ?
5
3607
by: Nazir | last post by:
I am trying to do something pretty simple - but can't see how it can be done in ASP.NET. I have an aspx web page with a form which opens up a new window. The web page uses code behind to build the new window. There is simple validation on the form. However, after the form page validates and opens the new window, I want it to redirect to another page (or stop displaying the form).
3
5938
by: Rune Jacobsen | last post by:
Hey all, Maybe someone knows this problem; I have a C# WinForms app that every now and then has a new version that I deploy to my users using an installation script written with the NSIS installer. To improve on this, I want the installer to shut down any running instances of my application when it does the installation. To do this, I have implemented the following function to kill any instances I find (yeah, I have the pinvoke for...
3
1536
by: marc | last post by:
If I open a window like this mywin=window.open("http://localhost:3456/" ); Is there a way to find out, in the calling javascript code, if the opened window mywin could read server information from "http://localhost:3456/". I tried mywin.error and mywin.status, but it's not yet clear to me what to do.
4
17499
by: drodrig | last post by:
Hi. I am trying to close/kill all processes that show visible windows on Windows XP. So far I've created a script that uses win32gui.EnumWindows to iterate through all windows, check for which windows are visible, then send a WM_CLOSE message to the window to request that it closes. Of course, not all apps want to close nicely. At this point I need to use something like TerminateProcess to kill the app, but how do I find the process id...
4
2407
by: Abhishek | last post by:
Hi All, how do I find the handle of a child window and get a screenshot of that in a hbitmap at present i tried the below method but am getting the screenshot of the desktop. the Egyptian Addiction is the name of the game and the mozillacontentwindowclass is the handle i need who's window i want to capture int nScreenWidth = 300; int nScreenHeight = 225;
6
1710
by: =?Utf-8?B?VG9tYXM=?= | last post by:
Hi, I have an C++/CLI MDI application with two Forms A and B. When I work with Form A I would like to know the handle of Form B (if it is opened), to use its handle in a delegate that execute a function in Form B. In example: DelegateAbc^ d = gcnew DelegateAbc(HANDLE,&FormB::TestB);
0
2186
by: Sasie7679 | last post by:
Dear All, We have a requirement to open any document with a specific application and display it within a OCX control (Example - word, excel, adobe reader, MSPaint, Photoshop etc). We are using CreateProcess Api to open the application. This APi returns process id and process handle. Once the application is opened, i need the exact window handle to show within the container (OCX control). I use "EnumWindows" to enumerate all top level windows...
0
980
by: rajeshskollam | last post by:
Dear All, I have stuck in a problem that i want to get the handle of crrently opened windows in our system.My application is that a virtual key board,if i open a notepad or word docs after that i opens my virtual key board(C#),that time i want to get the handle of previously opened window for set the value typed on the virtual key board to just previously opened window. Regards, Rajesh.s
0
9666
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
10408
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
10199
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
10139
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
9983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7529
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...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4092
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
3700
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.