GetWindowEx() looping question

D

darkchild50

this is a little off topic but its also in comp.windows.programing
and hasent goten a reply and so im posting it here:

is it possible to loop through all top level windows using
GetWindowEx(), and save all their handles in an array? i have been
trying this one for a while but it dosent seem to work i end up in a
never ending loop. anyone know how this works?

please and thank you DarkChild
 
M

Micah Cowan

this is a little off topic but its also in comp.windows.programing
and hasent goten a reply and so im posting it here:

Actually, it's _completely_ off-topic.
is it possible to loop through all top level windows using
GetWindowEx(), and save all their handles in an array? i have been
trying this one for a while but it dosent seem to work i end up in a
never ending loop. anyone know how this works?

I'm sorry that you have been unable to get satisfactory response from
comp.windows.programming; you might try waiting a little longer, or
perhaps a web-based forum.

As to this newsgroup, I'm afraid we don't answer questions related to
non-Standard C function usage. Facilities provided by external
libraries or as extensions, etc., are way off-topic here, and as this
group already has a difficulty in keeping the signal-to-noise ratio
relatively sane, most of us simply refuse to answer such questions
(on-list, at least), even if we happen to know it (I don't).

At any rate, you are /far/ more likely to get useful responses from
trying several other Windows-programming-related forums.

Best of luck.

-Micah
 
K

Keith Thompson

this is a little off topic but its also in comp.windows.programing
and hasent goten a reply and so im posting it here:

is it possible to loop through all top level windows using
GetWindowEx(), and save all their handles in an array? i have been
trying this one for a while but it dosent seem to work i end up in a
never ending loop. anyone know how this works?

Sorry, but this is entirely off-topic here. I'm sorry you're not
getting answers in comp.windows.programming, but that doesn't make it
topical here. Perhaps you could try one of the microsoft.*
newsgroups.

When you find an appropriate newsgroup, I strongly suggest you post
the actual code you're using.
 
R

Rod Pemberton

this is a little off topic but its also in comp.windows.programing
and hasent goten a reply and so im posting it here:

is it possible to loop through all top level windows using
GetWindowEx(), and save all their handles in an array? i have been
trying this one for a while but it dosent seem to work i end up in a
never ending loop. anyone know how this works?

Forgive them, for they know not what they say.

Saving the return values from a function to an array is standard C. Anyone
here can help with that. However, you unfortunately mentioned
'GetWindowsEx()' which provokes hostility among the immature and
inconsiderate. How about rephrasing your question, and posting code where
the 'GetWindowsEx()' is replaced by something non-descript?


Rod Pemberton
 
M

Micah Cowan

Rod Pemberton said:
Forgive them, for they know not what they say.

Saving the return values from a function to an array is standard C. Anyone
here can help with that. However, you unfortunately mentioned
'GetWindowsEx()' which provokes hostility among the immature and
inconsiderate. How about rephrasing your question, and posting code where
the 'GetWindowsEx()' is replaced by something non-descript?

Actually, Rod, my lack of ability/inclination to post a helpful
response has nothing to do with arrays.

I have no idea what GetWindowEx() does, whether it can be used to loop
through all top level windows, and whether it provides access to
handles that could be stored in an array. Even if I did know these
things, their knowledge shouldn't really affect my answer.

Now, if his post explained something more about what GetWindowEx()
does, and asked a question that is obviously a Standard C-related
question, I (and others) might be able to help.

Also, I take issue to your assertion that anyone reacted with
hostility (at least, in any messages that have yet to show up on my
server), and would challenge you to produce an example of such. I was
very careful to word my response in a non-hostile manner.

The simple fact is, his question, at least as it was framed, was about
GetWindowEx(), not arrays, and is therefore off-topic here.

-Micah
 
K

Kenneth Brody

Rod said:
Forgive them, for they know not what they say.

Saving the return values from a function to an array is standard C.
True.

Anyone here can help with that.

If he had posted some code, perhaps.
However, you unfortunately mentioned
'GetWindowsEx()' which provokes hostility among the immature and
inconsiderate. How about rephrasing your question, and posting code where
the 'GetWindowsEx()' is replaced by something non-descript?

Except you fail to realize that, lacking any sample code, it is entirely
possible that the fault lays in the way in which he uses GetWindowEx(),
and that is not something topical to clc.

Replacing "GetWindowEx()" with "something non-descript" such as "foo()"
will simply (and rightfully) be met with "what does foo() do", unless
you explain what it does.

I don't think people would have a problem with using GetWindowEx(), if
the OP were to post code, along with a description of the function.

Of course, given that Microsoft's documentation shows no such function as
"GetWindowEx()" or "GetWindowsEx()", it's entirely possible that we're not
even talking about MS-Windows here. Or it may be some third-party library
for MS-Windows. Or it may be a typo in the OP's post. Or...

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
D

darkchild50

Of course, given that Microsoft's documentation shows no such function as
"GetWindowEx()" or "GetWindowsEx()", it's entirely possible that we're not
even talking about MS-Windows here. Or it may be some third-party library
for MS-Windows. Or it may be a typo in the OP's post. Or...

im sorry therir was an error in my pose the function is as follows:

HWND FindWindowEx(

HWND hwndParent,
HWND hwndChildAfter,
LPCTSTR lpszClass,
LPCTSTR lpszWindow
);

Parameters

hwndParent
[in] Handle to the parent window whose child windows are to be
searched.

If hwndParent is NULL, the function uses the desktop window as
the parent window. The function searches among windows that are child
windows of the desktop.

Microsoft Windows 2000 and Windows XP: If hwndParent is
HWND_MESSAGE, the function searches all message-only windows.
hwndChildAfter
[in] Handle to a child window. The search begins with the next
child window in the Z order. The child window must be a direct child
window of hwndParent, not just a descendant window.

If hwndChildAfter is NULL, the search begins with the first
child window of hwndParent.

Note that if both hwndParent and hwndChildAfter are NULL, the
function searches all top-level and message-only windows.
lpszClass
[in]

Pointer to a null-terminated string that specifies the class
name or a class atom created by a previous call to the RegisterClass or
RegisterClassEx function. The atom must be placed in the low-order word
of lpszClass; the high-order word must be zero.

If lpszClass is a string, it specifies the window class name.
The class name can be any name registered with RegisterClass or
RegisterClassEx, or any of the predefined control-class names, or it
can be MAKEINTATOM(0x800). In this latter case, 0x8000 is the atom for
a menu class. For more information, see the Remarks section of this
topic.
lpszWindow
[in] Pointer to a null-terminated string that specifies the
window name (the window's title). If this parameter is NULL, all window
names match.

Return Value

If the function succeeds, the return value is a handle to the
window that has the specified class and window names.

If the function fails, the return value is NULL. To get extended
error information, call GetLastError.

and sorry its off topic but im getting mixed messages so i figgure i
should try anyway.
 
K

Keith Thompson

Of course, given that Microsoft's documentation shows no such function as
"GetWindowEx()" or "GetWindowsEx()", it's entirely possible that we're not
even talking about MS-Windows here. Or it may be some third-party library
for MS-Windows. Or it may be a typo in the OP's post. Or...

im sorry therir was an error in my pose the function is as follows:

HWND FindWindowEx(

HWND hwndParent,
HWND hwndChildAfter,
LPCTSTR lpszClass,
LPCTSTR lpszWindow
); [snip]
and sorry its off topic but im getting mixed messages so i figgure i
should try anyway.

Sorry about the mixed messages. Some people here don't seem to
understand what's topical in this newsgroup and what isn't.

Your question is off-topic in comp.lang.c. HWND and LPCTSTR appear to
be system-specific types; we don't know how they're defined. (That's
not a request for you to explain them.)

There are a number of newsgroups that deal with MS Windows
programming. I don't know which one would be the most appropriate. I
think you mentioned comp.windows.ms.programmer; you might try
comp.os.ms-windows.programmer.win32, or perhaps one of the
microsoft.public.* newsgroups (there are 2349 of them on the news
server I use).

You've shown us the documentation for the FindWindowEx() function, but
you haven't shown us your code that's causing the problem. Once you
decide on an appropriate newsgroup, post a small complete compilable
program that exhibits the problem, so others can try it themselves,
and explain *exactly* how it fails (what it does and what you wanted
it to do). You shouldn't need to post a description of FindWindowEx()
if you find a forum where they already know about it.

Good luck.
 
M

Micah Cowan

im sorry therir was an error in my pose the function is as follows:

<snip>

Thanks for posting information on the function. There's still a lot of
Windows specific stuff in the description, but I think most would be
able to get the drift.

The thing is, from reading your description of the function, there
doesn't seem to be any obvious way (to me, at least) to use it to
iterate over all windows in a class of windows, and store their
handles in an array. That doesn't mean it can't be done, but it very
much seems like the answer will be Windows-related, rather than
C-related. Again, I'd really recommend that you ask this in a
different Windows-related forum. If the first one you tried turned out
unhelpful, you should look for others: there are many.

-Micah
 
M

Mike Wahler

this is a little off topic but its also in comp.windows.programing
and hasent goten a reply and so im posting it here:

is it possible to loop through all top level windows using
GetWindowEx(), and save all their handles in an array? i have been
trying this one for a while but it dosent seem to work i end up in a
never ending loop. anyone know how this works?

please and thank you DarkChild

Post your question (including your code) to group
comp.os.ms-windows.programmer.win32. It is a very
active group with many Windows experts. They'll
likely tell you about a function called 'EnumWindows()'.

Only standard C is topical for comp.lang.c

-Mike
 
P

pemo

this is a little off topic but its also in comp.windows.programing
and hasent goten a reply and so im posting it here:

is it possible to loop through all top level windows using
GetWindowEx(), and save all their handles in an array? i have been
trying this one for a while but it dosent seem to work i end up in a
never ending loop. anyone know how this works?

Ok OT, but as you're not getting anywhere fast ...

The simplest way to do this is to use EnumWindows() - as that enumerates
*only* top-level windows.

Say you have a main window wndproc, put this in some handy message handler
....

EnumWindows(EnumWindowsProc, (LPARAM)hwnd);

Note that the function call passes the current window's hwnd onto the
callback function EnumWindowsProc.

The EnumWindowsProc could be like this ...

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
HDC hDc;
char buffer[100]
static int n = 0;

// Get the main window's hwnd.
//
hDc = GetDC((HWND)lParam);

// Format the current enumerated window's hwnd.
//
wsprintf(buffer, "%X", hwnd);

TextOut(hDc, 0, n += 15, buffer, strlen(buffer));

ReleaseDC((HWND)lParam, hDc);

return TRUE;
}

The code above will output the window handles of all the top-level windows
on to the main window's client area.
 
C

CBFalconer

pemo said:
Ok OT, but as you're not getting anywhere fast ...

The simplest way to do this is to use EnumWindows() - as that
enumerates *only* top-level windows.

Say you have a main window wndproc, put this in some handy message
handler ...

He is getting nowhere rapidly because he is asking in the wrong
place. You are doing no favors by answering in that same wrong
place, since there is nobody here to evaluate and correct that
answer. All you are doing is encouraging misbehaviour and creating
clutter.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
P

pemo

CBFalconer said:
He is getting nowhere rapidly because he is asking in the wrong
place. You are doing no favors by answering in that same wrong
place, since there is nobody here to evaluate and correct that
answer. All you are doing is encouraging misbehaviour and creating
clutter.

Main point taken.

The answer is correct though.
 
K

Kenneth Brody

im sorry therir was an error in my pose the function is as follows:

HWND FindWindowEx(
[...snip...]

Well, you still haven't posted your code which is having the problem.

However, making some assumptions (a bad thing, I know), you mention that
you want to fill an array by using this function in a loop. However,
nothing in the description of the function says that it iterates through
a list. Rather, it returns "a handle to _the_ window" (emphasis mine),
which tells me that it is explicitly stating that you will get the same
return value over and over. Calling it repeatedly will _not_ get you a
handle to the _next_ window.

I think this is a perfect example of why (1) showing actual code is very
important, (2) posting to the proper group is very important, and (3) not
giving erroneous information (like the wrong function name) is very
important.

Had you posted a question to a Windows programming group asking about
using FindWindowEx() in a loop, and included your code, someone there
probably would have pointed out right away that you're either using the
function incorrectly, or using the wrong function entirely.

If you want to find _all_ of the windows, then you need to use a
function which will enumerate (key word -- hint, hint) them for you.
Of course, now we're back to "which function that is, and how you use it
properly, are off-topic to clc and probably belong in one of the
comp.os.ms-windows.* or microsoft.public.* newsgroups". If, once you
get the function and how to use it, and you are using it properly (that
is, you are getting a list of values returned from successive calls) you
still have trouble filling in an array with its return values, then that
would be back on-topic here, but you need to post the code which is
failing, along with a description of the failure.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top