Does anyone can help me with the MDI ?!

Pages: 12
May 15, 2020 at 12:08pm
I have an MDI created and it works until I press on menu new file and I get this error message I wrote on message box.. that the New MDI child creation failed this is the part where the compiler says Local mcs. szClass "Cannot acces memory at adress 0xcdbaabcd"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
HWND CreateNewMDIChild(HWND hMDIClient)
{
    MDICREATESTRUCT mcs;
    HWND hChild;

    mcs.szTitle     = "New";
    mcs.szClass     = ChildClass;
    mcs.hOwner      = GetModuleHandle(NULL);
    mcs.x = mcs.cx  = CW_USEDEFAULT;
    mcs.y = mcs.cy  = CW_USEDEFAULT;
    mcs.style       = MDIS_ALLCHILDSTYLES;

    hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);
    if(!hChild)
    {
        MessageBox(hMDIClient, "New MDI child creation failed !", "Error", MB_ICONERROR | MB_OK);
    }
    return hChild;
}


Well I looked for 2 days and can't figure out what is the matters.. cause all I wrote is perfect...
Does anyone have an idea why the MDI child doesn't start. ?!
Last edited on May 15, 2020 at 12:09pm
May 15, 2020 at 12:12pm
If the rest of the code is needed I can post it right away..
May 15, 2020 at 12:14pm
Where and how is ChildClass declared and defined, is it registered?
Last edited on May 15, 2020 at 12:14pm
May 15, 2020 at 12:17pm
yes at the very first time//... ok le'me upload all the code.. cause when I compiling I have no errors .. is just the MDI child doesn't want to create
May 15, 2020 at 12:23pm
OK, I personally prefer CreateMDIWindowW

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
hMDIClient = CreateMDIWindowW(
			ChildClass,
			L"Sample MDI",
			MDIS_ALLCHILDSTYLES,
			x, y,
			width,
			height,
			hMDIClient,
			nullptr);

if (!IsWindow(hMDIClient))
{
         MessageBoxW(
                hMDIClient,
                std::to_wstring(GetLastError()).c_str()",
                L"Error",
                MB_ICONERROR | MB_OK);
} 
Last edited on May 15, 2020 at 12:27pm
May 15, 2020 at 12:27pm
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include <windows.h>
#include <commctrl.h>
#include "resource.h"

#define IDC_MAIN_MDI        300
#define IDC_MAIN_STATUS     301
#define IDC_CHILD_STATIC1   101

#define ID_MDI_FIRSTCHILD   50000

const char MainClass[]  = "myWindowClass";
const char ChildClass[] = "myMDIChildWindowClass";

HWND hMDIClientWindow   = NULL;
HWND hMainWindow        = NULL;

HWND CreateNewMDIChild(HWND hMDIClient)
{
    MDICREATESTRUCT mcs;
    HWND hChild;

    mcs.szTitle     = "Act 1";
    mcs.szClass     = ChildClass;
    mcs.hOwner      = GetModuleHandle(NULL);
    mcs.x = mcs.cx  = CW_USEDEFAULT;
    mcs.y = mcs.cy  = CW_USEDEFAULT;
    mcs.style       = MDIS_ALLCHILDSTYLES;

    hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);
    if(!hChild)
    {
        MessageBox(hMDIClient, "Act 1 MDI child creation failed !", "Error", MB_ICONERROR | MB_OK);
    }
    return hChild;
}

LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_CREATE:
        {
            // Create Static control
            HFONT hfDefault;
            HWND hStatic1;

            hStatic1 = CreateWindowEx(WS_EX_CLIENTEDGE, "static", "",
                                      WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
                                      0, 0, 100, 100, hwnd, (HMENU)IDC_CHILD_STATIC1,
                                      GetModuleHandle(NULL), NULL);

            if(hStatic1 == NULL)
            {
                MessageBox(hwnd, "Could not create Static control !", "Error",
                           MB_ICONERROR | MB_OK);
            }

            hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
            SendMessage(hStatic1, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
        }
        break;
    case WM_MDIACTIVATE:
        {
            HMENU hMenu, hFileMenu;
			UINT EnableFlag;

			hMenu = GetMenu(hMainWindow);
			if(hwnd == (HWND)lParam)
			{	   //being activated, enable the menus
				EnableFlag = MF_ENABLED;
			}
			else
			{	   //being de-activated, gray the menus
				EnableFlag = MF_GRAYED;
			}

			EnableMenuItem(hMenu, 1, MF_BYPOSITION | EnableFlag);
			EnableMenuItem(hMenu, 2, MF_BYPOSITION | EnableFlag);

			hFileMenu = GetSubMenu(hMenu, 0);
			EnableMenuItem(hFileMenu, ID_FILE_CLOSE, MF_BYCOMMAND | EnableFlag);

			DrawMenuBar(hMainWindow);
        }
        break;
    case WM_SIZE:
        {
            // Calculate remaining height and size edit
            HWND hStatic1;
            RECT rcClient;

            GetClientRect(hwnd, &rcClient);

            hStatic1 = GetDlgItem(hwnd, IDC_CHILD_STATIC1);
            SetWindowPos(hStatic1, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
        }
        return DefMDIChildProc(hwnd, msg, wParam, lParam);
    default:
        return DefMDIChildProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

BOOL SetUpMDIChildWindowClass(HINSTANCE hInst)
{
    WNDCLASSEX wc;

    wc.cbClsExtra       = 0;
    wc.cbSize           = sizeof(WNDCLASSEX);
    wc.cbWndExtra       = 0;
    wc.hbrBackground    = (HBRUSH)(COLOR_3DFACE + 3);
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon            = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);
    wc.hIconSm          = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);
    wc.hInstance        = hInst;
    wc.lpfnWndProc      = MDIChildWndProc;
    wc.lpszClassName    = ChildClass;
    wc.lpszMenuName     = NULL;
    wc.style            = CS_HREDRAW | CS_VREDRAW;

    if(!RegisterClassEx(&wc))
    {
        MessageBox(0, "Could not register child window !", "Error",
                   MB_ICONERROR | MB_OK);
        return FALSE;
    }
    else
        return TRUE;
}

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_PAINT:
        break;
    case WM_CREATE:
        {
            /// Create MDI client ///////////////////////////////////

            ////////// Find window menu where children will be listed
            CLIENTCREATESTRUCT ccs;

            ccs.hWindowMenu  = GetSubMenu(GetMenu(hwnd), 2);
            ccs.idFirstChild = ID_MDI_FIRSTCHILD;

            hMDIClientWindow = CreateWindowEx(WS_EX_CLIENTEDGE, "mdiclient", NULL,
                            WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
                            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                            hwnd, (HMENU)IDC_MAIN_MDI, GetModuleHandle(NULL), (LPVOID)&ccs);

            if(hMDIClientWindow == NULL)
            {
                MessageBox(hwnd, "Could not create MDI client !", "Error", MB_ICONERROR | MB_OK);
            }

            // Create Status bar
            HWND hStatus;
            int statwidths[] = {140, 300, -1};

            hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
                            WS_VISIBLE | WS_CHILD | SBARS_SIZEGRIP,
                            0, 0, 0, 0, hwnd, (HMENU)IDC_MAIN_STATUS, GetModuleHandle(NULL), NULL);

            SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);

            SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)" Author:      Me");
            SendMessage(hStatus, SB_SETTEXT, 1, (LPARAM)"                 - MDI2 - ");
            SendMessage(hStatus, SB_SETTEXT, 2, (LPARAM)"                  May 2020");
        }
        break;
    case WM_SIZE:
        {
            // Size status bar and get height
            HWND hStatus;
            RECT rcStatus;
            int iStatusHeight;

            hStatus = GetDlgItem(hwnd, IDC_MAIN_STATUS);
            SendMessage(hStatus, WM_SIZE, 0, 0);
            GetWindowRect(hStatus, &rcStatus);
            iStatusHeight = rcStatus.bottom - rcStatus.top;

            // Calculate remaining height and size static
            HWND hMDI;
            RECT rcClient;
            int iMDIHeight;

            GetClientRect(hwnd, &rcClient);

            iMDIHeight = rcClient.bottom - iStatusHeight;

            hMDI = GetDlgItem(hwnd, IDC_MAIN_MDI);
            SetWindowPos(hMDI, NULL, 0, 0, rcClient.right, iMDIHeight, SWP_NOZORDER);

        }
        break;
    case WM_COMMAND:
        switch(LOWORD(wParam))
        {
        case ID_FILE_CLOSE:
            {
                HWND hChild = (HWND)SendMessage(hMDIClientWindow, WM_MDIGETACTIVE, 0, 0);
                if(hChild)
                {
                    SendMessage(hChild, WM_CLOSE, 0, 0);
                }
            }
            break;
        case ID_FILE_EXIT:
            PostMessage(hwnd, WM_CLOSE, 0, 0);
            break;
        case ID_FILE_ACT1:
            CreateNewMDIChild(hMDIClientWindow);
            break;
        case ID_WINDOW_TILE:
            SendMessage(hMDIClientWindow, WM_MDITILE, 0, 0);
            break;
        case ID_WINDOW_CASCADE:
            SendMessage(hMDIClientWindow, WM_MDICASCADE, 0, 0);
            break;
        default:
            {
                if(LOWORD(wParam) >= ID_MDI_FIRSTCHILD)
                {
                    DefFrameProc(hwnd, hMDIClientWindow, WM_COMMAND, wParam, lParam);
                }
                else
                {
                    HWND hChild = (HWND)SendMessage(hMDIClientWindow, WM_MDIGETACTIVE, 0, 0);
                    if(hChild)
                    {
                        SendMessage(hChild, WM_COMMAND, wParam, lParam);
                    }
                }
            }
        }
        break;
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefFrameProc(hwnd, hMDIClientWindow, msg, wParam, lParam);
    }
    return 0;
}
May 15, 2020 at 12:28pm
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
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    InitCommonControls();

    wc.cbClsExtra       = 0;
    wc.cbSize           = sizeof(WNDCLASSEX);
    wc.cbWndExtra       = 0;
    wc.hbrBackground    = (HBRUSH)(COLOR_WINDOW);
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon            = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);
    wc.hIconSm          = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);
    wc.hInstance        = hInst;
    wc.lpfnWndProc      = MainWndProc;
    wc.lpszClassName    = MainClass;
    wc.lpszMenuName     = MAKEINTRESOURCE(IDR_MAINMENU);
    wc.style            = 0;


    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window registration failed !", "Error",
                   MB_ICONERROR | MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(0, MainClass, "MDI2",
                          WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_CLIPCHILDREN, // -> Window(The Frame) Style
                          250, 90, 900, 600, NULL, NULL, hInst, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Failed to create window !", "Error",
                   MB_ICONERROR | MB_OK);
        return 0;
    }

    hMainWindow = hwnd;
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        if(!TranslateMDISysAccel(hMDIClientWindow, &Msg))
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    }
    return Msg.wParam;
}
May 15, 2020 at 1:06pm
The debugger complains because it can't read memory, it can't read because you did bad cast.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
HWND CreateNewMDIChild(HWND hMDIClient)
{
	MDICREATESTRUCT mcs;
	HWND hChild;

	mcs.szTitle = "Act 1";
	mcs.szClass = ChildClass;
	mcs.hOwner = GetModuleHandle(NULL);
	mcs.x = mcs.cx = CW_USEDEFAULT;
	mcs.y = mcs.cy = CW_USEDEFAULT;
	mcs.style = MDIS_ALLCHILDSTYLES;

        hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);
	
	if (!hChild)
	{
		ShowError(ERR_BOILER);
		MessageBox(hMDIClient, "Act 1 MDI child creation failed !", "Error", MB_ICONERROR | MB_OK);
	}
	return hChild;
}


