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

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

DWORD WINAPI AptThreadProc (LPVOID lpv)
{

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

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

/*
Initialize COM on this thread.
*/

	CoInitializeEx (NULL, COINIT_APARTMENTTHREADED) ;

/*
Create MDI Child window
*/


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

	PostMessage (hMdiClient, WM_MDITILE, MDITILE_HORIZONTAL , 0) ;


/*
Set flag to say it's apartment.
*/


	SetWindowLong (hChild, 0, FALSE) ;

/*
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);	   
	}


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