logotype

A developer library to enhance Flash ActiveX features

What is F-IN-BOX?

F-IN-BOX is a window control to enhance Macromedia / Adobe Flash Player ActiveX features. It does not use its own engine to display movies but provide a wrapper around official swflash.ocx/flash.ocx code instead. Thus it is possible to avoid certain Macromedia / Adobe Flash Player ActiveX limitations.

Macromedia / Adobe Flash Player ActiveX 3, 4, 5, 6, 7, 8, 9, 10 are supported.

Features

Load flash movies from memory directly (no temporary files!). Protect your flash movies.
Create flash-enabled applications which are ready to work even when the Macromedia / Adobe Flash Player ActiveX is not installed!
Transparency is fully supported!
Ability to play Flash Video (FLV) directly from memory
Enable/disable flash sounds
Adjust sound volume
Get a snap image of the current flash movie frame
Flash External API
Use a flash movie as a dynamic texture in DirectX applications.
Write code which is compatible with any version of Macromedia / Adobe Flash Player ActiveX (3, 4, 5, 6, 7, 8, 9, 10).

Load flash movies from memory directly (no temporary files!). Protect your flash movies.

Download sample code

It is known fact that the Flash Player ActiveX is able to load movies at certain URLs only. You have to save the movie to a temporary location from your application's resource before you can load it. You'll have to generate a corresponding link that you can pass to the Flash Player ActiveX and then delete the movie after. You'll have to admit that this is extremely inconvenient. Apart from being inconvenient there is a chance you'll fail when you try to create a temporary file if you don't have the appropriate permission or don't have access to a temporary folder. It is definitely not an appropriate approach when security is an issue since your movie can be easily intercepted. There is a solution! F-IN-BOX uses a different approach of swflash.ocx/flash.ocx code loading. It is able to load your movies directly to the Macromedia / Adobe Flash Player ActiveX thereby avoiding the temporary file step. The advantages are pretty obvious. And you can also protect your movies from unauthorized access using your favourite software protection application.

Using the control you can load any flash movie from memory directly. Just use the FPCM_LOADMOVIEFROMMEMORY and FPCM_PUTMOVIEFROMMEMORY messages. No temporary files! Load any movie on-the-fly from any supported source. For example, you can put one or more flash movies in the resource section of your application and then load it from the exe! That's the portability and power of F-IN-BOX!

Here's an example of how to load a flash movie from a resource:

Download sample code

[ C++ ]
HFPC hFPC = FPC_LoadRegisteredOCX();

if (NULL == hFPC)
    return;

HWND hwndFlashPlayerControl = 
   FPC_CreateWindow(hFPC, 
                    0, 
                    NULL, 
                    WS_CHILD | WS_VISIBLE, 
                    nLeft, 
                    nTop, 
                    nWidth, 
                    nHeight, 
                    hWnd, 
                    NULL, 
                    NULL, 
                    NULL)

HMODULE hModule = GetModuleHandle(NULL);
HRSRC hResInfo = 
   FindResource(hModule, _T("EmbeddedMovie"), _T("FLASH"));
HGLOBAL hResData = LoadResource(hModule, hResInfo);
LPVOID lpMovieData = LockResource(hResData);
DWORD dwMovieSize = SizeofResource(hModule, hResInfo);

SFPCPutMovieFromMemory sFPCPutMovieFromMemory;

sFPCPutMovieFromMemory.lpData = lpMovieData;
sFPCPutMovieFromMemory.dwSize = dwMovieSize;

::SendMessage(hwndFlashPlayerControl, 
              FPCM_PUTMOVIEFROMMEMORY, 
              0, 
              (LPARAM)&sFPCPutMovieFromMemory);

Download sample code

Back to top | Ask a question

Create flash-enabled applications which are ready to work even when the Macromedia / Adobe Flash Player ActiveX is not installed!

Download sample code

One of the biggest problem using the Flash Player ActiveX is the mandatory component registration. The common approach is to save swflash.ocx/flash.ocx code to temporary files and then register them. The disadvantages are the same as above mentioned - insufficient permissions to save and register an swflash.ocx/flash.ocx. Now you can forget about these problems! F-IN-BOX is able to use swflash.ocx/flash.ocx from any source. For example, you can put an swflash.ocx/flash.ocx code inside of your application's resources and instruct F-IN-BOX to use it. It is important to note that F-IN-BOX does not use temporary files and swflash.ocx/flash.ocx registration but loads and uses the code directly. No more user management rights problems - no more temporary files and no more component registrations. It is up to you to decide what swflash.ocx/flash.ocx to use - by default already registered component is used.