This is wrong:
hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);

It should be this:
hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, reinterpret_cast<LPARAM>(&mcs));

EDIT:
A hint to prevent such trouble in the future is to never use C style casts, and enable all warnings in your IDE so that compiler can give you a warning for you to solve. ie. a warning about incompatible data conversion.
Last edited on May 15, 2020 at 1:13pm
May 15, 2020 at 1:37pm
Okay.. thank you very much.. but i get same error even if I change the cast..
and I have another MDI1 that uses the same WNDCLASS EX and is quite the same structure

But the problem is that the MDI1 is working fine.. and it has the same cast and is creating the child window with the same cast I mean this one:

 
hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);


becose all I have did is to copy and paste without some codes parts that will include DoSaveFile and DoOpenFIle, and I renamed the class name of the main and child win. in the rest is the same thing.. That's pretty strange..
May 15, 2020 at 1:46pm
I'm unable to reproduce your problem, because I don't have resource definition of a menu.
It worked just fine with the change of a cast here, and commenting out some code.

Can you zip up your entry project, upload it to http://www.tinyupload.com/
and send a link here.

just make sure you clean it first, to avoid uploading build output.
Last edited on May 15, 2020 at 1:48pm
May 15, 2020 at 2:16pm
Seems like it take an eternity to upload a few Kb of zip.. I'll wait some minutes , if it doesn't I'll send you here the .h and .rc files .. so you can save and include in the .cpp and then compile..
May 15, 2020 at 2:20pm
ok, if you have one drive or google drive should be ok.
just don't upload it to dropbox or similar.

