Desperate: SendMessage fails with WM_MDICREATE

Hi all:

I've been debugging with my MDI app for one bug:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
        MDICREATESTRUCT mcs;
	HWND hChild;

	mcs.szTitle = L"[Untitled]";
	mcs.szClass = MDI_CHILD_WND_NAME;
	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 == NULL)
	{
		MessageBox(hMDIClient, L"Failed to create MDI Child", L"Error",
			MB_ICONEXCLAMATION | MB_OK);
	}


The MDI client window shows up correctly. I've also double checked hMDIClient is having the correct value, i.e. it is indeed the handle to the MDI client window. But why does it always fail to create MDI child window?

I'm stuck on this single issue for more than 20 hours. Please help if you can!
Thanks.
Last edited on
Does it work this way ?
hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LPARAM)(LPMDICREATESTRUCT)mcs);
@modoran:
Thanks for your reply.

It doesn't work.
Compiler (vs 2008) gives me this:
error C2440: 'type cast' : cannot convert from 'MDICREATESTRUCT' to 'LPMDICREATESTRUCT'


I think the problem doesn't lie in the syntax. I guess I would need someone to point out some common mistake newbies make (I can't give an example because I am a newbie).


My understanding is,
hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);
sends message WM_MDICREATE to hMDIClient, which is the client window. The window procedure of the client window is defined by the system in WM_CREATE case in the MDI frame window procedure
MDI_CLIENT_WND = CreateWindowEx(WS_EX_CLIENTEDGE, L"mdiclient", NULL, WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU)IDC_CLIENT_WND, GetModuleHandle(NULL), (LPVOID)&ccs);

So the system-defined client window should automatically create a child window when it receives my WM_MDICREATE message. But it doesn't. I don't understand what can possibly go wrong.

I've got it.
Never mind. It was a very silly mistake of mine. I actually want to share with you some experience/tech behind the issue, but the issue doesn't have any tech element behind it at all! The only thing I can say is, look at the code globally when you find nothing's wrong with a local routine.

In addition, I really want to say "FU*K"! For this silly thing I lost so much time.
Topic archived. No new replies allowed.