Why IsWindowVisible makes callback of EnumDesktopWindows runs only once?
See the following code.
The MyEnumProc runs only one time with the following code. But if I commented out the IsWindowVisible(wnd);, it runs many times.
Why IsWindowVisible make this happened(run only one time)? I thought IsWindowVisible just a function to check the wnd's attributes?
codes of test.c:
#include <windows.h>
#include <stdio.h>
BOOL CALLBACK MyEnumProc( HWND wnd, LPARAM lParam )
{
pri开发者_JAVA百科ntf("run\n");
IsWindowVisible(wnd);
}
int main( void )
{
EnumDesktopWindows( NULL, MyEnumProc, 0 );
printf("end\n");
return 0;
}
My environment is:
Windows XP SP3.
gcc 3.4.6(mingw)
compiled option is: gcc -o test.exe test.c
I did the compile and run the test.exe in the cmd.exe.
You have to return a value. I would expect your compiler to be warning you that you are not. If it is not warning you then you should change the options to make it do so.
The documentation states:
To continue enumeration, the callback function must return TRUE; to stop enumeration, it must return FALSE.
This capability to terminate enumeration exists to allow you to short-circuit an enumeration. Once you have found the item you want there is no need to continue receiving callbacks. There are numerous Windows API functions that follow this idiom.
EnumDesktopWindows expects you to return a value from your MyEnumProc:
return TRUE;
Read the documentation for more information.
精彩评论