473,406 Members | 2,619 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,406 software developers and data experts.

to find instances of form running in c# using FindWindowEx

Hello,

i want to find out how many instances of a form (say childForm1) is
running using FindWindowEx but value return is always zero by this method.

What wrong I am doing it..Can anybody help me to find the no. of form
instances running ?

Thanks.

Below is the code

I have already declared

[DllImport("user32.dll", SetLastError = true)]

static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter,
string lpszClass, string lpszWindow);

string lpszClass = childForm.Name;

IntPtr ParenthWnd = new IntPtr(0);

ParenthWnd = FindWindowEx(ParenthWnd,hWnd,lpszClass,"");

if (ParenthWnd .Equals(IntPtr.Zero))

Console.WriteLine("childForm.Name is not running?");

else

Console.WriteLine("childForm.Name is running?");

return;
Nov 22 '05 #1
1 6397
FindWindowEx requires you to specify the Windows Class Name (see
RegisterWindowEx in the Platform SDK). You have used Form.Name as the class
name but this is not correct. To get the class name of your form you can use
the Win32 API function GetClassName as in the following example:

[DllImport("user32.dll")]
static extern int GetClassName(IntPtr hWnd, [Out] StringBuilder lpClassName,
int nMaxCount);

StringBuilder className = new StringBuilder(256);
GetClassName(this.Handle, className, className.Capacity);
IntPtr h = FindWindowEx(IntPtr.Zero, IntPtr.Zero, className.ToString(), null);

HTH, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"enahar" wrote:
Hello,

i want to find out how many instances of a form (say childForm1) is
running using FindWindowEx but value return is always zero by this method.

What wrong I am doing it..Can anybody help me to find the no. of form
instances running ?

Thanks.

Below is the code

I have already declared

[DllImport("user32.dll", SetLastError = true)]

static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter,
string lpszClass, string lpszWindow);

string lpszClass = childForm.Name;

IntPtr ParenthWnd = new IntPtr(0);

ParenthWnd = FindWindowEx(ParenthWnd,hWnd,lpszClass,"");

if (ParenthWnd .Equals(IntPtr.Zero))

Console.WriteLine("childForm.Name is not running?");

else

Console.WriteLine("childForm.Name is running?");

return;

Nov 22 '05 #2

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

Similar topics

1
by: enahar | last post by:
Hello, i want to find out how many instances of a form (say childForm1) is running using FindWindowEx but value return is always zero by this method. What wrong I am doing it..Can anybody...
7
by: a s i l b a . p t | last post by:
Can someone please explain why the following code raises error 2450?... Note: frmTest is a simple form with code behind form so it can be instantiated through the form's class module. Public...
0
by: Paul Steele | last post by:
I've written a callback function for use with EnumWindow that is intended to return the URL of all open IE windows. The code seems to do almost exactly what I want, but fails at the final step when...
4
by: Roland Riess | last post by:
Hi all, at the moment i am developing an app which is sort of an interface to copy data from one database to another and it shall run as a service. As there are several databases the app must be...
7
by: Lars Netzel | last post by:
Do I use FindWindowEx() to find control ( a button.. ) within a Window or is that only to find child Windows after using FindWindows() best regards /Lars
0
by: Apnea | last post by:
Hi all I am working on a C# application that is launched as a child within a 3rd party application (not .net) my problem is that when i use the any control on the form that inherits from...
2
by: moondaddy | last post by:
I had to repost this because I had to update and change my msdn alias. I will re-ask the question and clarify a few things that were not clear before. This code is all executed on my dev...
5
by: Neil | last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com... Question for you. I'm doing something similar, only, instead of opening...
8
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm trying to get a list of SQL Server Instances thru a VB.NET application. I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe from...
6
by: kru | last post by:
Hi All, I've been trying to get FindWindowEx to work to locate a button, and am stumped on the following: The structure of the external app is as so from Spy++: - "Main Window" -...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.