or just c/p rc and resource.h here. and what's needed to for clean compile.
May 15, 2020 at 2:23pm
No chance file Zip stuck in Upload process.. but here are resource definition:
This is the .rc file
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//Microsoft
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS


/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (Canada) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENC)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_CAN
#pragma code_page(1252)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE DISCARDABLE
BEGIN
    "#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
    "#include ""windows.h""\r\n"
    "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
    "\0"
END

3 TEXTINCLUDE DISCARDABLE
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

IDR_MAINMENU MENU DISCARDABLE
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "Close",   ID_FILE_CLOSE,   GRAYED
        MENUITEM "&Exit",   ID_FILE_EXIT
    END
    POPUP "&Quests"
    BEGIN
        MENUITEM "&Act 1",   ID_FILE_ACT1
        MENUITEM "&Act 2",   ID_FILE_ACT2
        MENUITEM "&Act 3",   ID_FILE_ACT3
        MENUITEM "&Act 4",   ID_FILE_ACT4
        MENUITEM "&Act 5",   ID_FILE_ACT5
    END
    POPUP "&Window",    GRAYED
    BEGIN
        MENUITEM "&Tile",    ID_WINDOW_TILE
        MENUITEM "&Cascade", ID_WINDOW_CASCADE
    END
END

#endif    // English (Canada) resources
/////////////////////////////////////////////////////////////////////////////
///////////////////////////
// Icon


IDI_ICON    ICON    "WinMDI2.ico"

#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED 


And this is the .h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
///used by resource.rc

#define IDR_MAINMENU        102

#define ID_FILE_EXIT        201
#define ID_FILE_ACT1        202
#define ID_FILE_ACT2        203
#define ID_FILE_ACT3        204
#define ID_FILE_ACT4        205
#define ID_FILE_ACT5        206
#define ID_WINDOW_TILE      207
#define ID_WINDOW_CASCADE   208
#define ID_FILE_CLOSE       209

#define IDI_ICON        900 


..see if it works
Last edited on May 15, 2020 at 2:24pm
May 15, 2020 at 2:44pm
You can put a random icon in the main folder and renamed "WinMDI2" WinMDI2.ico
May 15, 2020 at 2:58pm
Yes already figured out thanks ;)

Well problem is you didn't register window class for MDI child window.

Inside your MainWndProc WM_CREATE put this code at the end of WM_CREATE:

SetUpMDIChildWindowClass(GetModuleHandleA(NULL));

This will register MDI child window once for the duration of the program, note that you must call this function after MDI client was created, otherwise it will fail. (that is at the end of your WM_CREATE)

Also do not ignore casting to LPARAM instead of LONG, it works for you maybe because you compile 32bit application, but it WILL FAIL for x64 bit program.


