Flash GUI for Your EXE Using Minimalistic Approach
http://www.codeproject.com/KB/cpp/FlashGui.aspxIntroductionWell we all know how boring gui today applications have. Especially when compared to even subpar flash web site. So how about nice flashy flashy gui for your super application ?Embed flash in 3 lines of code#include <windows.h> int WINAPI WinMain(HINSTANCE inst,HINSTANCE prev,LPSTR cmd,int show) { MSG msg={0}; void* init = GetProcAddress(LoadLibrary("atl"),"AtlAxWinInit"); _asm call init; CreateWindow("AtlAxWin","c:WINDOWSHelpToursmmToursegment2.swf",WS_VISIBLE|WS_POPUP,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),0); while (GetMessage(&msg,0)) DispatchMessage(&msg); }; Also worth noting is fact that you can insert swf file as resource and have everything in one executable. Path to yourflash (second param to createwindow) would be then in this format "res://YOUR_EXE_PATH/YOUR_RES_NAME" Ehm... and what about 3D VRML Gui ?In fact it is possible to render ANY file format using ANY protocol that Internet Explorer is able. Just go ahead and try React to flash eventsAfter you play enough with previous sample you will notice that it's missing one important element. #include <windows.h> #include <exdisp.h> #include <mshtmlc.h> #import "PROGID:ShockwaveFlash.ShockwaveFlash" no_namespace raw_interfaces_only #define MsgLoopWhile(a) while(a) { GetMessage(&msg,0); DispatchMessage(&msg); } typedef HRESULT (WINAPI *LPAtlAxWinInit) (); typedef HRESULT (WINAPI *LPAtlAxGetControl)(HWND hwnd,IUnknown** unk); int WINAPI WinMain(HINSTANCE inst,int show) { LPAtlAxWinInit AtlAxWinInit3 = (LPAtlAxWinInit) GetProcAddress(LoadLibrary("atl"),"AtlAxWinInit"); // Atl.dll v 3.0 is part of the windows LPAtlAxGetControl AtlAxGetControl3 = (LPAtlAxGetControl)GetProcAddress(LoadLibrary("atl"),"AtlAxGetControl"); MSG msg; HRESULT hr = AtlAxWinInit3(); HWND hwnd = CreateWindow("AtlAxWin","http://www.screenvader.com/_ROOT.swf",0); IUnknown* unkn; hr = AtlAxGetControl3(hwnd,&unkn); IWebBrowser2* brow; hr = unkn->QueryInterface(__uuidof(IWebBrowser2),(void**)&brow); IDispatch* disp; MsgLoopWhile( !brow->get_Document(&disp) && !disp ); // Document loading loop IHTMLDocument2* html; hr = disp->QueryInterface(__uuidof(IHTMLDocument2),(void**)&html); IHTMLElementCollection* elems; hr = html->get_embeds(&elems); VARIANT id; VariantInit(&id); MsgLoopWhile( elems && !elems->item(id,id,&disp) && !disp ); // Document parsing loop IShockwaveFlash* flash=0; hr = disp->QueryInterface(__uuidof(IShockwaveFlash),(void**)&flash); while (GetMessage(&msg,0) && flash) { BSTR val,var=L"MyEvent"; hr = flash->GetVariable(var,&val); // Set this var/s in flash long frame; hr = flash->CurrentFrame(&frame); DispatchMessage( &msg); } }; Change Flash content from C++Text fields can be connected to variables names,thus alowing us to display dynamicflash content. For details see http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_16184 Then just use method SetVariable onflash object. Transparent FlashWell this one is a bit challenging and not yet finished. Rendering is usualy split to 2 steps. Clear background and draw rest. To gain control over how backround is filled we need to activateflash activex control in so called "windowless" mode. One way to do this with ATL is with AtlAxAttachControl (Thx for this info goes to JaeWook Choi ) // create invisible container window HWND ctrl = CreateWindowEx(0,"AtlAxWin",0); IShockwaveFlash* flash=0; hr = CoCreateInstance(__uuidof(ShockwaveFlash),CLSCTX_ALL,__uuidof(IShockwaveFlash),(void **)&flash); hr = flash->put_WMode(L"transparent"); hr = AtlAxAttachControl(flash,ctrl,0); IViewObjectEx* view=0; hr = flash->QueryInterface(__uuidof(IViewObjectEx),(void **)&view); hr = flash->put_Movie(L"c:WINDOWSHelpToursmmToursegment2.swf"); ... // In msg loop update background and render (to 2nd visible window) hr = view->Draw(DVASPECT_CONTENT,GetDC(hwnd),0); Points of interestNice thing is that you can react to frame positions on allready existing .swf files or by checking variable values (if you know them for that swf). For your ownflashes you decide variable/s name/s that you will set inflash and monitor in exe msg loop. Also the path to swf file in 3 line sample is for Windows XP owners. Other users should put some other url/path to some other file. You may need PlatformSDK (Visual C++ 6)For example Visual c++ 6 etc does not contain PlatformSDK (thus // An old Visual c++ 6 #import statement doesn't supports PROGID ? #import "C:WINDOWSsystem32MacromedFlashFlash.ocx" #include "DebugFlash.tlh" Now go and create some nice animated breath-taking GUI for your exe. "There is always simpler way". (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |