IonicWind Software

Aurora Compiler => Software Projects => Topic started by: JR on April 18, 2006, 07:10:39 AM

Title: ShockWave Flash Demo
Post by: JR on April 18, 2006, 07:10:39 AM
Uses ATL to embed an instance of ShockWave Flash in a window and plays a movie.

An small video is provided in the attached zipped file for testing purposes.


#use "atl.lib"
#use "uuid.lib"

struct GUID,1
{
  unsigned int data1;
  unsigned word data2;
  unsigned word data3;
  unsigned byte data4[8];
}

extern _IID_IDispatch as GUID;

interface IUnknown
{
    declare virtual QueryInterface(GUID *riid, void *ppvObject), int;
    declare virtual AddRef(), unsigned int;
    declare virtual Release(), unsigned int;
}

interface IDispatch : IUnknown
{
    declare virtual GetTypeInfoCount(unsigned int *pctinfo),int;
    declare virtual GetTypeInfo(unsigned int iTInfo, int lcid, pointer *ppTInfo),int;
    declare virtual GetIDsOfNames(GUID *riid, unsigned word *rgszNames, unsigned int cNames, int lcid, int *rgDispID),int;
    declare virtual Invoke(int dispIdMember, GUID *riid, int lcid, unsigned word wFlags, pointer *pDispParams, pointer *pVarResult, pointer *pExcepInfo, unsigned int *puArgErr),int;
}

interface IShockwaveFlash : IDispatch
{
    declare virtual get_ReadyState(int *pVal), int;
    declare virtual get_TotalFrames(int *pVal), int;
    declare virtual get_Playing(word *pVal), int;
    declare virtual put_Playing(word pVal), int;
    declare virtual get_Quality(int *pVal), int;
    declare virtual put_Quality(int pVal), int;
    declare virtual get_ScaleMode(int *pVal), int;
    declare virtual put_ScaleMode(int pVal), int;
    declare virtual get_AlignMode(int *pVal), int;
    declare virtual put_AlignMode(int pVal), int;
    declare virtual get_BackgroundColor(int *pVal), int;
    declare virtual put_BackgroundColor(int pVal), int;
    declare virtual get_Loop(word *pVal), int;
    declare virtual put_Loop(word pVal), int;
    declare virtual get_Movie(/*BSTR*/ pointer *pVal), int;
    declare virtual put_Movie(/*BSTR*/ pointer *pVal), int;
    declare virtual get_FrameNum(int *pVal), int;
    declare virtual put_FrameNum(int pVal), int;
    declare virtual SetZoomRect(int left, int top, int right, int bottom), int;
    declare virtual Zoom(int factor), int;
    declare virtual Pan(int x, int y, int mode), int;
    declare virtual Play(), int;
    declare virtual Stop(), int;
    declare virtual Back(), int;
    declare virtual Forward(), int;
    declare virtual Rewind(), int;
    declare virtual StopPlay(), int;
    declare virtual GotoFrame(int FrameNum), int;
    declare virtual CurrentFrame(int *FrameNum), int;
    declare virtual IsPlaying(word *Playing), int;
    declare virtual PercentLoaded(int *percent), int;
    declare virtual FrameLoaded(int FrameNum, word *loaded), int;
    declare virtual FlashVersion(int *version), int;
    declare virtual get_WMode(/*BSTR*/ pointer *pVal), int;
    declare virtual put_WMode(/*BSTR*/ pointer *pVal), int;
    declare virtual get_SAlign(/*BSTR*/ pointer *pVal), int;
    declare virtual put_SAlign(/*BSTR*/ pointer *pVal), int;
    declare virtual get_Menu(word *pVal), int;
    declare virtual put_Menu(word pVal), int;
    declare virtual get_Base(/*BSTR*/ pointer *pVal), int;
    declare virtual put_Base(/*BSTR*/ pointer *pVal), int;
    declare virtual get_Scale(/*BSTR*/ pointer *pVal), int;
    declare virtual put_Scale(/*BSTR*/ pointer *pVal), int;
    declare virtual get_DeviceFont(word *pVal), int;
    declare virtual put_DeviceFont(word pVal), int;
    declare virtual get_EmbedMovie(word *pVal), int;
    declare virtual put_EmbedMovie(word pVal), int;
    declare virtual get_BGColor(/*BSTR*/ pointer *pVal), int;
    declare virtual put_BGColor(/*BSTR*/ pointer *pVal), int;
    declare virtual get_Quality2(/*BSTR*/ pointer *pVal), int;
    declare virtual put_Quality2(/*BSTR*/ pointer *pVal), int;
    declare virtual LoadMovie(int layer, /*BSTR*/ pointer *url), int;
    declare virtual TGotoFrame(/*BSTR*/ pointer *target, int FrameNum), int;
    declare virtual TGotoLabel(/*BSTR*/ pointer *target, /*BSTR*/ pointer *plabel), int;
    declare virtual TCurrentFrame(/*BSTR*/ pointer *target, int *FrameNum), int;
    declare virtual TCurrentLabel(/*BSTR*/ pointer *target, /*BSTR*/ pointer *pVal), int;
    declare virtual TPlay(/*BSTR*/ pointer *target), int;
    declare virtual TStopPlay(/*BSTR*/ pointer *target), int;
    declare virtual SetVariable(/*BSTR*/ pointer *name, /*BSTR*/ pointer *value), int;
    declare virtual GetVariable(/*BSTR*/ pointer *name, /*BSTR*/ pointer *pVal), int;
    declare virtual TSetProperty(/*BSTR*/ pointer *target, int property, /*BSTR*/ pointer *value), int;
    declare virtual TGetProperty(/*BSTR*/ pointer *target, int property, /*BSTR*/ pointer *pVal), int;
    declare virtual TCallFrame(/*BSTR*/ pointer *target, int FrameNum), int;
    declare virtual TCallLabel(/*BSTR*/ pointer *target, /*BSTR*/ pointer *plabel), int;
    declare virtual TSetPropertyNum(/*BSTR*/ pointer *target, int property, double value), int;
    declare virtual TGetPropertyNum(/*BSTR*/ pointer *target, int property, double *pVal), int;
    declare virtual TGetPropertyAsNumber(/*BSTR*/ pointer *target, int property, double *pVal), int;
    declare virtual get_SWRemote(/*BSTR*/ pointer *pVal), int;
    declare virtual put_SWRemote(/*BSTR*/ pointer *pVal), int;
    declare virtual get_FlashVars(/*BSTR*/ pointer *pVal), int;
    declare virtual put_FlashVars(/*BSTR*/ pointer *pVal), int;
    declare virtual get_AllowScriptAccess(/*BSTR*/ pointer *pVal), int;
    declare virtual put_AllowScriptAccess(/*BSTR*/ pointer *pVal), int;
    declare virtual get_MovieData(/*BSTR*/ pointer *pVal), int;
    declare virtual put_MovieData(/*BSTR*/ pointer *pVal), int;
    declare virtual get_InlineData(IUnknown *ppIUnknown), int;
    declare virtual put_InlineData(IUnknown pIUnknown), int;
    declare virtual get_SeamlessTabbing(word *pVal), int;
    declare virtual put_SeamlessTabbing(word pVal), int;
}

import unsigned int CreateWindowEx alias CreateWindowExA(
  unsigned int dwExStyle,
  unsigned byte *lpClassName,
  unsigned byte *lpWindowName,
  unsigned int dwStyle,
  int x,
  int y,
  int nWidth,
  int nHeight,
  unsigned int hWndParent,
  unsigned int hMenu,
  unsigned int hInstance,
  void *lpParam
);

import unsigned int GetModuleHandle alias GetModuleHandleA(unsigned byte *lpModuleName);
import int MoveWindow(unsigned int hWnd, int X, int Y, int nWidth, int nHeight, int bRepaint);
import void RtlZeroMemory(void *Destination, unsigned int Length);

import int MultiByteToWideChar(
  unsigned int CodePage,          // code page
  unsigned int dwFlags,           // character-type options
  unsigned byte *lpMultiByteStr,  // string to map
  int cbMultiByte,                // number of bytes in string
  unsigned word *lpWideCharStr,   // wide-character buffer
  int cchWideChar                 // size of buffer
);

import int WideCharToMultiByte(
  unsigned int CodePage,            // code page
  unsigned int dwFlags,             // performance and mapping flags
  unsigned word *lpWideCharStr,     // wide-character string
  int cchWideChar,                  // number of chars in string.
  unsigned byte *lpMultiByteStr,    // buffer for new string
  int cbMultiByte,                  // size of buffer
  unsigned byte *lpDefaultChar,     // default for unmappable chars
  unsigned int *lpUsedDefaultChar   // set when default char used
);

import pointer SysAllocString(pointer *sz);
import void SysFreeString(pointer *bstr);
import unsigned int SysStringLen(pointer *bstr);
import int lstrlenW(unsigned word *lpwcs);

sub AnsiToUnicode(string psz), heap
{
    int hr;
    int nLen;
    pointer pwcs;

    nLen = (len(psz) + 1) * 2;
    pwcs = AllocHeap(nLen);
    RtlZeroMemory(pwcs, nLen);
    hr = MultibyteToWideChar(0, 0, psz, len(psz), pwcs, nLen);
    return pwcs;
}

sub UnicodeToAnsi(pointer *pwcs), string
{
    int nLen;
    pointer psz;

    nLen = lstrlenW(pwcs);
    psz = AllocHeap(nLen);
    RtlZeroMemory(psz, nLen);
    nLen = WideCharToMultibyte(0, 0, pwcs, -1, psz, nLen, 0, 0);
    return psz;
}

import int AtlAxWinInit();
import int AtlAxGetControl(unsigned int hWnd, IUnknown *pUnk);

// TestFlash definition
class TestFlash : CWindow
{
    declare virtual OnClose(),int;
    declare virtual OnCreate(),int;
    declare virtual OnSize(int nType,int cx,int cy),int;
    unsigned int m_ctl;
}

global sub main()
{
    TestFlash win;
    win.Create(0, 0, 600, 400,
               AWS_VISIBLE|AWS_SYSMENU|AWS_SIZE|AWS_MINIMIZEBOX| \
               AWS_MAXIMIZEBOX|AWS_AUTODRAW|AWS_CLIPCHILDREN,
               0, "Test Shockwave Flash", null);

    unsigned int hInst;
    hInst = GetModuleHandle(null);

    AtlAxWinInit();  // Initialize ATL
    rc = win.GetClientRect();
    win.m_ctl = CreateWindowEx (0, "AtlAxWin", "ShockwaveFlash.ShockwaveFlash",
                                AWS_VISIBLE|AWS_CHILD|AWS_BORDER,
                                rc.left + 5, rc.top + 5,
                                rc.right - rc.left - 10, rc.bottom - rc.top - 10,
                                win.m_hwnd,
                                1, // control id
                                hInst,
                                null);

    int hr = 0;
    IUnknown *pUnk = null;
    IShockwaveFlash *pFlash = null;

    // Obtains a direct interface pointer to the control contained
    // inside a specified window given its handle.
    hr = AtlAxGetControl(win.m_ctl, &pUnk);
    if (hr = 0)
    {
        // Obtains the dispatch interface pointer of the control
        hr = pUnk->QueryInterface(_IID_IDispatch, &pFlash);
        // Release the IUnknown pointer (no longer needed)
        pUnk->Release();
        if (hr = 0)
        {
            // Set the path of the movie (must be a fully qualified path)
            pbstrPath = SysAllocString(AnsiToUnicode(GetStartPath() + "choudanse7.swf"));
            pFlash->put_Movie(pbstrPath);
            SysFreeString(pbstrPath);
            // Rotate the video
//            pbstrName = SysAllocString(AnsiToUnicode("_rotation"));
//            pbstrValue = SysAllocString(AnsiToUnicode("10"));
//            pFlash->SetVariable(pbstrName, pbstrValue);
//            SysFreeString(pbstrName);
//            SysFreeString(pbstrValue);
            // Modify the video transparency
//            pbstrName = SysAllocString(AnsiToUnicode("_alpha"));
//            pbstrValue = SysAllocString(AnsiToUnicode("50"));
//            pFlash->SetVariable(pbstrName, pbstrValue);
//            SysFreeString(pbstrName);
//            SysFreeString(pbstrValue);
            // Modify the scale and position
//            pbstrName = SysAllocString(AnsiToUnicode("_xscale"));
//            pbstrValue = SysAllocString(AnsiToUnicode("50"));
//            pFlash->SetVariable(pbstrName, pbstrValue);
//            SysFreeString(pbstrName);
//            SysFreeString(pbstrValue);
//            pbstrName = SysAllocString(AnsiToUnicode("_yscale"));
//            pbstrValue = SysAllocString(AnsiToUnicode("50"));
//            pFlash->SetVariable(pbstrName, pbstrValue);
//            SysFreeString(pbstrName);
//            SysFreeString(pbstrValue);
//            pbstrName = SysAllocString(AnsiToUnicode("_x"));
//            pbstrValue = SysAllocString(AnsiToUnicode("80"));
//            pFlash->SetVariable(pbstrName, pbstrValue);
//            SysFreeString(pbstrName);
//            SysFreeString(pbstrValue);
//            pbstrName = SysAllocString(AnsiToUnicode("_y"));
//            pbstrValue = SysAllocString(AnsiToUnicode("40"));
//            pFlash->SetVariable(pbstrName, pbstrValue);
//            SysFreeString(pbstrName);
//            SysFreeString(pbstrValue);
            // Play the movie
            pFlash->Play();
            // Release the interface
            pFlash->Release();
        }
    }

    do{ wait();} until !win.IsValid();
}

TestFlash::OnCreate()
{
    CenterWindow();
    return 0;
}

TestFlash::OnClose()
{
    Destroy();
    return 0;
}

TestFlash::OnSize(int nType,int cx,int cy),int
{
    if (m_ctl != 0)
    {
        rc = GetClientRect();
        MoveWindow(m_ctl, rc.left + 5, rc.top + 5, rc.right - rc.left - 10, rc.bottom - rc.top - 10, true);
    }
    return true;
}
Title: Re: ShockWave Flash Demo
Post by: Ionic Wind Support Team on April 18, 2006, 08:44:56 AM
You can also use AddControlEx and create a bound control that is directly compatible with Aurora's windows too.


win.AddControlEx("AtlAxWin", "ShockwaveFlash.ShockwaveFlash", rc.left + 5, rc.top + 5,
                                rc.right - rc.left - 10, rc.bottom - rc.top - 10,AWS_VISIBLE|AWS_CHILD|AWS_BORDER,0,1);

Title: Re: ShockWave Flash Demo
Post by: Mkey on May 21, 2006, 08:28:56 AM
Hello,

Really interresting.

Did you try to set the Wmode to transaparent????

I would like to have a transparent movie.

Thanks.
Title: Re: ShockWave Flash Demo
Post by: JR on May 21, 2006, 09:10:43 AM
The put_WMode property is not available at run-time. You will need to create an stream, fill it with the name and value of the property and create the controll with AtlAxCreateControl, one of whose parameters is a pointer to an stream that is used to initialize the properties of the control. To create an stream is easy, but currently I don't have precise information of how exactly the information has to be written in it to work.
Title: Re: ShockWave Flash Demo
Post by: Mkey on May 21, 2006, 02:56:20 PM
Quote from: JosÃÆ'Ã,© Roca on May 21, 2006, 09:10:43 AM
The put_WMode property is not available at run-time. You will need to create an stream, fill it with the name and value of the property and create the controll with AtlAxCreateControl, one of whose parameters is a pointer to an stream that is used to initialize the properties of the control. To create an stream is easy, but currently I don't have precise information of how exactly the information has to be written in it to work.


It s something I search for since a long time ago. I search too how to read with flash control a movie only from stream without have it on the disk for example to read it from a database blobstream ...
I wasn't able to do it with Delphi. I'm new with Aurora, (or C++).

If you have any information or links (all you have C++, ..., too) please post it.

Thanks a lot.
Title: Re: ShockWave Flash Demo
Post by: Pip1957 on November 28, 2008, 03:11:24 AM
Would it be possible for someone to convert this program to Ebasic
Title: Re: ShockWave Flash Demo
Post by: Pip1957 on November 30, 2008, 07:54:17 AM
No takers then  ???
Title: Re: ShockWave Flash Demo
Post by: sapero on November 30, 2008, 08:47:42 AM
Hey Pip, here is your code for Emergence 8)
Title: Re: ShockWave Flash Demo
Post by: Pip1957 on November 30, 2008, 09:19:15 AM
As always Sapero you the best ;D
Title: Re: ShockWave Flash Demo
Post by: Pip1957 on December 01, 2008, 03:00:10 AM
Sapero thank you for the code at the moment it is way over my head, would it be possible to rewrite it without using classes what I need is to be able to open a flash control or window in a dialog that would close by button and leave the dialog open, again thank you for the code will keep studying it.
Title: Re: ShockWave Flash Demo
Post by: sapero on December 01, 2008, 05:50:18 AM
Sure, but you can convert it too, just move code from method into window handler case.
Title: Re: ShockWave Flash Demo
Post by: Pip1957 on December 01, 2008, 06:23:36 AM
Thank you sapero this I can understand :D
Title: Re: ShockWave Flash Demo
Post by: pistol350 on December 01, 2008, 06:58:42 AM
LOL.
I can confirm that it's easier to understand now  ;D