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

EnumWindows

Hello, Newsgroupians:

I've a question regarding the Win32 function EnumWindows. First, the
prototype for EnumWindows is as follows...

BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam)

As such, I have declared the following...

[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int EnumWindows(EnumWindowsProcDelegate lpEnumFunc,
IntPtr lParam];
private delegate int EnumWindowsProcDelegate(IntPtr hwnd, IntPtr lParam);

Now, I'd like to call the EnumWindows. When it finds a specific window I'm
looking for, I want the lParam to be the return value of that specific
window. Here's an example...

IntPtr hwnd = new IntPtr();
EnumWindows(new EnumWindowsProcDelegate(EnumWndProc), hwnd);
....

private static int EnumWndProc(IntPtr hwnd, IntPtr lParam)
{
// For simplicity, the first window I find will be set to the lParam
lParam = hwnd;
}

However, after calling EnumWindows(...), hwnd is always 0x00000000 after the
EnumWndProc. As such, I tried the GCHandle, but I still get no where. Does
anyone know what I can do to return a client handle in the lParam?

Thank you, all.
Trecius
Jan 24 '08 #1
1 6548
Trecius,

I would use an anonymous method to do this, like so:

IntPtr value = IntPtr.Zero;
IntPtr hwnd = IntPtr.Zero;

EnumWindows(delegate(IntPtr hwnd, IntPtr lParam)
{
// Set the value variable based on your condition.
value = < whatever >;
}, hwnd);

Then, when you run EnumWindows, it will set the value variable, and you
can use it from there.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Trecius" <Tr*****@discussions.microsoft.comwrote in message
news:30**********************************@microsof t.com...
Hello, Newsgroupians:

I've a question regarding the Win32 function EnumWindows. First, the
prototype for EnumWindows is as follows...

BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam)

As such, I have declared the following...

[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int EnumWindows(EnumWindowsProcDelegate lpEnumFunc,
IntPtr lParam];
private delegate int EnumWindowsProcDelegate(IntPtr hwnd, IntPtr lParam);

Now, I'd like to call the EnumWindows. When it finds a specific window
I'm
looking for, I want the lParam to be the return value of that specific
window. Here's an example...

IntPtr hwnd = new IntPtr();
EnumWindows(new EnumWindowsProcDelegate(EnumWndProc), hwnd);
...

private static int EnumWndProc(IntPtr hwnd, IntPtr lParam)
{
// For simplicity, the first window I find will be set to the lParam
lParam = hwnd;
}

However, after calling EnumWindows(...), hwnd is always 0x00000000 after
the
EnumWndProc. As such, I tried the GCHandle, but I still get no where.
Does
anyone know what I can do to return a client handle in the lParam?

Thank you, all.
Trecius

Jan 24 '08 #2

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

Similar topics

5
by: Sean Dudley | last post by:
I am currently enumerating windows via the EnumWindows API. I noticed that for some reason the very first time I call my enumwindows routine (inside or outside of a thread) it seems to be very...
3
by: Tim Chase | last post by:
I have found that EnumWindows works very quickly. In DotNet (I use C#), I can enumerate the windows, narrow them down to just the windows which are the main windows (i.e., windows which you can...
11
by: Wayne | last post by:
I have some code written in delphi that uses EnumWindows, I would like to begin to translate this code to C#. Is there a built in EnumWindows call in Csharp? or do I have to import the API and use...
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...
1
by: Frederic_BD | last post by:
Hello! I am trying to get a list of all the process running on WinCE. I first developed my code on NT (which is working fine) and now I am porting it to WinCE 4.20. I am using embedded Visual...
4
by: Geoff | last post by:
I need to reproduce functionality from a VB6 application in VB .Net. In the VB6 app, I use FindWindow, EnumWindows and other related functions. Is there a .Net NameSpace that replaces these...
1
by: Geoff | last post by:
Tom, I am trying to find out if a specific app is already running. And, in some cases, I will need to be able to "click a button" in that other app if it IS running. Using VS.Net 2003 and .Net...
3
by: Nick | last post by:
Hi there, I'm using the EnumWindows method in VB.NET to acquire the HDC of all open windows. Unfortunately I get lots of unwanted window handles, I would *ideally* like just the windows that...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
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
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
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...
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,...
0
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...

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.