Traditionally, there are many obstacles or annoyances that one will encounter when using Macromedia / Adobe Flash Player ActiveX in an application.

The Application...

  1. needs swflash.ocx/flash.ocx installed in the system before it will work.
  2. has to work flawlessly with the already installed version of the Macromedia / Adobe Flash Player ActiveX.
  3. has no easy way to prevent flash movies from being abused.

F-IN-BOX to the rescue. It solves these problems and more!

By default, the component will use the swflash.ocx/flash.ocx that's already installed on the system. The component can alternatively use any swflash.ocx/flash.ocx that you would like to provide it with using any supported source. An example of this how you can embed the flash.ocx into the resource section of your application's exe file and then load it at runtime. Using this method, your application will work even if the Macromedia / Adobe Flash Player ActiveX doesn't exist on the target system. Just use RegisterFlashWindowClassEx function! With F-IN-BOX, hassling around with Macromedia / Adobe Flash Player ActiveX installation issues are a thing the past! It's so easy to do! There are even demos provided which come complete with source code to prove it!

Here's an example of how to load swflash.ocx/flash.ocx code from a resource:

Download sample code

[ C++ ]
HMODULE hModule = GetModuleHandle(NULL);
HRSRC hResInfo = FindResource(hModule, _T("FLASH_OCX_CODE"), _T("BIN"));
HGLOBAL hResData = LoadResource(hModule, hResInfo);
LPVOID lpFlashOCXCode = LockResource(hResData);
DWORD dwFlashOCXCodeSize = SizeofResource(hModule, hResInfo);

HFPC hFPC = FPC_LoadOCXFromMemory(lpFlashOCXCodeData, dwFlashOCXCodeSize);

if (NULL == hFPC)
{
    // Error
}        

Download sample code

Here's an example of how to load swflash.ocx/flash.ocx code from a file:

Download sample code

[ C++ ]
HANDLE hFile = CreateFile(_T("flash.ocx"), 
                          GENERIC_READ, 
                          FILE_SHARE_READ, 
                          NULL, 
                          OPEN_EXISTING, 
                          FILE_ATTRIBUTE_NORMAL, 
                          NULL);

DWORD dwFlashOCXCodeSize = GetFileSize(hFile, NULL);

HANDLE hFileMapping = CreateFileMapping(hFile, 
                                        NULL, 
                                        PAGE_READONLY, 
                                        0, 
                                        dwFlashOCXCodeSize, 
                                        NULL);

LPVOID lpFlashOCXCodeData = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);

HFPC hFPC = FPC_LoadOCXFromMemory(lpFlashOCXCodeData, dwFlashOCXCodeSize);

if (NULL == hFPC)
{
    // Error
}        

UnmapViewOfFile(lpFlashOCXCodeData);
CloseHandle(hFileMapping);
CloseHandle(hFile);

Download sample code

Back to top | Ask a question

Transparency is fully supported!

Download sample code

Using F-IN-BOX you are able to create applications based on transparent flash movies. You can create applications with translucency non-rectangle windows. Use Flash to make applications with modern user interface. See the code:

Download sample code

[ C++ ]
HFPC hFPC = FPC_LoadRegisteredOCX();

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

HWND hwndFlashPlayerControl = 
   FPC_CreateWindow(hFPC, 
                    WS_EX_LAYERED, 
                    NULL, 
                    WS_POPUP | WS_VISIBLE, 
                    nLeft, 
                    nTop, 
                    nWidth, 
                    nHeight, 
                    hWnd, 
                    NULL, 
                    NULL, 
                    NULL)

ShowWindow(hwndFlashPlayerControl, SW_SHOW);

UpdateWindow(hwndFlashPlayerControl);

Download sample code

Please note that form transparency is supported only under Win2k (or higher), 16 / 32 bpp display mode. To check if the transparency is supported use global function FPCIsTransparentAvailable:

Download sample code

[ C++ ]
if (!FPCIsTransparentAvailable()) 
{ 
    // Transparent mode is not available 
}

Download sample code

Back to top | Ask a question

Ability to play Flash Video (FLV) from memory

Download sample code

Using F-IN-BOX you are able to play Flash Video (FLV) from external files, URL or directly from memory. When F-IN-BOX loads Flash Video no temporary files are created everything runs directly from memory. You can encrypt your video and put into application's resource - F-IN-BOX loads FLV without ever saving or extracting the file to disk.

To play Flash Video from memory you should create flash movie that loads Flash Video from "private" URL (http://FLV/FlashVideo.flv). Flash Movie uses the following code to load Flash Video (put this in under a button in your Swf Flash Movie):

Download sample code

[ ActionScript ]
var netConn:NetConnection = new NetConnection(); 
netConn.connect(null); 
var netStream:NetStream = new NetStream(netConn); 
my_video.attachVideo(netStream); 
netStream.setBufferTime(0); 
netStream.play("http://FLV/FlashVideo.flv");

Download sample code

When Flash tries to load Flash Video from http://FLV/FlashVideo.flv, F-IN-BOX provides content of FLV. Use function FPC_AddOnLoadExternalResourceHandler to handle the external resources and provide them to Flash. See the code:

Download sample code

[ C++ ]
HFPC hFPC = FPC_LoadRegisteredOCX();

FPC_AddOnLoadExternalResourceHandler(hFPC, &GlobalOnLoadExternalResourceHandler, 0);

HRESULT WINAPI StaticGlobalOnLoadExternalResourceHandler(
    LPCTSTR lpszURL, 
    IStream** ppStream, 
    HFPC hFPC, 
    LPARAM lParam)
{
	HRESULT hr = E_FAIL;

	if (0 == lstrcmpi(lpszURL, _T("http://FLV/FlashVideo.flv")))
	{
		// Save flash video to the stream from the resource
		HMODULE hModule = GetModuleHandle(NULL);
		HRSRC hResInfo = FindResource(hModule, _T("EMBEDDED_FLV"), _T("FLV"));
		HGLOBAL hResData = LoadResource(hModule, hResInfo);
		LPCVOID lpData = LockResource(hResData);
		DWORD dwSize = SizeofResource(hModule, hResInfo);

		ULONG nWritten;
		(*ppStream)->Write(lpData, dwSize, &nWritten);

		hr = S_OK;
	}

	return hr;
}

Download sample code

Back to top | Ask a question

Enable/disable flash sounds

Download sample code

Using the library you can turn on/off all sounds in all loaded flash movies that belong to the same HFPC.

  1. Use function FPC_EnableSound to enable/disable the sounds.
  2. Use function FPC_IsSoundEnabled to get current status of sounds enabling.

Download sample code

[ C++ ]
void Mute()
{
   FPC_EnableSound(hFPC, FALSE);
}

Download sample code

Back to top | Ask a question

Adjust sound volume

Download sample code

Using the library you can adjust sound volume of all loaded flash movies that belong to the same HFPC. To set volume call FPC_SetSoundVolume.

Download sample code

Back to top | Ask a question

Get a snap image of the current flash movie frame

Download sample code

You can get a bitmap image from the current frame of a flash movie. It means you are able create applications that can coverts Flash movies to a series of bitmaps, JPEGs and others. Also you can build generated images to make an AVI video for example.

Download sample code

[ C++ ]
#include <atlimage.h>
...
SFPCGetFrameBitmap FPCGetFrameBitmap = { 0 }; 

::SendMessage(g_hwndFlashPlayerControl, 
             FPCM_GET_FRAME_BITMAP, 
             0, 
             (LPARAM)&FPCGetFrameBitmap); 

HBITMAP hBitmap = FPCGetFrameBitmap.hBitmap; 

if (NULL != hBitmap) 
{ 
    CImage Image; 
    Image.Attach(hBitmap); 
    Image.Save(_T("Frame.bmp")); 
    Image.Detach(); 
    DeleteObject(hBitmap); 
}

Download sample code

Back to top | Ask a question

Flash External API

Download sample code

F-IN-BOX supports External API. You can call functions of a movie and a movie is able to get data from an application synchronously (instead of fscommand).

Call an ActionScript function from an application

Register your function using ExternalInterface.addCallback:

Download sample code

[ ActionScript ]
import flash.external.*; 

ExternalInterface.addCallback("CallMeFromApplication", this, InternalFunction); 

function InternalFunction(str: String): String { 
   TextArea1.text = str; 
   return "The function was called successfully"; 
}

Download sample code

Use function FPCCallFunction or FPCCallFunctionBSTR:

Download sample code

[ C++ ]
WCHAR szRequest[1024] = { 0 }; 

lstrcatW(szRequest, L("<invoke name=\"CallMeFromApplication\""));
lstrcatW(szRequest, L("returntype=\"xml\">"));
lstrcatW(szRequest, L("<arguments><string>"));
lstrcatW(szRequest, L("Some text for F-IN-BOX"));
lstrcatW(szRequest, L("</string></arguments></invoke>");

BSTR bstrRequest = SysAllocString(szRequest);

BSTR bstrResponse; 

if (S_OK == 
    FPCCallFunctionBSTR(m_hwndFlashPlayerControl, 
                        bstrRequest, 
                        &bstrResponse)) 
{ 
    USES_CONVERSION; 

    CString str = OLE2T(bstrResponse); 
    AfxMessageBox(CString(_T("The function returned: ")) + str); 

    SysFreeString(bstrResponse); 
} 

SysFreeString(bstrRequest);

Download sample code

[ C++ ]
TCHAR szResponse[1024] = { 0 }; 

DWORD dwLength = sizeof(szResponse) / sizeof(szResponse[0]) - 1; 

TCHAR szRequest[1024] = { 0 }; 

lstrcat(szRequest, _T("<invoke name=\"CallMeFromApplication\""));
lstrcat(szRequest, _T("returntype=\"xml\">"));
lstrcat(szRequest, _T("<arguments><string>"));
lstrcat(szRequest, _T("Some text for F-IN-BOX"));
lstrcat(szRequest, _T("</string></arguments></invoke>");

FPCCallFunction(m_hwndFlashPlayerControl, 
                szRequest, 
                szResponse, 
                &dwLength); 

AfxMessageBox(CString(_T("The function returned: ")) + szResponse);

Download sample code

Call an application function from a flash script

Use flash.external.ExternalInterface.call:

Download sample code

[ ActionScript ]
on (click) { 
   _root.TextArea1.text = flash.external.ExternalInterface.call("SomeFunction"); 
}

Download sample code

Handle notification FPCN_FLASHCALL:

Download sample code

[ C++ ]
LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{ 
    if (WM_NOTIFY == message) 
    { 
        LPNMHDR lpNMHDR = (LPNMHDR)lParam; 

        if (m_hwndFlashPlayerControl == lpNMHDR->hwndFrom) 
            switch (lpNMHDR->code) 
            { 
                case FPCN_FLASHCALL: 
                { 
                    SFPCFlashCallInfoStruct* pInfo = (SFPCFlashCallInfoStruct*)lpNMHDR; 

                    CString str; 
                    str += _T("The request is: '"); 
                    str += pInfo->request; 
                    str += _T("'"); 

                    AfxMessageBox(str); 

                    COleDateTime now = COleDateTime::GetCurrentTime(); 
                    FPCSetReturnValue(m_hwndFlashPlayerControl, 
_T("<string>Current time is: ") + 
now.Format() + 
_T("\r\nThis info is returned from the handler</string>")); 

                    return 1; 
            } 
        } 
...

}

Download sample code

Back to top | Ask a question

Use a flash movie as a dynamic texture in DirectX applications.

Download sample code

You can get semitransparent bitmap images from a flash movie. It means you are able create a dynamic texture for your DirectX application.

Download sample code


Movie
Texture based on the flash movie
Texture based on the flash movie

Download sample code

[ C++ ]
#define DEF_WIDTH (128) 
#define DEF_HEIGHT (128) 

HWND g_hwndFlashPlayerControl; 
...

HFPC hFPC = FPC_LoadRegisteredOCX(); 

// Create FlashPlayerControl as a hidden child control 
// in transparent mode (see style FPCS_TRANSPARENT) 
g_hwndFlashPlayerControl = 
    CreateWindow((LPCTSTR)FPC_GetClassAtom(hFPC), 
                 NULL, 
                 WS_CHILD | FPCS_TRANSPARENT, 
                 0, 
                 0, 
                 DEF_WIDTH, 
                 DEF_HEIGHT, 
                 hWnd, 
                 NULL, 
                 NULL, 
                 NULL); 

// Load movie from resource 
FPCPutMovieFromResource(g_hwndFlashPlayerControl, NULL, _T("SWF1"), _T("SWF")); 
// Play 
FPC_Play(g_hwndFlashPlayerControl); 
...

// Creates texture from current frame 
LPDIRECT3DTEXTURE8 CreateTextureFromFlash() 
{ 
    LPDIRECT3DTEXTURE8 pTexture = NULL; 

    D3DXCreateTexture(g_PDIRECT3DDEVICE8, 
                      DEF_WIDTH, 
                      DEF_HEIGHT, 
                      1, 
                      0, 
                      D3DFMT_A8R8G8B8, 
                      D3DPOOL_MANAGED, 
                      &pTexture); 
                      
    if (NULL == pTexture) 
        return pTexture; 

    D3DSURFACE_DESC d3dsd; 
    pTexture->GetLevelDesc(0, &d3dsd); 

    MoveWindow(g_hwndFlashPlayerControl, 
               0, 
               0, 
               d3dsd.Width, 
               d3dsd.Height, 
               TRUE); 

    SIZE size = { d3dsd.Width, d3dsd.Height }; 

    D3DLOCKED_RECT rcLockedRect = { 0 }; 
    RECT rc = { 0, 0, size.cx, size.cy }; 

    pTexture->LockRect(0, &rcLockedRect, &rc, D3DLOCK_DISCARD); 

    SFPCGetFrameBitmap FPCGetFrameBitmap = { 0 }; 

    ::SendMessage(g_hwndFlashPlayerControl, 
                  FPCM_GET_FRAME_BITMAP, 
                  0, 
                  (LPARAM)&FPCGetFrameBitmap); 

    HBITMAP hBitmap = FPCGetFrameBitmap.hBitmap; 

    BITMAP bmp_info; 
    GetObject(hBitmap, sizeof(bmp_info), &bmp_info); 

    BYTE* pTextureBits = (BYTE*)rcLockedRect.pBits; 

    DWORD* pBitmapBits = (DWORD*)bmp_info.bmBits; 

    BYTE* pLineTextureBits = pTextureBits; 

    for (int j = 0; j < size.cy; j++) 
    { 
        DWORD* pPixels = (DWORD*)pLineTextureBits; 

        for (int i = 0; i < size.cx; i++) 
        { 
            *pPixels = *pBitmapBits; 

            pPixels++; 
            pBitmapBits++; 
        } 

        pLineTextureBits += rcLockedRect.Pitch; 
    } 

    DeleteObject(hBitmap); 

    pTexture->UnlockRect(0); 

    return pTexture; 
}

Download sample code

Back to top | Ask a question

Write code which is compatible with any version of Macromedia / Adobe Flash Player ActiveX (3, 4, 5, 6, 7, 8, 9, 10).

Download sample code

One of the problem with Macromedia / Adobe Flash Player ActiveX programming is that you have to control what version of Macromedia / Adobe Flash Player ActiveX you are using. For example, the property "Stacking" exists only in Macromedia / Adobe Flash Player ActiveX 5 but doesn't exist in later revisions. TFlashPlayerControl automatically detects what Macromedia / Adobe Flash Player ActiveX version is being used and prevents failure if access to non existant properties/methods is attempted. Applications using TFlashPlayerControl are not only compatible with Macromedia / Adobe Flash Player ActiveX 3, 4, 5, 6, 7, 8, 9, 10, but are also "smart" about how Macromedia / Adobe Flash Player ActiveX control is used. This makes your application more robust which can result in fewer technical support issues.

Back to top | Ask a question

Copyright © 2004 – 2014 Softanics. All rights reserved.
F-IN-BOX ® is a trademark of Softanics and Artem A. Razin
Delphi is a trademark of Embarcadero Technologies, Inc.. Macromedia and Shockwave Flash are trademarks of Adobe, Inc.