Create a Flash control in MFC and load the SWF from the memory stream

Source: Internet
Author: User
Tags rewind

#include <atlbase.h>extern CComModule _module; #include <atlcom.h> #include <oleacc.h> #include <comdef.h> #pragma comment (lib, "ATL") #pragma Comment (lib, "User32.lib") #import "C:\WINDOWS\system32\Macromed\Flash\Flash32_11_5_502_135.ocx" using namespace shockwaveflashobjects; #pragma pack (push, 1) typedef struct _flash_stream_header{&nbsp;&nbsp;&nbsp; DWORD m_dwsignature;&nbsp;&nbsp;&nbsp; DWORD M_dwdatasize;} Flash_stream_header, *pflash_stream_header; #pragma pack (POP)
BOOL cflashtest::initinstance () {... CoInitialize (NULL); AtlAxWinInit ();}
Flash initialization .... crect rc; GetClientRect (&AMP;RC);static cwnd wnd; Bool bret = wnd. CreateControl ("Shockwaveflash.shockwaveflash", "flash", ws_child| ws_visible,rc,this,0x223); ccomptr<ishockwaveflash> spflash; Lpunknown punknow = wnd. GetControlUnknown ();p unknow->queryinterface (__uuidof (Ishockwaveflash), (void **) &spFlash); Hrsrc hres = findresource (NULL, (LPCTSTR) idr_swf1, "SWF");if  (hres) {dword  Dwresourcedatasize = sizeofresource (Null,hres); Hglobal hresourceloaded = ::loadresource (null, hres);istream *spstream; Hresult hresult = ::createstreamonhglobal (Null, true, &spstream); flash_stream_header fsh = {0x55665566, dwresourcedatasize}; ularge_integer uli = {sizeof  (FSH)  + dwResourceDataSize};hResult =  Spstream->setsize (ULI); Hresult = spstream->write (&AMP;FSH,&NBSP;SIZEOF&NBSP; (FSH),  null); Hresult = spstream->write (Reinterpret_cast<void*> (hResourceLoaded),  dwresourcedatasize, null); Uli. Quadpart = 0;hresult = spstream->seek (*reinterpret_cast<plarge_integer> (&uli) ,  stream_seek_set, null); Ccomptr<ipersiststreaminit> sppersiststreaminit; spflash.queryinterface (& Sppersiststreaminit); Sppersiststreaminit->load (Spstream);} ...
Cflashtest::~cflashtest () {... CoUninitialize (NULL);}

---------------------------------------------------------------------------

Properties:
1.AlignMode (read/write)
Syntax: Alignmode as Long
Description: Alignment, linkage with the Salign property. When the height-to-width ratio of a control is inconsistent with the movie and WMode is not exactfit, the position of the movie (not magnified) in the control can be adjusted by that property. The property value consists of a flag bit. , set the corresponding alignment direction by marking the corresponding bit in the attribute value (binary) as 1. The property value is aligned with the corresponding alignment. The binary number is in the parentheses behind it.
1: Align Left (0001)
2: Right-justified (0010)
4: Top-aligned (0100)
8: Bottom-aligned (1000)
You can also combine the various alignments and mark two or more bits as 1, which is the combination of the four base values. For example, left and top aligned at the same time, the attribute value is set to 5 (0101).
Example: Set the movie to right-justified:
Movie. Alignmode = 2

2.SAlign (read/write)
Syntax: Salign as String
Description: Alignment mode (linkage with Alignmode). When Alignmode
When a bit is set to "1" on behalf of each alignment mode, the Salign value is also
A combination of "L" (left), "T" (Top), "R" (right), "B" (Bottom) characters. The order of ' L ', ' T ', ' R ', ' B ' is the same.
Example: Set the movie to align left and top:
Movie. Salign = "LT"

3.BackgroundColor (read/write)
Syntax: BackgroundColor as Long
Description: The background color of the film (linked with BGColor). Calculates the color value (red x65536 + green x256 + blue). The value range of red, green and blue color (0-255). The default movie background color is-1. If the movie has an undertone or a picture as the background, then it doesn't see how the change in the property value will affect it.
Example: Set the movie background color to blue:
Movie. BackgroundColor = 255


