[C++/WinApi] .swf im Fenster abspielen?

posi90

Erfahrenes Mitglied
Hallo,

Ich würde gerne eine Flash-Movie abspielen lassen. Kennt jemand eine SDK oder ein Tutorial dafür, dies in C++/WinApi zu lösen?

Wäre toll wenn man es wie ein Bild in der WM_PAINT Message erzeugen lassen kann =)
Aber so einfach wird das wohl nicht funktionieren.

Bitte um Lösungsansätze/vorschläge oder auch alternativen.

mfg. Poseidon
 
Habe nun eine Lösung gefunden.
http://www.rohitab.com/discuss/topic/29239-swf-and-c/

C++:
// 
// SWF In Window Example
// by Napalm
// 

#import "C:\windows\system32\macromed\flash\flash.ocx" rename_namespace("Flash")
#pragma comment(lib, "atl")
#include  <atlbase.h>
CComModule _Module;
#include <atlwin.h>
#include <windows.h>
#include <string.h>

HINSTANCE g_hInst;


LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
	static Flash::IShockwaveFlash* m_pFlash;
	static HWND hWndActiveX;
	switch(uMessage)
	{
		case WM_CREATE:
			{
				WCHAR wcPath[MAX_PATH];
				RECT rc; GetClientRect(hWnd, &rc);
				hWndActiveX = CreateWindowEx(0, "AtlAxWin", NULL, WS_CHILD | WS_VISIBLE,
					0, 0, rc.right, rc.bottom, hWnd, NULL, g_hInst, NULL);
				if(FAILED(CoCreateInstance(__uuidof(Flash::ShockwaveFlash), NULL, CLSCTX_ALL,
					__uuidof(Flash::IShockwaveFlash), (void**)&m_pFlash)))
						return -1;
				if(FAILED(AtlAxAttachControl(m_pFlash, hWndActiveX, NULL))){
					m_pFlash->Release();
					return -1;
				}
				GetCurrentDirectoryW(MAX_PATH, wcPath);
				wcscat(wcPath, L"\\shapes.swf");
				m_pFlash->LoadMovie(0, wcPath);
				m_pFlash->Menu = VARIANT_FALSE;
			}
			return 0;
			
		case WM_SIZE:
			MoveWindow(hWndActiveX, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
			return 0;
		
		case WM_PAINT:
		case WM_ERASEBKGND:
			ValidateRect(hWnd, NULL);
			return 0;
		
		case WM_DESTROY:
			DestroyWindow(hWndActiveX);
			m_pFlash->Release();
			PostQuitMessage(0);
			return 0;
	}
	
	return DefWindowProc(hWnd, uMessage, wParam, lParam);
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
{
	CoInitialize(NULL);
	AtlAxWinInit();
	g_hInst = hInstance;

	WNDCLASSEX wcex = {
		sizeof(WNDCLASSEX), 0, WndProc, 0, 0, g_hInst, LoadIcon(NULL, IDI_APPLICATION),
		LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_WINDOW + 1), NULL, "SWFWin", NULL,
	};
	if(!RegisterClassEx(&wcex))
		return MessageBox(HWND_DESKTOP, "Could not register class!", "Error", MB_ICONERROR | MB_OK);
	
	int nX = ((GetSystemMetrics(SM_CXSCREEN) - 400) / 2),
	    nY = ((GetSystemMetrics(SM_CYSCREEN) - 340) / 2);
	HWND hWnd = CreateWindowEx(0, wcex.lpszClassName, "SWF In Window Example - by Napalm",
		WS_OVERLAPPEDWINDOW, nX, nY, 400, 340, HWND_DESKTOP, NULL, g_hInst, NULL);
	if(!hWnd)
		return MessageBox(HWND_DESKTOP, "Could not create window!", "Error", MB_ICONERROR | MB_OK);
	
	ShowWindow(hWnd, nCmdShow);
	
	MSG Msg;
	while(GetMessage(&Msg, NULL, 0, 0)){
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	
	CoUninitialize();
	return (int)Msg.wParam;
}

Die angelegte .exe funktioniert einwandfrei, obwohl die nur 5kb hat. Meine hat ~300kb.

Wollte nun den Sourcecode in einem neuen Project implementieren und bin darauf gekommen, dass ich beim #import... Abschnitt am Anfang etwas ändern muss, da ich auf 64-Bit fahre. Denn diese Datei ist nicht vorhanden.

Hab die nun auf folgendes geändert:
C++:
#import "C:\Windows\SysWOW64\Macromed\Flash\Flash10n.ocx" rename_namespace("Flash")

Auch der Dateiname musste sich von flash.ocx auf Flash10n.ocx ändern.

Müsste man bei der Pfad Angabe nicht "\\" statt "\" schreiben?

Habe nun das alles probiert.
Leider funktioniert die Anzeige der flash Datei nur mit der .exe die beigelegt ist (siehe URL).

Kann mir jemand helfen?

mfg. Poseidon
 
Habe nun einen Code gefunden, der es mir ermöglicht eine swf. Datei abzuspielen.

C++:
void* init;
init = GetProcAddress(LoadLibrary(L"atl"),"AtlAxWinInit"); 
			_asm call init;
				 CreateWindow(L"AtlAxWin", L"C:\\flash.swf", WS_VISIBLE|WS_BORDER|WS_CHILD,0,0,	400,200,hWnd,0,hInst,NULL);

Poseidon
 
Zurück