Click here to Skip to main content
Licence CPOL
First Posted 2 Feb 2006
Views 448,386
Bookmarked 128 times

Flash GUI for Your EXE Using Minimalistic Approach

By | 1 Jul 2006 | Article
Attempt to create a Flash GUI for a Win32 app with ehm ... 3 lines of code.

Introduction

Well 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:\\WINDOWS\\Help\\Tours\\mmTour\\segment2.swf", WS_VISIBLE|WS_POPUP,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),0,0,0,0);
    while (GetMessage(&msg,0,0,0)) DispatchMessage(&msg);
};

Also worth noting is fact that you can insert swf file as resource and have everything in one executable. Path to your flash (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 ZIP, PDF, JPG, VRML, DOC, CHM, AVI, MP3,etc... via MSHtml:, File:, Res:, Http:, Ftp:, etc. The only problem is if you wana react to user interactions in those documents. Right now i dig inside IE to find solution but let's focus to what this article is about.

React to flash events

After you play enough with previous sample you will notice that it's missing one important element.
It's missing place where we catch events from flash. So here is another sample where i dig thru all the interfaces up to IShockwaveFlash. And i know what you think.
it's 10 more lines but hey, still better than class galore ;) And as for the second used flash. I must give credit to very talented artist named Stephane Bourez. That interface is really innovative and fresh light at the same time.

#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,0,0); DispatchMessage(&msg); }

typedef HRESULT (WINAPI *LPAtlAxWinInit)   ();
typedef HRESULT (WINAPI *LPAtlAxGetControl)(HWND hwnd, IUnknown** unk);

int WINAPI WinMain(HINSTANCE inst,HINSTANCE prev,LPSTR cmd,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",WS_VISIBLE|WS_POPUP,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),0,0,0,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,0,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 dynamic flash content. For details see http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_16184 Then just use method SetVariable on flash object.

Transparent Flash

Well 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 activate flash 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,0,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),0,0,0,0);
IShockwaveFlash* flash=0; hr = CoCreateInstance(__uuidof(ShockwaveFlash),0,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:\\WINDOWS\\Help\\Tours\\mmTour\\segment2.swf");
... 
// In msg loop update background and render (to 2nd visible window) 

hr = view->Draw(DVASPECT_CONTENT, 0, 0, 0, 0, GetDC(hwnd), 0, 0, 0, 0);

Points of interest

Nice 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 own flashes you decide variable/s name/s that you will set in flash 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 mshtmlc.h) .But since this is MIDL generated file you should probably be able to generate it from mshtml ocx with MIDL compiler. Also thanks goes to Mirjini who found out that following changes are needed for VC++ 6:

// An old Visual c++ 6 #import statement doesn't supports PROGID ?

#import "C:\WINDOWS\system32\Macromed\Flash\Flash.ocx"
#include "Debug\Flash.tlh"

Now go and create some nice animated breath-taking GUI for your exe.
And remember

"There is always simpler way".

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ladislav Nevery

Software Developer (Senior)

Slovakia Slovakia

Member

Past Projects:
[Siemens.sk]Mobile network software: HLR-Inovation for telering.at (Corba)
Medical software: CorRea module for CT scanner
[cauldron.sk]Computer Games:XboxLive/net code for Conan, Knights of the temple II, GeneTroopers, CivilWar, Soldier of fortune II
[www.elveon.com]Computer Games:XboxLive/net code for Elveon game based on Unreal Engine 3

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralSWF in Resource Pinmembervasquez4:05 1 Jun '07  
QuestionHow to get flash dimensions Pinmembervian250:59 26 May '07  
Questiondoesnt work on resize Pinmembervasquez14:34 25 May '07  
QuestionRe: doesnt work on resize Pinmembervasquez14:41 25 May '07  
QuestionI can not find mshtmlc.h in PlatformSDK, where is it please? PinmemberFeiluHang0:29 24 May '07  
Generalnewbie question Pinmembervasquez14:42 12 May '07  
GeneralRe: newbie question Pinmembervasquez6:09 17 May '07  
okay, forget it, it was a stupid question but havent done
windows-programming for a while.
 
Waiting for WM_SYSCOMMAND (SC_CLOSE) and doing a ExitProcess() was
the solution i searched for. ;-D
 
thanks anyway,
laszlo
 

QuestionDetect and install Flash 8 Pinmemberkyincx15:55 12 Mar '07  
QuestionThreading problem PinmemberBig Muscle8:29 2 Mar '07  
AnswerRe: Threading problem Pinmembervasquez14:39 25 May '07  
AnswerRe: Threading problem Pinmembervasquez14:49 25 May '07  
Generalok But [modified] Pinmemberbose_sard16:37 9 Feb '07  
QuestionSlow Flash Pinmemberkyincx11:39 17 Dec '06  
GeneralUpdate available Pinmemberhanishn10:38 8 Dec '06  
QuestionMake it work for all Version of flash PinmemberKimberley38:44 21 Nov '06  
AnswerRe: Make it work for all Version of flash PinmemberLadislav Nevery8:58 29 Nov '06  
QuestionIs it possible to handle events? PinmemberShuang. Wu23:50 16 Nov '06  
QuestionWndProc with AtlAxWin Pinmemberkyincx11:17 2 Nov '06  
AnswerRe: WndProc with AtlAxWin Pinmemberkyincx8:33 3 Nov '06  
GeneralRe: WndProc with AtlAxWin Pinmemberevren32023:33 1 Apr '10  
GeneralThankyou PinmemberEddie_NG7:11 31 Oct '06  
GeneralRe: Thankyou Pinmemberaniday4:35 9 Jan '08  
AnswerRe: Is there any way to call an actionscript function from c++? PinmemberLadislav Nevery12:28 17 Oct '06  
GeneralIShockwaveFlash undeclared Pinmembermclougm4bat1:12 12 Oct '06  
GeneralRe: IShockwaveFlash undeclared PinmemberFeiluHang17:19 24 May '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 1 Jul 2006
Article Copyright 2006 by Ladislav Nevery
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid