Create MDI child from dll

Started by
7 comments, last by Haggdahl 17 years, 5 months ago
I've been developing a control which combines a MDI Client and a Tab Control, one similar to the one VS uses. After writing it as a regular project I decided to write it as a dll to make it easier to use in future projects. The dll creates a MDI Client and a Tab Control in the parent window, but when I'm calling CreateMDIWindow the HWND is NULL and GetLastError returns 8 (ERROR_NOT_ENOUGH_MEMORY). The call for CreateMDIWindow is made within the dll. What's wrong?! Appreciate any comments! / Olle Häggdahl
Advertisement
Can you post the code where you call this function?
Here's the whole Add function!
Hope it'll help.
Thanks!

void CMDITabControl::AddItem(LPSTR lpWndTitle){	HWND hWndChild;	TCITEM ti;	CWnd *wnd = NULL;	wnd = new CWnd;	hWndChild = CreateMDIWindow(		g_strChildWndClass,		lpWndTitle,		WS_MAXIMIZE,		0, 0, 0, 0,		m_hWndMDIClient,		m_hInstWorkspace,		NULL		);	if(!hWndChild)	{		MessageBox(m_hWndWorkspace, "Child window creation failed!", "MDITabControl Error!", MB_ERROR);		SAFE_DELETE(wnd);		return;	}	// Show the tab control if it was previously hidden	if(m_nSize == 0)	{		ShowWindow(m_hWndTab, SW_SHOW);		ShowWindow(m_CloseBtn.m_hWnd, SW_SHOW);	}	// Add to our tab control	ti.mask = TCIF_TEXT;	ti.pszText = lpWndTitle;		SendMessage(m_hWndTab, TCM_INSERTITEM, 0, (LPARAM)(LPTCITEM)&ti);	SendMessage(m_hWndTab, TCM_SETCURSEL, 0, 0);	// Insert in our window list and increase size	wnd->m_hWnd = hWndChild;	wnd->m_pNext = m_pFirst;	m_pFirst = wnd;	m_nSize++;}


[Edited by - Haggdahl on October 22, 2006 2:10:39 PM]
Looks awful with tabsize 0:S
Edit your post to use [ source ] [ /source ] tags.

Are you sure that the parameters to CreateMDIWindow() are correct? Where are you getting m_hInstWorkspace?

Also, for style and clarity, I recommend you use CW_USEDEFAULT rather than zeros if you want the default size and position.
Thanks for the advice with tags!

As you can see the window is maximized and will stay maximized as long as it's visible, so the zeros doesn't matter.
The m_hInstWorkspace is defined in Init(), which is given the HINSTANCE from the parent when called. But I recently discovered that the HINSTANCES shouldn't matter
because their value is, almost always, 0x00400000. (some standard in Win32, see "http://blogs.msdn.com/oldnewthing/archive/2006/05/05/590749.aspx" which says some concerning Win32 and HINSTANCES)
And the rest of the parameters should be all right. This is very confusing.

/ Olle
You should probably be using the HINSTANCE that was used when registering the window class.
I am=/
I've got it now. Skipped registering the class in the dll and now it works. Don't really know what was wrong. Thanks anyway!

This topic is closed to new replies.

Advertisement