c++操作flash

c++操作falsh,忘了原文在哪了,自己尝试了,直接贴代码

  1 // SDK版本  
  2 ////   
  3 // Use swflash.ocx to play flash   
  4 // if it works, it is written by masterz, otherwise I don't know who writes it(*_*)   
  5 ////   
  6 //#include "stdafx.h"   
  7 //#import "c:\windows\system32\macromed\flash\swflash.ocx"   
  8 #import "C:\WINDOWS\system32\Macromed\Flash\Flash32_11_8_800_94.ocx"   
  9 #include <atlbase.h>   
 10 CComModule _Module;   
 11 #include <atlwin.h>   
 12 #include <windows.h>  
 13 #include "stdio.h"  
 14 #pragma comment(lib,"atl")   
 15 #define ODS(x) OutputDebugString(x)   
 16 #define MAX_LOADSTRING 100  
 17   
 18 // Global Variables:   
 19   
 20 HINSTANCE hInst; // current instance   
 21 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text   
 22 TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text   
 23 CAxWindow m_container;   
 24 using namespace ShockwaveFlashObjects;   
 25 IShockwaveFlash* shwaveflash;   
 26   
 27 HWND heditfilepath;   
 28   
 29 // Foward declarations of functions included in this code module:   
 30 ATOM MyRegisterClass(HINSTANCE hInstance);   
 31 BOOL InitInstance(HINSTANCE, int);   
 32 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);   
 33   
 34 int APIENTRY WinMain(HINSTANCE hInstance,   
 35                      HINSTANCE hPrevInstance,   
 36                      LPSTR lpCmdLine,   
 37                      int nCmdShow)   
 38 {   
 39     MSG msg;   
 40     // Initialize global strings   
 41     wsprintf(szTitle, _T("use flash control in sdk exe"));   
 42     wsprintf(szWindowClass, _T("flashinsdk"));   
 43     MyRegisterClass(hInstance);   
 44     CoInitialize(NULL);   
 45     // Perform application initialization:   
 46     if (!InitInstance (hInstance, nCmdShow))   
 47         return FALSE;   
 48     while (GetMessage(&msg, NULL, 0, 0))   
 49     {   
 50         TranslateMessage(&msg);   
 51         DispatchMessage(&msg);   
 52     }   
 53     CoUninitialize();   
 54     return msg.wParam;   
 55 }   
 56   
 57 // FUNCTION: MyRegisterClass()   
 58 // PURPOSE: Registers the window class.   
 59 ATOM MyRegisterClass(HINSTANCE hInstance)   
 60 {   
 61     WNDCLASSEX wcex;   
 62     wcex.cbSize = sizeof(WNDCLASSEX);   
 63     wcex.style = CS_HREDRAW | CS_VREDRAW;   
 64     wcex.lpfnWndProc = (WNDPROC)WndProc;   
 65     wcex.cbClsExtra = 0;   
 66     wcex.cbWndExtra = 0;   
 67     wcex.hInstance = hInstance;   
 68     wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);   
 69     wcex.hCursor = LoadCursor(NULL, IDC_ARROW);   
 70     wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);   
 71     wcex.lpszMenuName = NULL;//(LPCSTR)IDC_FLSH;   
 72     wcex.lpszClassName = szWindowClass;   
 73     wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);   
 74     return RegisterClassEx(&wcex);   
 75 }   
 76   
 77 // FUNCTION: InitInstance(HANDLE, int)   
 78 // PURPOSE: Saves instance handle and creates main window   
 79 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)   
 80 {   
 81     HWND hWnd;   
 82     hInst = hInstance; // Store instance handle in our global variable   
 83     AtlAxWinInit();   
 84     hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,   
 85         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);   
 86     if (!hWnd)   
 87         return FALSE;   
 88     ShowWindow(hWnd, nCmdShow);   
 89     UpdateWindow(hWnd);   
 90     return TRUE;   
 91 }   
 92   
 93 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)   
 94 {   
 95     int wmId, wmEvent;   
 96     PAINTSTRUCT ps;   
 97     HDC hdc;   
 98     TCHAR szHello[MAX_LOADSTRING];   
 99     wsprintf(szHello, _T("use flash control in sdk"));   
100     HWND hbtnstart;   
101     RECT rc;   
102     switch (message)   
103     {   
104     case WM_CREATE:   
105         GetClientRect(hWnd, &rc );   
106         rc.top = 100;
107         m_container.Create( hWnd, rc,  _T("{D27CDB6E-AE6D-11cf-96B8-444553540000}"),WS_CHILD |WS_VISIBLE |WS_HSCROLL |WS_VSCROLL );//create a browser control   
108         hbtnstart=CreateWindow(_T("BUTTON"), _T("play"), WS_CHILD|WS_VISIBLE,0,0,120,30,hWnd,(HMENU)0x100,hInst,0);   
109         heditfilepath=CreateWindow(_T("EDIT"), _T("filepath"),WS_CHILD |WS_VISIBLE |WS_BORDER,0,40,420,30,hWnd,(HMENU)0x101,hInst,0);   
110         SetWindowText(heditfilepath, _T("E:\\test\\c++\\flashocx\\Debug\\loginui.swf"));
111         m_container.QueryControl( __uuidof(IShockwaveFlash), reinterpret_cast<void**>(&shwaveflash) );   
112         break;   
113     case WM_SIZING:   
114         GetClientRect(hWnd, &rc );   
115         rc.top = 100;
116         m_container.MoveWindow(&rc,true);
117         shwaveflash->SetZoomRect( 0, 0, rc.right - rc.left, rc.bottom - rc.top );
118         break;   
119     case WM_COMMAND:   
120         wmId = LOWORD(wParam);   
121         wmEvent = HIWORD(wParam);   
122         // Parse the menu selections:   
123         switch (wmId)   
124         {   
125         case 0x100:   
126             {   
127                 ODS(_T("0x100"));
128                 wchar_t buf[256];
129                 GetWindowText(heditfilepath, (LPWSTR)buf,255);   
130                 _bstr_t bstr((wchar_t*)buf);   
131                 //ODS(buf);
132                 //bstr=_bstr_t(_T("c:\\2.1.swf"));
133                 //bstr=_bstr_t(_T("E:\\test\\c++\\flashocx\\Debug\\loginui.swf"));
134                 if(shwaveflash->put_Movie(bstr)!=S_OK){// you have to change the path here 
135                     ODS(_T("load movie error"));
136                 }else{     
137                 shwaveflash->Play();
138                 shwaveflash->SetVariable(_bstr_t(_T("user")), _bstr_t(_T("testuser")));
139                 shwaveflash->SetVariable(_bstr_t(_T("password")), _bstr_t(_T("password")));
140                 GetClientRect(hWnd, &rc );
141                 shwaveflash->SetZoomRect( 0, 0, rc.right - rc.left, rc.bottom - rc.top );
142                 shwaveflash->PutMenu( false );
143                 }
144             }   
145             break;
146         default:   
147             return DefWindowProc(hWnd, message, wParam, lParam);   
148         }   
149         break;   
150     case WM_PAINT:   
151         hdc = BeginPaint(hWnd, &ps);   
152         RECT rt;   
153         GetClientRect(hWnd, &rt);   
154         DrawText(hdc, szHello, strlen((const char*)szHello), &rt, DT_CENTER);   
155         EndPaint(hWnd, &ps);   
156         break;   
157     case WM_DESTROY:   
158         PostQuitMessage(0);   
159         break;
160     default:   
161         return DefWindowProc(hWnd, message, wParam, lParam);   
162     }   
163     return 0;   
164   
165 }  
View Code

下面是尝试的swf

http://files.cnblogs.com/marcher/loginui.swf

转载于:https://www.cnblogs.com/marcher/p/3444394.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值