4.BGColor (read/write)
Syntax: BGColor as String
Description: The background color of the film (linked with BackgroundColor). Unlike BackgroundColor, BGColor is a six-digit hexadecimal number, each of which represents a red-green-blue color value. For example: FFEEAA indicates that the red value is FF, the green value is EE, and the blue value is AA.
Example: Set the movie background color to red:
Movie. BGColor = "FF0000"

5.Base (read/write)
Syntax: Base as String
Description: Specifies the base address of the declaration that is used to resolve all relative paths in the movie. This property is especially useful when the movie is not in the same directory as the other files it needs. If not specifically specified, the value of Base defaults to ".", which is the path where the current movie is located.
Example:
Movie. Base = "Http://www.domain.com/pathname1/pathname2"

6.Movie (read/write)
Syntax: Movie as String
Description: The movie path (URL) to play. Setting this property to the URL of a SWF file will load the file and play it. If the movie is on a local hard drive, write the absolute path starting from the drive letter, and if the movie is on a Web site, the full URL is also written.
Example:
Movie. Movie = "http://www.domain.com/path1/path2/filename.swf"
Or
Movie. Movie = "c:/temp/test.swf"

7.DeviceFont (read/write)
Syntax: Devicefont as Boolean
Description: Determines whether to use the font embedded in the movie, and the default value is False. Setting this property value to True forces the player to use the Local system font without using the embedded font in the movie.
Example:
Movie. Devicefont = True

8.EmbedMovie (read/write)
Syntax: Embedmovie as Boolean
Description: Whether the movie is stored in the container where the control resides. Set this property to True when you have loaded a movie, and you do not have to read the SWF file when you play the movie. This makes it easier to use Flash movies in PowerPoint presentations or VB programs. However, when this property is set to True, the Movie property of the control no longer accepts the new value. To play another movie (assigning a new value to the movie property), you must first set the Embedmovie property to False.
Example:
Movie. Embedmovie = True

9.FrameNum (read/write)
Syntax: Framenum as Long
Description: The number of the current frame of the movie (counting starting from 0). Setting this property value will cause the movie to stop at the frame specified by Framenum.
Example: Display the current number of frames:
MsgBox "Current display is" & movie. Framenum & "frame. "

Make the Movie show frame 10th:
Bomovie.framenum = 9

10.TotalFrames (Read only)
Syntax: Totalframes as Long
Description: Returns the total number of frames in the movie. This parameter is valid until the movie loading is complete (readystate=4).
Example:
If movie. ReadyState = 4 Then MsgBox "Total Film" & Movie. Totalframes & "frame. "

11.Loop (read/write)
Syntax: Loop as Boolean
Description: Whether to loop playback. Set to True to loop playback, set to False to play only once.
Example:
Movie. Loop = True


12.Menu (read/write)
Syntax: Menu as Boolean
Description: Whether the menu is displayed. Set to True to show all menus, set to False the menu is masked, but there is still a "about Macromedia Flash Player ...". If you really do not like this menu, you should stop the mouse messages in the program to achieve the goal. Unlike in a standalone Flash player, in the right-click menu of a control, click
"About ..." will open the browser to Macromedia's website to see about.
Example:
Movie. Menu = False

13.Playing (read only)
Syntax: Playing as Boolean
Description: The current playback state. True If the movie is playing, False otherwise.
Example:
If movie. Playing = False then MsgBox "The movie has stopped playing!" "

14.Quality (read/write)
Syntax: Quality as Long
Description: Picture quality (linkage with Quality2). Quality can take:
0--equivalent to Quality2 "low"
The equivalent of Quality2 take "high"
2--equivalent to Quality2 take "Autolow"
3--equivalent to Quality2 take "Autohigh"
Example:
Movie. Quality = 1

15.quality2 (Read and write)
Syntax: Quality as String
Description: Picture quality (linkage with quality). Quality2 can take:
Low :Emphasis on playback speed regardless of display effect, and do not enable
Anti-aliasing function.
High :Emphasis on the screen regardless of playback speed and always enable anti-aliasing. If the movie does not contain animations, the bitmap is smoothed, and if there is an animation, the bitmap is not smoothed. (The animation here should be to translate or rotate a picture.)
Autolow:Focus on playback speed first, but improve the display as soon as possible. Disables the anti-aliasing feature first when playback starts. If the player detects that the processor is capable of withstanding, enable anti-aliasing.
Autohigh:At first, the playback speed and the display effect are both equal, but if necessary, make sure the speed is at the expense of quality. Anti-aliasing is enabled when you start playback. However, if the actual frame rate is slower than the rate specified at design time, the anti-aliasing feature is disabled to improve playback speed.
Example:
Movie. Quality2 = "High"

