// Sample4_Translucency.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Sample4_Translucency.h"
#include "TransparentFlashPlayerControlWnd.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CSample4_TranslucencyApp

BEGIN_MESSAGE_MAP(CSample4_TranslucencyApp, CWinApp)
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()


// CSample4_TranslucencyApp construction

CSample4_TranslucencyApp::CSample4_TranslucencyApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}


// The one and only CSample4_TranslucencyApp object

CSample4_TranslucencyApp theApp;


// CSample4_TranslucencyApp initialization

BOOL CSample4_TranslucencyApp::InitInstance()
{
	// InitCommonControls() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	InitCommonControls();

	CWinApp::InitInstance();

	AfxEnableControlContainer();

	//
	if (!FPCIsFlashInstalled())
	{
		AfxMessageBox(_T("The application needs Flash\nFlash is not installed"));
		return FALSE;
	}

	if (!RegisterFlashWindowClass())
	{
		AfxMessageBox(_T("RegisterFlashWindowClass() failed"));
		return FALSE;
	}

	if (!FPCIsTransparentAvailable())
	{
		AfxMessageBox(_T("Flash Transparent is not available"));
		return FALSE;
	}

	RECT rc = { 0, 0, 640, 480 };

	/*
	    Note about WS_EX_LAYERED:

		#if(_WIN32_WINNT >= 0x0500)
		#define WS_EX_LAYERED           0x00080000

		You should define _WIN32_WINNT to make WS_EX_LAYERED available for compiler
		See stdafx.h
	*/

	// FlashPlayerControl creating
	// NOTE: CALL RegisterFlashWindowClass() or RegisterFlashWindowClassEx() before creating!

	HWND hwndFlashPlayerControl = 
		CreateWindowEx(WS_EX_LAYERED, 
					   WC_FLASH, 
					   NULL, 
					   WS_POPUP | WS_VISIBLE, 
					   rc.left, 
					   rc.top, 
					   rc.right - rc.left, 
					   rc.bottom - rc.top, 
					   NULL, 
					   NULL, 
					   NULL, 
					   NULL);

	CTransparentFlashPlayerControlWnd* pFlashProjectorWnd = new CTransparentFlashPlayerControlWnd;
	pFlashProjectorWnd->SubclassWindow(hwndFlashPlayerControl);
	pFlashProjectorWnd->SetWindowText(_T("Sample 4 - Translucency"));
	pFlashProjectorWnd->CenterWindow();
	pFlashProjectorWnd->ShowWindow(SW_SHOW);
	pFlashProjectorWnd->UpdateWindow();

	// Also you can use FPCM_LOADMOVIEFROMMEMORY
	// FPCLoadMovieFromResource is useful for loading from resources, 
	// use FPCM_LOADMOVIEFROMMEMORY to load movie from any memory block
	FPCLoadMovieFromResource(hwndFlashPlayerControl, 0, 0, _T("MOVIE"), _T("SWF"));

	// Disable standard flash context menu
	SFPCPutStandartMenu FPCPutStandartMenu;
	FPCPutStandartMenu.StandartMenu = VARIANT_FALSE;
	SendMessage(hwndFlashPlayerControl, FPCM_PUT_STANDART_MENU, 0, (LPARAM)&FPCPutStandartMenu);

	m_pMainWnd = pFlashProjectorWnd;

	return TRUE;
}
