简体   繁体   中英

enumerate child windows doesn't function, but enumWindows does…?

Heading

I don't know why, but when i start enumerating windows, it goes correctly, but enumerating child windows do not enter function... and moves around code... if i put hwnd = 0 it runs... have no idea why not with hwnd to find child windows.

enter code here
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;
HWND h;
int WPoc, CHPoc;
static BOOL CALLBACK EnumWindowsProc(HWND hProg, long lParam)
{
    WPoc++; 
    cout << WPoc << ": " << hProg << endl;
    if(WPoc == 5) h = hProg;
    if (WPoc > 20) return FALSE;
    return TRUE;
}
static BOOL CALLBACK EnumChildProc(HWND hProg, long lParam)
{
    CHPoc++;
    cout <<"ch "<< CHPoc << endl;
    if (CHPoc > 20) return FALSE;
    return TRUE;
}
void Search()
{
    WPoc = 0;
    BOOL ProcSuccess;
    ProcSuccess = EnumWindows((WNDENUMPROC)EnumWindowsProc,NULL);
}
void SearchMap()
{
    CHPoc = 0;
    BOOL ProcSuccess;
    ProcSuccess = EnumChildWindows( h,(WNDENUMPROC)EnumChildProc,NULL);
}

int _tmain(int argc, _TCHAR* argv[])
{
    Search();
    SearchMap();

    return 0;
}

I made this simple code to find mistakes and it does the same... I don't know what is wrong... thanks for help.

It's not work for you, because you found the window with no childrens. Debug your stuff. Paste breackpoint after Serach() , see the value of h . Open Spy++ and find the handle with the same value as h . See if this window has a childrens. Possible output:

1: 0004069E
2: 000305C4
3: 00030526
4: 00010158
5: 000100BA
6: 000100BC
7: 000100A6
8: 000100AA
9: 000100AC
10: 0001008E
11: 000100A2
12: 000100A4
13: 00010086
14: 00050598
15: 0006052E
16: 0010042E
17: 0011041A
18: 000D040C
19: 000803B8
20: 000903BC
21: 000903C8
ch 1
ch 2
ch 3
ch 4

The output of the program you posted is not determined by the source code.

It depends on the actual window that was the 5th window that EnumWindows enumerated, which is system dependent. If that window has no children the callback you pass to EnumChildWindows will never be called -- evidently, in your case, this is what is happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM