Home

SWF Scout

SWF Scout screenshot (click to enlarge)



SWF Scout ActiveX/NET library

see also: How to display flash animation in VC++ application

How to create SWF animation movie file from Visual C++ using SWF Scout library: 

"Hello, World!" example
 

You can download the source code of this example here: swfscout_vc.zip

See also: adding PNG image (visual c++ source code) - swfscout_add_png_visual_c.zip (100 KB)

This tutorial will teach you how to create simple SWF flash movie animation from VC++ using SWF Scout library.

1) Install SWF Scout library on your computer and run Visual C++
2) Select the "New.." command from "File" menu (as it is shown below) to run  :
File menu in VC IDE
 
3)The  New Project Wizard dialog will appear on the screen. Select "Win32 Console Application" project type and enter "HelloWorld" as the Project name as shown on the screenshot below:
 
VC new project wizard
Set new project name and click OK
 
4) The wizard will ask what kind of Console Application you want to create. Select  A "Hello, World!" application and click Finish:
 
Select new project type
 
VC++ will show the summary information for a new project. Click OK:
 
New project summary
 
Visual C++ will generate the application code for simple console application
 
Source code editor window will appear. To edit main() function just open the class tree on the left and double click on "H elloWorld Classes" | "Globals" | "main (int argc, char* argv[1])":
 
Main function in code editor
 
VC++ will open main() function: 
 
Code editor window
 
5) To use SWF Scout from  VC++ application you have to tell the compiler to import type library information into the project.
 
To import the type library just add #import compiler directive after #include directive:
 
#import "SWFScout.tlb"
using namespace SWFScout;
 
and then HelloWorld.cpp will look like this:
 
Hello World project code editor window
 
6) The code snippet that will generate SWF flash animation should be placed in main() function body. 
 
// HelloWorld.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
 
#import "SWFScout.tlb"
using namespace SWFScout;
 
int main(int argc, char* argv[])
{
       // initialize OLE
       HRESULT hr = CoInitialize(NULL);
 
       // check for errors
       if (FAILED(hr)) {
       MessageBox(0,"OLE initialization errp","error",MB_OK);
       return -1;
       }
       // declare SWFScout object
       IFlashMovie* Movie = NULL;
       long Shape, Font, Text;
       CLSID clsid;
 
       // get inuque ID for IFlashMovie interface
       hr = CLSIDFromProgID(OLESTR("SWFScout.FlashMovie"), &clsid);
       // check for errors
       if (FAILED(hr)) {
       MessageBox(0,"Can't get CLSID for interface","error",MB_OK);
       goto Uninit;
       };
       // create FlashMovie object
       hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL,__uuidof(IFlashMovie), (LPVOID*)&Movie);
       // check for errors
       if (FAILED(hr)) {
       MessageBox(0,"Can't create Movie object","error",MB_OK);
       goto Uninit;
       }
 
       // initialize library
       Movie->InitLibrary("demo", "demo");
       // start movie generation
       Movie->BeginMovie(0,0,640,480, 1, 12,6);
       // start document generation
 
       Font = Movie->AddFont("Arial", 18, true, false, false, false, 0); // add font
       // create and place text
       Text = Movie->AddText("Hello, World!", 0, 0, 0, 255, Font, 0, 100, 250, 160);
       Movie->PlaceText(Text, Movie->CurrentMaxDepth); // place text into current depth
       Movie->PLACE_FadeOut(0.5); // fade out text
       Shape = Movie->AddShape(); // add new shape
       Movie->SHAPE_Rectangle (0, 140, 150, 285); // draw rectangle
       Movie->SHAPE_SetSolidColor(50, 255, 50, true, 255); // set solid fill for shape
 
       Movie->PlaceShape(Shape, Movie->CurrentMaxDepth); // place shape into current depth
       Movie->ShowFrame(10); // show 10 frames
       Movie->EndMovie(); // end movie generation
       Movie->SaveToFile("c:\\Shapes.swf"); // save generated SWF into file
 
       // disconnect from library
       Movie->Release();
       // uninitialize OLE libraries
       Uninit:
       CoUninitialize();
       return 0;
}
This code will generate SWF flash animation file that will be saved as "c:\shapes.swf" file
 
Hint: 
 
you can simply copy and paste the code from the sample above into VC++ code editor window:
 
Code editor with new code
 
7) Run the application by pressing F5 (or use  "Build" | "Debug" | "Go")
VC++ will compile and run "Hello, World!" application. It will generate Shapes.swf file on C:\ disk 
 
You can view generated flash file (.SWF) using Internet Explorer or another application that is capable of viewing and playing of  flash animations.
 
SWF generated by VC project
 

You can download the source code of this example here: swfscout_vc.zip

See also: adding PNG image (visual c++ source code) - swfscout_add_png_visual_c.zip (100 KB)


Products  |  Download  |  Purchase  |  Support  |  Contacts  |  Testimonials |  

ByteScout, 2003-2008. All other company and product names may be trademarks of their respective companies. Privacy Statement