The advantageous advantage of COM said that using ATL development COM is convenient and fast, and has a small size of Size, depundency. VC Import Compilation Support is a huge support for COM development. Gossip, let's start.
One .flash component
1.atl COM AppWizard Creates a new project "Atlflash", select the DLL type.
2. Join the ATL Object "Flash"
Insert -> New ATL Object
Select Simple Object in Object,
Short name: "Flash"
3. Interface Add Method "Play"
The parameter is: [in] bstr bstrfile, [in] long hinstance, [in] long hwnd
4. Add: in the CFLASH class:
Private:
HWND M_HWND; // Video window handle
5. Implement a Play method.
StdMethodimp Cflash :: Play (BSTR BSTRFILE, Long Hinstance, long hwnd)
{
Try {
m_hmciwnd = (hwnd) hwnd;
_BSTR_T File (BStrfile);
m_hmciwnd = :: mciWndcreate ((hwnd) hWnd, (hinstance) Hinstance,
WS_POPUP & BrVBARWS_VISIBLE|
MCIWNDF_NOPLAYBAR|
MCIWNDF_NOMENU,
(char *) File;
RECT;
Int SX, SY;
:: getWindowRect (M_HMCIWND, & Rect);
SX = (:: getSystemMetrics (SM_CXSCREEN)
-Rect.right Rect.Left) / 2;
Sy = (:: getSystemMetrics (sm_cyscreen)
-Rect.Bottom Rect.top/2;
// Window
:: SetwindowPos (M_HMCIWND, HWND_TOPMOST, SX,
Sy, 0,0, swp_showwindow & brvbarswp_nosize;
g_nlength = mciWndgetLength (m_hmciwnd);
McIWndPlay (m_hmciwnd);
SetTimer (M_HMCIWND, 1, 50, TimerProc);
} catch (...)
{
ATLTRACE ("Error:% UL", :: getLastError ());
}
Return S_OK;
}
6. Flash.cpp Implement TimerProc for closing the video window.
Long g_nlendh;
Void Callback TimerProc
HWND HWND, // Handle of Window for Timer Messages
UINT UMSG, // WM_TIMER MESSAGE
Uint IDEvent, // Timer Identifier
DWORD DWTIME / / CURRENT System Time
)
{
Long nlength;
Bool Bescape = :: getKeyState & 0x0100;
NLENGTH = MCIWNDGETPSITION (HWND);
// Video is finished, or click the ESC button, turn off the video window
IF ((NLENGTH> = g_nlength) || (BESCAPE)) {
KillTimer (hwnd, idevent);
McIWndend (HWND);
MCIWNDCLOSE (HWND); MCIWNDDESTROY (HWND);
}
}
7. STDAFX.H Join
#Include
Add "VWF32.LIB" library in the project settings,
Open Enable Error Handling in C , C Language in the project settings
Compile, everything is OK.
Second, the use of components.
1. Create a MDI or SDI project "FlashClient"
2. STDAFX.H Join
#Import "atlflash.dll" no_namespace
Add to Flashcient.cpp
Struct_initcom {
_INITCOM () {:: Coinitialize (null);
~ _Initcom () {:: couninitialize ();
} __ initcom;
3.CflashClientView joins
Private:
Iflashptr pflashserver;
4.cflashclent :: onInitialupdate () Add to
_BSTR_T File ("Sample.avi");
Pflash Server-> Play (file, (long) :: AfxgetInstanceHandle (), (long )-> getsafehwnd ());
5. Compile, everything is OK.