Not understanding How to Enumerate Child Windows.

HEADER
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef CHILDWINDOWTOMAINWINDOW_H
#define CHILDWINDOWTOMAINWINDOW_H
#include <windows.h>


class ChildWindowToMainWindow
{

    public:
        ChildWindowToMainWindow(HINSTANCE hInstance);

        virtual ~ChildWindowToMainWindow();
static LONG APIENTRY MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

    protected:
    private:
    BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParamChild);
    WNDCLASSEX m_classChild;
    HWND m_hwndChild;
    static HINSTANCE hChildInstance;
    static char m_szChildClassName[];

};

#endif // CHILDWINDOWTOMAINWINDOW_H 



.CPP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "ChildWindowToMainWindow.h"
#include "WindowsProgram/MainWindow.h"
#include "resources.h"
char ChildWindowToMainWindow::m_szChildClassName[]="Child!";

HINSTANCE ChildWindowToMainWindow::hChildInstance = NULL;

ChildWindowToMainWindow::ChildWindowToMainWindow(HINSTANCE hinstance)
{
hChildInstance = hinstance;
m_classChild.cbClsExtra = 0;
m_classChild.cbSize = sizeof(WNDCLASSEX);
m_classChild.cbWndExtra;
m_classChild.hbrBackground = (HBRUSH) (COLOR_WINDOW);
m_classChild.hCursor = LoadCursor(NULL, IDC_HAND);
m_classChild.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_APP_ICON));
m_classChild.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_APP_ICON));
m_classChild.hInstance = hinstance;
m_classChild.lpfnWndProc = MainWndProc;
m_classChild.lpszClassName = m_szChildClassName;
m_classChild.lpszMenuName = NULL;
m_classChild.style = CS_DBLCLKS;

}

ChildWindowToMainWindow::~ChildWindowToMainWindow()
{
    //dtor
}

LONG APIENTRY ChildWindowToMainWindow::MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

    RECT RectClient;
    switch(msg)
    {

    case WM_CREATE:
    CreateWindowEx(
                   0,
                   m_szChildClassName,
                   "ChildWindow",
                   WS_OVERLAPPEDWINDOW,
                   CW_USEDEFAULT,
                   CW_USEDEFAULT,
                   500, 400,
                   MainWindow::m_hwnd,
                   NULL,
                hChildInstance,
                    NULL
                    );
    return 0;
                case WM_SIZE:

                GetClientRect(hwnd, &RectClient);
               EnumChildWindows(hwnd, EnumChildProc,
                (LPARAM) &RectClient);
            return 0;


    }
    return DefWindowProc(hwnd, msg, wParam, lParam);

    }

BOOL CALLBACK ChildWindowToMainWindow::EnumChildProc(HWND hwndChild, LPARAM lParam)
{

    
    rcParent = (LPRECT) lParam;
    MoveWindow(hwndChild,

       

    /* Make sure the child window is visible. */

    ShowWindow(hwndChild, SW_SHOW);

    return TRUE;
}

}


Heres where am im having the problem and its probably because I dont understand exactly what im doing here.

1
2
3
4
5
6
 case WM_SIZE:

                GetClientRect(hwnd, &RectClient);
               EnumChildWindows(hwnd, EnumChildProc,
                (LPARAM) &RectClient);
            return 0;



Im doing something Wrong with the EnumChildWindows. Im getting this error:
C:\Users\Owner\Desktop\Computer\MainProject\ChildWindowToMainWindow.cpp|57|error:



argument of type 'BOOL (ChildWindowToMainWindow::)(HWND__*, LPARAM)' does not match 'BOOL (*)(HWND__*, LPARAM)'


If someone could tell me exactly what im doing wrong here and explain what exactly EnumChildWindows Does i would be very thankful. Thank you :D
Hi edumoette,

EnumChildWindows() will walk the tree of child windows belonging to a parent window (given by the hwnd param), and call the user-supplied EnumChildProc for each child window (and children-of-children, etc.)

The compiler is complaining because EnumChildProc() is a member-function (as seen in the ChildWindowToMainWindow:: part of the error message) , while EnumChildWindows() expects a free function.

You need to make your EnumChildProc static, and pass it any instance-specific data in its LPARAM (if required).

Also, I'm a little confused about your setup... your C++ class wraps the parent window, but registers the same MainWndProc with the child window-class? Won't this create a recursion, where the child window gets WM_CREATE, and creates another child in turn, etc.?


Topic archived. No new replies allowed.