So your WM_CREATE should looke like this:

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
	case WM_CREATE:
	{
		/// Create MDI client ///////////////////////////////////

		////////// Find window menu where children will be listed
		CLIENTCREATESTRUCT ccs;

		ccs.hWindowMenu = GetSubMenu(GetMenu(hwnd), 2);
		ccs.idFirstChild = ID_MDI_FIRSTCHILD;

		hMDIClientWindow = CreateWindowEx(WS_EX_CLIENTEDGE, "mdiclient", NULL,
			WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
			CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			hwnd, (HMENU)IDC_MAIN_MDI, GetModuleHandle(NULL), (LPVOID)&ccs);

		if (hMDIClientWindow == NULL)
		{
			MessageBox(hwnd, "Could not create MDI client !", "Error", MB_ICONERROR | MB_OK);
		}

		// Create Status bar
		HWND hStatus;
		int statwidths[] = { 140, 300, -1 };

		hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
			WS_VISIBLE | WS_CHILD | SBARS_SIZEGRIP,
			0, 0, 0, 0, hwnd, (HMENU)IDC_MAIN_STATUS, GetModuleHandle(NULL), NULL);

		SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths) / sizeof(int), (LPARAM)statwidths);

		SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)" Author:      Me");
		SendMessage(hStatus, SB_SETTEXT, 1, (LPARAM)"                 - MDI2 - ");
		SendMessage(hStatus, SB_SETTEXT, 2, (LPARAM)"                  May 2020");


                // registering MDI after client window is made here!
		SetUpMDIChildWindowClass(GetModuleHandleA(NULL));

	}


and please cast to LPARAM because that's what the function expectes:

hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LPARAM)&mcs);
Last edited on May 15, 2020 at 3:08pm
May 15, 2020 at 3:18pm
Ohhh man... thank you so much. It works just fine.

Now.. I just wanna ask you a last question...

Indeed the the MDI child window wasn't registered.. but why the first MDI1 is working and I don't have that line I mean in WM_CREATE I didn't wrote that line .. well I didn't register the MDI child and still it works..
very very strange..

Thanks malibor.. this is indeed a fine day... :)
May 15, 2020 at 3:19pm
And yes my compiler is 32 bit... but i did change the cast like you said..
May 15, 2020 at 3:27pm
but why the first MDI1 is working and I don't have that line

Maybe we should ask Microsoft for implementation on how MDI client handles WM_MDICREATE message.

I know only that it calls CreateWindow internally, but no clue how and if it registers the window, probably as private class or existing system class, not visible to your program, IDK. but worth investigating if you want.

I'm glad it worked!


Last edited on May 15, 2020 at 3:30pm
May 15, 2020 at 3:38pm
But yes yes.. here I found something that I miss when I first create the Main window I mean the Frame MDI...

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
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    InitCommonControls();

    wc.cbClsExtra       = 0;
    wc.cbSize           = sizeof(WNDCLASSEX);
    wc.cbWndExtra       = 0;
    wc.hbrBackground    = (HBRUSH)(COLOR_WINDOW);
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon            = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);
    wc.hIconSm          = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);
    wc.hInstance        = hInst;
    wc.lpfnWndProc      = MainWndProc;
    wc.lpszClassName    = MainClass;
    wc.lpszMenuName     = MAKEINTRESOURCE(IDR_MAINMENU);
    wc.style            = 0;


    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window registration failed !", "Error",
                   MB_ICONERROR | MB_OK);
        return 0;
    }
    if(!SetUpMDIChildWindowClass(hInstance))
		return 0;

    hwnd = CreateWindowEx(0, MainClass, "MDI2",
                          WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_CLIPCHILDREN, // -> Window(The Frame) Style
                          250, 90, 900, 600, NULL, NULL, hInst, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Failed to create window !", "Error",
                   MB_ICONERROR | MB_OK);
        return 0;
    }

    hMainWindow = hwnd;
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        if(!TranslateMDISysAccel(hMDIClientWindow, &Msg))
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    }
    return Msg.wParam;
}


this my friend:
if(!SetUpMDIChildWindowClass(hInstance))
return 0;
was in the Main window... and that is what i miss... and yes now on MDI2 i don't have it there but I have it in the WM_CREATE.. so yes it has to be registered.
But however you did save my day...
Thanks a lot.. cheers
May 15, 2020 at 3:44pm
OK, it's the same thing,

Btw. Your Frame Window doesn't need WS_CLIPCHILDRENstyle
and not even the MDI client needs that style.

Pages: 12