#include <windows.h>
#include "resource.h"

extern HINSTANCE hInst;
extern HWND  hMainWnd ;
extern HWND  hMdiClient ;

DWORD WINAPI FreeThreadProc (LPVOID lpv)
{

/*
Find current thread ID and convert to a string
*/

	char name [256] ;
	wsprintf (name, "Free Thread, ID == 0x%x", GetCurrentThreadId( )) ;

/*
Initialize COM on this thread.
*/

	CoInitializeEx (NULL, COINIT_MULTITHREADED) ;

/*
Create MDI Child window
*/


	HWND hChild = CreateMDIWindow ("FreeChildClass", name, 
		WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CAPTION,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
		hMdiClient, hInst, NULL) ;

	PostMessage (hMdiClient, WM_MDITILE, MDITILE_HORIZONTAL , 0) ;


/*
Set flag to say that it's free
*/

	SetWindowLong (hChild, 0, TRUE) ;
/*
Set advise sink pointer to NULL
*/


	SetWindowLong (hChild, 4, 0) ;

/*
Acquire and dispatch messages until a WM_QUIT message is received.
*/

	MSG msg ;

	while (GetMessage(&msg, NULL, NULL, NULL))	
	{
	 	TranslateMessage(&msg);	  
		DispatchMessage(&msg);	
	}


/*
Uninitialize COM in this thread.
*/
	 
	CoUninitialize ( ) ;	
	return 0 ;
}