-
June 1st, 2006, 04:40 AM
#1
[RESOLVED] EnumWindowsProc as a member function?
Hi all
I'm going to enum all windows using EnumWindows, as I need to check some Z order between some window handles that my program has.
I know I have to make a callback function to use EnumWindows, but as I'm relatively new to pointers to functions, I'm wondering if it's possible to make the callback function a member function of the class that is calling EnumWindows.
I know pointers to functions and pointers to member functions doesn't like to be mixed, and that the size of the address can be different. So is it impossible?
To clearly specify what I want, here is some pseudo code.
Code:
class CMyClass
{
public:
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
void SomeFunction()
{
BOOL (CMyClass::*pEnumProc)(HWND hwnd, LPARAM lParam);
pEnumProc = CMyClass::EnumWindowsProc;
EnumWindows(pEnumProc, 0);
}
};
Some syntax might be wrong, I just wrote it, and the editor can't compile it. But I think it shows what it is I want to archive.
So, can this be done, or is not possible?
Thanks in advance!
-
June 1st, 2006, 05:27 AM
#2
Re: EnumWindowsProc as a member function?
You should declare it as static.
Code:
class CMyClass
{
public:
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
:
:
};
Cheers
-
June 1st, 2006, 03:47 PM
#3
Re: EnumWindowsProc as a member function?
Is that a requirement to reach my goal, or just a suggestion?
-
June 2nd, 2006, 12:37 AM
#4
Re: EnumWindowsProc as a member function?
Originally Posted by ReneG
Is that a requirement to reach my goal?
Definitely.
See THIS ARTICLE.
-
June 2nd, 2006, 02:41 AM
#5
Re: EnumWindowsProc as a member function?
Great link ovidiucucu! Thanks alot! It explains all the questions I had about pointers to member functions!
And FYI, I've rated both of your posts. Thanks for your replies!
-
June 2nd, 2006, 05:40 AM
#6
Re: EnumWindowsProc as a member function?
Okay, I tried implementing the EnumWindowsProc callback function, but I get a compiler error.
Code:
error C2664: 'EnumWindows' : cannot convert parameter 1 from 'bool (__stdcall *)(HWND,LPARAM)' to 'WNDENUMPROC'
The callback function is defined like this in my class header file:
Code:
static bool CALLBACK EnumCallback(HWND hwnd, LPARAM lParam);
The function is defined in the protected section of my class.
I try to use the EnumWindows in a member function of the same class, like this:
Code:
::EnumWindows(&CSnapWebConference::EnumCallback, (LPARAM)this);
That gives the error I mentioned above.
I've tried changing it to
Code:
::EnumWindows(&EnumCallback, (LPARAM)this);
and
Code:
::EnumWindows(EnumCallback, (LPARAM)this);
Neither one works.
I can't figure out what i'm doing wrong, but I'm guessing my function signature is incorrect, or incompatible with WNDENUMPROC, that EnumWindows expects.
Any help is highly appreciated!
Last edited by ReneG; June 2nd, 2006 at 05:43 AM.
-
June 2nd, 2006, 06:52 AM
#7
Re: EnumWindowsProc as a member function?
I solved it!
The problem was not with the function signature as expected, but with the syntax in the call to EnumWindows. All I had to change was the call to EnumWindows. The changed line looks like this:
Code:
::EnumWindows((WNDENUMPROC)this->EnumCallback, (LPARAM)this);
I found out after reading this article from Microsoft.
Thanks alot anyway.
-
July 16th, 2020, 10:45 AM
#8
Re: [RESOLVED] EnumWindowsProc as a member function?
Here is another point that might save some of you visitors some time if you have this problem:
Make sure you are using the return type BOOL and not bool since callbacks require the old school int version!
I could not get it working even with all the above help until I realized I also need to change this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|