16.ReadyState (read only)
Syntax: ReadyState as Long
Description: The current state of the movie. ReadyState can take:
0--is loading
Not initialized
2--Loaded
3--is interacting
4--Complete Example:
If movie. ReadyState = 4 then MsgBox "Movie Loading complete! "

17.Scale (read/write)
Syntax: Scale as String
Description: Zoom mode (linkage with ScaleMode). Scale can take:
showall--displays all movie areas within the control, keeping the movie's length-to-width ratio constant, and the size of the movie depends on the smaller side of the control's length or width.
noborder--displays part of the movie area within the control, keeping the movie's length-to-width ratio constant, and the size of the movie depends on the length of the control or the larger side of the width.
exactfit--Displays the entire movie area within the control, forcing the length-to-width ratio of the movie equal to the height-to-width ratio of the control.
Example:
MsgBox "The current zoom mode is:" & Movie. Scale

18.ScaleMode (read/write)
Syntax: ScaleMode as Long
Description: Zoom mode (linkage with scale). ScaleMode can take:
0--equivalent to scale "showall"
The equivalent of the scale of "Noborder"
2--equivalent to scale "Exactfit"
Example: Change the zoom mode of the movie to "Exactfit":
Movie. ScaleMode = 2

19.Stacking (read/write)
Syntax: Stacking as String
Description: Used for HTML, which uses Flash Player as a "behavior" in HTML, determines how the Flash movie is displayed relative to its referenced HTML content. (for behaviors, see the style sheet's data). Stacking can take:
none--"Behavior" is not displayed.
replaceall--the display of "behavior" supersedes the contents of all other elements, including the background.
content--the display of "behavior" replaces the contents of other elements only.
background--the display of "behavior" replaces the background of other elements only.
below--"Behavior" is displayed below the content of all other elements.
belowflow--"Behavior" is displayed in reverse Z-order on the child objects of other elements, but above the main content of the element.
aboveflow--"Behavior" is displayed in a positive Z-order below the sub-object of another element, but above the main content of the element.
above--"Behavior" is displayed above the content of all other elements.
The display of top--"behavior" is placed above the entire page content.
Example:
Movie. Stacking = "Below"

20.WMode (read/write)
Syntax: WMode as String
Description: The window mode of the control. WMode can take: Default value of Window--wmode property, press Flash player
The typical way to work is to play the movie in the control's rectangular window, which generally provides the fastest animation effect.
opaque--make the movie opaque. transparent--create a transparent movie. If the movie has
Transparent fragments, when placed here, you can see the background under the control. But with this property value, the animation may play slower.
Example:
Movie. WMode = "Transparent"


---------------------------------------------------------------------------

Method:

The methods in the following do not return a value:
1.Back
Syntax: Back ()
Description: The movie backs up one frame and stops playing. Example:
Movie. Back

2.Forward
Syntax: Forward ()
Description: The movie advances one frame and stops playing.
Example:
Movie. Forward

3.GotoFrame
Syntax: Gotoframe (framenum as Long)
Description: Jumps the movie to the frame specified by Framenum and stops playback. If the specified frame is not loaded, the player advances to the last available frame and stops, which can have unpredictable consequences during the call. It is a good idea to use the Percentloaded method to determine whether enough movies have been loaded to perform this method. The parameter framenum is starting from 0, which is not the same as the Goto action in Flash, it starts with 1.
Example: Jump to the 20th frame of the movie:
Movie. Gotoframe 20

4.LoadMovie
Syntax: Loadmovie (layer as Long, url as String)
Description: The movie specified by the URL is loaded onto the layer specified by layers.
Example: Loading the movie.swf onto layer 0:
Movie. Loadmovie 0, "movie.swf"

5.Pan
Syntax: Pan (x As Long, y as long, mode as long)
Description: Pans A zoomed-in movie by the distance specified by x and Y. Both x and Y are relative values. That is, the distance the control is shifted relative to the movie (you can imagine the control is a window, the movie is the set that we see from the window, and we see that the window shifts some distance relative to the scene, that the outside scene is moving and the window is motionless). Use the mode parameter to specify whether the value of x and Y is a pixel or a percentage of the window, and the coordinate system is measured in pixels when mode=0, and the coordinate system is calculated as a percentage of the window when mode=1. Panning does not extend beyond the frame of the movie, that is, the degree to which the edge of the movie is aligned to the control in one Direction.
Example: the control pans 5 pixels to the left of the movie (although the control does not move, the movie is shifted to the right):

6.Play
Syntax: Play ()
Description: Starts playing the movie.
Example:
Movie. Play

7.Rewind
Syntax: Rewind ()
Description: Rewind the tape. Returns to the first frame of the movie.
Example:
Movie. Rewind

8.SetVariable
Syntax: setvariable (name as String, value as String)
Description: Sets the Flash variable value specified by name to value.
Example:
Movie. SetVariable "/form:username", "John Smith"


---------------------------------------------------------------------------
Event:

1.FSCommand
Syntax: Shockwaveflash1_fscommand (ByVal command As String, ByVal args as String)
Description: An event triggered by a call to Fscommand () in Flash
Parameters:
Command: Represents an order identifier
Args: Representing parameters
Example:
Select Case Command ' here can be used if
' But after command, it's not good if it's used.
' I was doing a demonstration
Case "Command1"
If args = "123" Then
...
Else
...
End If
Case ...
End Select

2.FlashCall
Syntax: Shockwaveflash1_flashcall (ByVal request as String)
Note: Few people may know the usefulness of this event, in fact this is similar to the FSCommand incident. Unlike FSCommand, this event can have a return value (as discussed below)
parameter is a string in XML format that is
"<invoke name= '%s ' returntype= ' xml ' ><arguments><string>%s</string></arguments>< /invoke> ", to find out the help will know.
Processing request: Standard VB does not handle the XML library, you can find XML-enabled plug-in to use. Here's what you need to do with your request.
return value:
The event handler does not have a return value, but Flash Player provides a method: Shockwaveflash1.setreturnvalue () specifically passes the return value, in the format <string>%s</string> (It can also be a different as structure, specifically see Help).
Example: I give an example of tinyxml here:
Private Sub Shockwaveflash1_flashcall (ByVal request as String)
Dim Request_xml as New tixmldocument
Dim Request_name as String
Request_xml. Parse Request
Request_name = Request_xml. RootElement (). Attribute ("name")

... Take care of it yourself.

End Sub

3.OnProgress
Syntax: shockwaveflash1_onprogress (ByVal percentdone as Long)
Description: It is estimated that flash was triggered during the load process change, right?
PercentDone should be a percentage ~
Anyway, I haven't caught the incident yet. = =!

4.OnReadyStateChange
Syntax: Shockwaveflash1_onreadystatechange (newstate as Long)
Description: As the name implies, is the event triggered when the ReadyState change, specifically, see the above about the ReadyState attribute description, I do not nonsense in this ....

As for other events, such as
GotFocus, LostFocus, I don't want to talk nonsense ...

The corresponding class of the Ps:shockwave Flash Object control is the Cshockwaveflash class, a common function of the class:

Play () play animation Stopplay () Stop animation isplaying (): Whether the animation is playing (True,false)

Gotoframe (Frame_number) jump to a frame (frame_number+1)

Totalframes () Gets the total number of animation frames Currentframe () callback the current animation frame number-1

Rewind () causes the animation to return to the first frame Setzoomrect (left,top,right,buttom) to enlarge the specified area

Zoom (percent) changes the animation size pan (x_position,y_position,unit) pans The animation in the X, y direction

Percentloaded () returns the percentage of animation loaded (0-100)

Loadmovie (level_number,path) Loading animations

Tgotoframe (Movie_clip,frame_number) Movie_clip jump to the specified number of frames
Tgotolabel (muvie_clip,label_name) Movie_clip jump to the specified label
Tcurrentframe (Movie_clip) callback Movie_clip Current frame-1

Tcurrentlabel (Movie_clip) Callback Movie_clip current tab

Tplay (movie_clip) play Movie_clip Tstopplay (movie_clip) Stop movie_clip playback

GetVariable (variable_name) Get variable setvariable (variable_name,value) variable assignment

Tcallframe (movie_clip,frame_number) Call action on the specified frame

Tcalllabel (Movie_clip,label) Call the action on the specified label

Tgetproperty (movie_clip,property) Gets the specified property of the Movie_clip

Tsetproperty (movie_clip,property,number) sets the specified properties of the Movie_clip


Create a Flash control in MFC and load the SWF from the memory stream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.